Class: Getty::Client
- Inherits:
-
Object
- Object
- Getty::Client
- Extended by:
- Forwardable
- Defined in:
- lib/getty/client.rb
Constant Summary collapse
- DEFAULT_CONNECTION_MIDDLEWARE =
[ # Faraday::Response::Logger, FaradayMiddleware::EncodeJson, FaradayMiddleware::Mashify, FaradayMiddleware::ParseJson ]
Instance Attribute Summary collapse
-
#system_id ⇒ Object
readonly
Returns the value of attribute system_id.
-
#system_pwd ⇒ Object
readonly
Returns the value of attribute system_pwd.
-
#user_name ⇒ Object
readonly
Returns the value of attribute user_name.
-
#user_pwd ⇒ Object
readonly
Returns the value of attribute user_pwd.
Instance Method Summary collapse
-
#api_url ⇒ Object
Base URL for api requests.
-
#connection ⇒ Object
Sets up the connection to be used for all requests based on options passed during initialization.
-
#initialize(options = {}) ⇒ Client
constructor
Initialize the client class that will be used for all getty API requests.
-
#return_error_or_body(response, response_body) ⇒ Object
Helper method to return errors or desired response data as appropriate.
- #ssl ⇒ Object
Methods included from Images
#download_image, #image_details, #largest_image_authorizations, #search
Methods included from Sessions
#create_session, #renew_session
Constructor Details
#initialize(options = {}) ⇒ Client
Initialize the client class that will be used for all getty API requests.
20 21 22 23 24 25 26 27 28 |
# File 'lib/getty/client.rb', line 20 def initialize(={}) @system_id = [:system_id] || Getty.system_id @system_pwd = [:system_pwd] || Getty.system_pwd @user_name = [:user_name] || Getty.user_name @user_pwd = [:user_pwd] || Getty.user_pwd @connection_middleware = [:connection_middleware] || Getty.connection_middleware || [] @connection_middleware += DEFAULT_CONNECTION_MIDDLEWARE @ssl = [:ssl] || { :verify => false } end |
Instance Attribute Details
#system_id ⇒ Object (readonly)
Returns the value of attribute system_id.
17 18 19 |
# File 'lib/getty/client.rb', line 17 def system_id @system_id end |
#system_pwd ⇒ Object (readonly)
Returns the value of attribute system_pwd.
17 18 19 |
# File 'lib/getty/client.rb', line 17 def system_pwd @system_pwd end |
#user_name ⇒ Object (readonly)
Returns the value of attribute user_name.
17 18 19 |
# File 'lib/getty/client.rb', line 17 def user_name @user_name end |
#user_pwd ⇒ Object (readonly)
Returns the value of attribute user_pwd.
17 18 19 |
# File 'lib/getty/client.rb', line 17 def user_pwd @user_pwd end |
Instance Method Details
#api_url ⇒ Object
Base URL for api requests.
48 49 50 |
# File 'lib/getty/client.rb', line 48 def api_url "https://connect.gettyimages.com/v1" end |
#connection ⇒ Object
Sets up the connection to be used for all requests based on options passed during initialization.
36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
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.
56 57 58 59 60 61 62 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/getty/client.rb', line 30 def ssl @ssl end |