Class: RoviAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rovi_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/rovi_api/client.rb', line 3

def connection
  @connection
end

#last_responseObject (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

#dataObject



11
12
13
# File 'lib/rovi_api/client.rb', line 11

def data
  @data ||= Services::Data.new(self)
end

#default_paramsObject



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

#inspectObject



38
39
40
# File 'lib/rovi_api/client.rb', line 38

def inspect
  "<#{self.class} @key=#{@key.inspect}>"
end

#searchObject



15
16
17
# File 'lib/rovi_api/client.rb', line 15

def search
  @search ||= Services::Search.new(self)
end

#signatureObject



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