32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/printfection/api.rb', line 32
def request(verb, uri, params={})
perform_request do
uri = Util.join_uri(ENDPOINT, uri)
url = "https://#{api_token}:@#{uri}"
unless logger.nil?
logger.info "[Printfection] #{verb.upcase} #{url}"
end
response = case verb
when :get; RestClient.get url, :params => params, :accept => :json
when :post; RestClient.post url, params.to_json, :accept => :json, :content_type => :json
when :patch; RestClient.patch url, params.to_json, :accept => :json, :content_type => :json
when :delete; RestClient.delete url
end
json = JSON.parse(response.body)
if json["object"] == "list" and json.has_key? "data"
json["data"]
else
json
end
end
end
|