Skip to content

Instantly share code, notes, and snippets.

@nullcookies
Forked from jeffdonthemic/httparty.rb
Created December 17, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nullcookies/b377e875297afe1bffdfa6c468b793af to your computer and use it in GitHub Desktop.
Save nullcookies/b377e875297afe1bffdfa6c468b793af to your computer and use it in GitHub Desktop.
HTTParty Examples
options = { :body =>
{ :username => 'my',
:password => 'password'
}
}
results = HTTParty.post("http://api.topcoder.com/v2/auth", options)
##
## example for post with papertrail and basic auth
##
auth = {
:username => ENV['PAPERTRAIL_DIST_USERNAME'],
:password => ENV['PAPERTRAIL_DIST_PASSWORD']
}
# create the user's account
user = {
:id => membername,
:email => email
}
payload = {
:id => membername,
:name => membername,
:user => user,
:plan => 'free'
}
options = {
:body => payload,
:basic_auth => auth
}
results = HTTParty.post("https://papertrailapp.com/api/v1/distributors/accounts", options)
results = HTTParty.get("http://some.api", :headers => {
"X-Api-Key" => "#{api_key}",
"Content-Type" => "application/json",
"Authorization" => "Bearer #{response.access_token}"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment