Skip to content

Instantly share code, notes, and snippets.

@frankyston
Forked from jeffdonthemic/httparty.rb
Created October 9, 2024 19:03
Show Gist options
  • Save frankyston/2bbe907606fcb8f00314731b16c587f8 to your computer and use it in GitHub Desktop.
Save frankyston/2bbe907606fcb8f00314731b16c587f8 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