Class: JSdk::LOTR
- Inherits:
-
Object
- Object
- JSdk::LOTR
- Defined in:
- lib/j_sdk/lotr.rb
Overview
def self.set_token(token)
@@api_token = token
end
Constant Summary collapse
- BASE_URL =
"https://the-one-api.dev/v2"
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #get_movie(id) ⇒ Object
- #get_movies ⇒ Object
- #get_quotes(id, limit = 10, page = 0) ⇒ Object
-
#initialize(token) ⇒ LOTR
constructor
A new instance of LOTR.
Constructor Details
#initialize(token) ⇒ LOTR
Returns a new instance of LOTR.
17 18 19 |
# File 'lib/j_sdk/lotr.rb', line 17 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
13 14 15 |
# File 'lib/j_sdk/lotr.rb', line 13 def token @token end |
Instance Method Details
#get_movie(id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/j_sdk/lotr.rb', line 40 def get_movie(id) uri = URI("#{BASE_URL}/movie/#{id}") res = Net::HTTP.get_response(uri, headers) data = JSON.parse(res.body)['docs'][0] movie = Movie.new( data['_id'], data['name'], data['runtimeInMinutes'], data['budgetInMillions'], data['boxOfficeRevenueInMillions'], data['academyAwardNominations'], data['academyAwardWins'], data['rottenTomatoesScore'], self ) end |
#get_movies ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/j_sdk/lotr.rb', line 21 def get_movies() uri = URI("#{BASE_URL}/movie") res = Net::HTTP.get_response(uri, headers) data = JSON.parse(res.body)['docs'] movies = data.map do |mv| Movie.new( mv['_id'], mv['name'], mv['runtimeInMinutes'], mv['budgetInMillions'], mv['boxOfficeRevenueInMillions'], mv['academyAwardNominations'], mv['academyAwardWins'], mv['rottenTomatoesScore'], self ) end end |
#get_quotes(id, limit = 10, page = 0) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/j_sdk/lotr.rb', line 57 def get_quotes(id, limit=10, page=0) uri = URI("#{BASE_URL}/movie/#{id}/quote?limit=10") res = Net::HTTP.get_response(uri, headers) data = JSON.parse(res.body)['docs'] quotes = data.map do |quote| Quote.new( quote['id'], quote['dialog'], quote['movie'], quote['character'], self ) end end |