Last active
December 28, 2015 04:09
-
-
Save tstachl/7440363 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'desk_api' | |
require 'json' | |
site = { | |
username: '[email protected]', | |
password: 'yourpassword', | |
site_name: 'yoursubdomain' | |
} | |
client = DeskApi::Client.new username: site[:username], password: site[:password], subdomain: site[:site_name] | |
client.middleware = Proc.new do |builder| | |
builder.request :json | |
builder.request :basic_auth, site[:username], site[:password] | |
builder.request :retry | |
builder.response :mashify | |
builder.response :dates | |
# remove raising of errors | |
# builder.response :raise_error, DeskApi::Error::ClientError | |
# builder.response :raise_error, DeskApi::Error::ServerError | |
builder.response :json, content_type: /application\/json/ | |
# add a request/response logger | |
builder.response :logger | |
builder.adapter Faraday.default_adapter | |
end | |
resp = client.get('/api/v2/cases/:a_non_existent_id') | |
puts resp.body.to_json | |
# {"message":"Resource Not Found"} | |
puts resp.headers.to_json | |
# {"accept-ranges"=>"bytes", "cache-control"=>"no-cache, private", "content-type"=>"application/json; charset=utf-8", "date"=>"Tue, 12 Nov 2013 22:58:54 GMT", "status"=>"404 Not Found", "vary"=>"X-AppVersion", "x-appversion"=>"13.9", "x-frame-options"=>"SAMEORIGIN", "x-rate-limit-limit"=>"60", "x-rate-limit-remaining"=>"59", "x-rate-limit-reset"=>"6", "x-request-id"=>"084842f889484a4bf07c2618284383f2", "content-length"=>"32", "connection"=>"Close"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment