Last active
October 9, 2024 19:03
-
-
Save jeffdonthemic/99c4da9daba9a4ee36ba to your computer and use it in GitHub Desktop.
HTTParty Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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