Module: Shutterstock::API::Util
- Includes:
- Configurable
- Included in:
- Auth, Images, Subscriptions
- Defined in:
- lib/shutterstock/api/util.rb
Constant Summary collapse
- FORMAT =
:json- ENDPOINT =
'http://api.shutterstock.com'
Instance Attribute Summary
Attributes included from Configurable
#api_key, #api_username, #email, #password, #username
Instance Method Summary collapse
Methods included from Configurable
#configure, #credentials, keys
Instance Method Details
#call(path, type, params = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shutterstock/api/util.rb', line 12 def call(path, type, params = {}) base_url = "#{ File.join(ENDPOINT, path) }.#{ FORMAT }" uri = URI.parse(base_url) uri.query = URI.encode_www_form(params) http = Net::HTTP.new(uri.host, uri.port) case type when :get request = Net::HTTP::Get.new(uri.request_uri) when :post request = Net::HTTP::Post.new(uri.request_uri) end request.basic_auth(credentials[:api_username], credentials[:api_key]) response = http.request(request) JSON.parse(response.body) end |
#call_with_auth_token(path, type, params = {}) ⇒ Object
30 31 32 |
# File 'lib/shutterstock/api/util.rb', line 30 def call_with_auth_token(path, type, params = {}) call(path, type, {auth_token: customer["auth_token"]}.merge(params)) end |