Class: OneApiSdk::Client
- Inherits:
-
Object
- Object
- OneApiSdk::Client
- Defined in:
- lib/one_api_sdk/books.rb,
lib/one_api_sdk/client.rb,
lib/one_api_sdk/movies.rb,
lib/one_api_sdk/quotes.rb,
lib/one_api_sdk/chapters.rb,
lib/one_api_sdk/constants.rb,
lib/one_api_sdk/characters.rb
Defined Under Namespace
Modules: Books, Chapters, Characters, Constants, Movies, Quotes
Constant Summary
Constants included from Constants
Constants::API_BASE_PATH, Constants::BOOK_BASE_PATH, Constants::CHAPTER_BASE_PATH, Constants::CHARACTER_BASE_PATH, Constants::MOVIE_BASE_PATH, Constants::QUOTE_BASE_PATH
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#base_api_url ⇒ Object
Returns the value of attribute base_api_url.
Instance Method Summary collapse
-
#call_with_token(path) ⇒ Object
This method calls each method and attaches the access token under the authorization header.
-
#initialize(access_token = ENV['access_token']) ⇒ Client
constructor
Initialize using passed in access token.
Methods included from Quotes
Methods included from Movies
#movie, #movie_quotes, #movies
Methods included from Characters
#character, #character_quotes, #characters
Methods included from Chapters
Methods included from Books
Constructor Details
#initialize(access_token = ENV['access_token']) ⇒ Client
Initialize using passed in access token
31 32 33 34 35 |
# File 'lib/one_api_sdk/client.rb', line 31 def initialize(access_token=ENV['access_token']) @access_token = access_token @base_api_url = Constants::API_BASE_PATH @http ||= HTTP::Client.new end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
26 27 28 |
# File 'lib/one_api_sdk/client.rb', line 26 def access_token @access_token end |
#base_api_url ⇒ Object
Returns the value of attribute base_api_url.
27 28 29 |
# File 'lib/one_api_sdk/client.rb', line 27 def base_api_url @base_api_url end |
Instance Method Details
#call_with_token(path) ⇒ Object
This method calls each method and attaches the access token under the authorization header
41 42 43 44 45 46 |
# File 'lib/one_api_sdk/client.rb', line 41 def call_with_token(path) @http .headers(accept: 'application/json', content: 'application/json') .auth("Bearer #{@access_token}") .send('get', URI(@base_api_url + path)) end |