Class: Pexels::Client
- Inherits:
-
Object
- Object
- Pexels::Client
- Defined in:
- lib/pexels/client.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#ratelimit_remaining ⇒ Object
readonly
Returns the value of attribute ratelimit_remaining.
Instance Method Summary collapse
-
#initialize(api_key = ENV['PEXELS_API_KEY']) ⇒ Client
constructor
A new instance of Client.
- #photos ⇒ Object
- #request(path, method: 'GET', params: {}) ⇒ Object
- #videos ⇒ Object
Constructor Details
#initialize(api_key = ENV['PEXELS_API_KEY']) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/pexels/client.rb', line 8 def initialize(api_key = ENV['PEXELS_API_KEY']) @api_key = api_key end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/pexels/client.rb', line 4 def api_key @api_key end |
#ratelimit_remaining ⇒ Object (readonly)
Returns the value of attribute ratelimit_remaining.
4 5 6 |
# File 'lib/pexels/client.rb', line 4 def ratelimit_remaining @ratelimit_remaining end |
Instance Method Details
#photos ⇒ Object
12 13 14 |
# File 'lib/pexels/client.rb', line 12 def photos @photos ||= Pexels::Client::Photos.new(self) end |
#request(path, method: 'GET', params: {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pexels/client.rb', line 20 def request(path, method: 'GET', params: {}) results = Requests.request( method, "#{Pexels.api_base_url}#{path}", params: params, headers: { 'Authorization' => api_key } ) @ratelimit_remaining = results.headers['x-ratelimit-remaining'].first.to_i return JSON.parse(results.body) rescue StandardError => exception raise Pexels::APIError.new(exception) end |
#videos ⇒ Object
16 17 18 |
# File 'lib/pexels/client.rb', line 16 def videos @videos ||= Pexels::Client::Videos.new(self) end |