Class: Tmdb::Resource

Inherits:
Object show all
Includes:
Utils
Defined in:
lib/tmdb/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#parse_json

Constructor Details

#initialize(query_url, filters = {}) ⇒ Resource

Returns a new instance of Resource.



8
9
10
11
# File 'lib/tmdb/resource.rb', line 8

def initialize(query_url, filters={})
  @params = filters
  @query_url = query_url
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/tmdb/resource.rb', line 6

def params
  @params
end

#query_urlObject (readonly)

Returns the value of attribute query_url.



6
7
8
# File 'lib/tmdb/resource.rb', line 6

def query_url
  @query_url
end

Instance Method Details

#getObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tmdb/resource.rb', line 13

def get
  request_params = Api.params.merge(@params)

  begin
    response = RestClient.get Api::BASE_URI + query_url,
                              Api::JSON_HEADERS.merge(params: request_params)
  rescue => e
    parsed_exception_rs = parse_json(e.response)

    if parsed_exception_rs['status_message'].present?
      raise Tmdb::Error, parsed_exception_rs['status_message']
    else
      raise Tmdb::Error, e.response
    end
  end

  parse_json(response)
end