Class: RoviAPI::Client
- Inherits:
-
Object
- Object
- RoviAPI::Client
- Defined in:
- lib/rovi_api/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
- #data ⇒ Object
- #default_params ⇒ Object
- #get(service, version, endpoint, method, params = {}) ⇒ Object
-
#initialize(key: RoviAPI.key, secret: RoviAPI.secret, connection: RoviAPI.connection) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #search ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize(key: RoviAPI.key, secret: RoviAPI.secret, connection: RoviAPI.connection) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 |
# File 'lib/rovi_api/client.rb', line 5 def initialize(key: RoviAPI.key, secret: RoviAPI.secret, connection: RoviAPI.connection) @key = key or raise ArgumentError("missing key") @secret = secret or raise ArgumentError("missing secret") @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/rovi_api/client.rb', line 3 def connection @connection end |
#last_response ⇒ Object (readonly)
Returns the value of attribute last_response.
3 4 5 |
# File 'lib/rovi_api/client.rb', line 3 def last_response @last_response end |
Instance Method Details
#data ⇒ Object
11 12 13 |
# File 'lib/rovi_api/client.rb', line 11 def data @data ||= Services::Data.new(self) end |
#default_params ⇒ Object
30 31 32 |
# File 'lib/rovi_api/client.rb', line 30 def default_params { apikey: @key, sig: signature } end |
#get(service, version, endpoint, method, params = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rovi_api/client.rb', line 19 def get(service, version, endpoint, method, params={}) path = [service, version, endpoint, method].join("/") begin @last_response = @connection.get(path, default_params.merge(params)) rescue ::Faraday::ClientError => ex @last_response = ex.response raise end @last_response.body end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/rovi_api/client.rb', line 38 def inspect "<#{self.class} @key=#{@key.inspect}>" end |
#search ⇒ Object
15 16 17 |
# File 'lib/rovi_api/client.rb', line 15 def search @search ||= Services::Search.new(self) end |
#signature ⇒ Object
34 35 36 |
# File 'lib/rovi_api/client.rb', line 34 def signature Digest::MD5.hexdigest(@key + @secret + Time.now.to_i.to_s) end |