Guest User

Untitled

a guest
Sep 14th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.58 KB | None | 0 0
  1. require 'httparty'
  2. require 'vine'
  3. class Hash
  4.   def to_xml
  5.     map do |k, v|
  6.       text = v.class==Hash ? v.to_xml : v
  7.       "<%s>%s</%s>" % [k, text, k]
  8.    end.join
  9.  end
  10. end
  11.  
  12. hash={"client" =>
  13.         {"first_name"=>"rishabh",
  14.      "last_name" =>"adi",
  15.      "organization" =>"test",
  16.      "email"=>"foobar@xml.com"
  17.  
  18.         }
  19.     }
  20. auth={:username =>API_KEY, :password => "X"}
  21.  
  22. string ="<?xml version=\'1.0'\ encoding= \'utf-8'\ ?>  
  23. <request method=\'client.create'> #{hash.to_xml} </request>"
  24. response=HTTParty.post(API_URL,
  25.     :body => string,
  26.     :basic_auth => auth
  27.     )
Add Comment
Please, Sign In to add comment