class Getty::Client
Constants
- DEFAULT_CONNECTION_MIDDLEWARE
Attributes
system_id[R]
system_pwd[R]
user_name[R]
user_pwd[R]
Public Class Methods
new(options={})
click to toggle source
Initialize the client class that will be used for all getty API requests.
# File lib/getty/client.rb, line 20 def initialize(options={}) @system_id = options[:system_id] || Getty.system_id @system_pwd = options[:system_pwd] || Getty.system_pwd @user_name = options[:user_name] || Getty.user_name @user_pwd = options[:user_pwd] || Getty.user_pwd @connection_middleware = options[:connection_middleware] || Getty.connection_middleware || [] @connection_middleware += DEFAULT_CONNECTION_MIDDLEWARE @ssl = options[:ssl] || { :verify => false } end
Public Instance Methods
api_url()
click to toggle source
Base URL for api requests.
# File lib/getty/client.rb, line 48 def api_url "https://connect.gettyimages.com/v1" end
connection()
click to toggle source
Sets up the connection to be used for all requests based on options passed during initialization.
# File lib/getty/client.rb, line 36 def connection params = {} @connection ||= Faraday::Connection.new(:url => api_url, :ssl => ssl, :params => params, :headers => default_headers) do |builder| @connection_middleware.each do |middleware| builder.use *middleware end builder.adapter Faraday.default_adapter end end
return_error_or_body(response, response_body)
click to toggle source
Helper method to return errors or desired response data as appropriate.
Added just for convenience to avoid having to traverse farther down the response just to get to returned data.
# File lib/getty/client.rb, line 56 def return_error_or_body(response, response_body) if response.status == 200 response_body else raise Getty::APIError.new(response.status, response.body) end end
ssl()
click to toggle source
# File lib/getty/client.rb, line 30 def ssl @ssl end
Private Instance Methods
default_headers()
click to toggle source
# File lib/getty/client.rb, line 67 def default_headers headers = { :content_type => 'application/json', :accept => 'application/json', :user_agent => 'Ruby gem' } end