Class: OneApiSdk::Client

Inherits:
Object
  • Object
show all
Includes:
Books, Chapters, Characters, Constants, Movies, Quotes
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

Instance Method Summary collapse

Methods included from Quotes

#quote, #quotes

Methods included from Movies

#movie, #movie_quotes, #movies

Methods included from Characters

#character, #character_quotes, #characters

Methods included from Chapters

#chapter, #chapters

Methods included from Books

#book, #book_chapters, #books

Constructor Details

#initialize(access_token = ENV['access_token']) ⇒ Client

Initialize using passed in access token

Parameters:



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_tokenObject

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_urlObject

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

Parameters:

  • path (String)

    the path to the endpoint including any query parameters

See Also:



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