Class: DMM::Client

Inherits:
Object
  • Object
show all
Includes:
ItemList
Defined in:
lib/ruby-dmm/client.rb,
lib/ruby-dmm/client/item_list.rb

Defined Under Namespace

Modules: ItemList

Constant Summary

Constants included from ItemList

ItemList::ITEM_LIST_PARAMETERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemList

#item_list

Constructor Details

#initialize(params = {}) ⇒ Client

Returns a new instance of Client.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ruby-dmm/client.rb', line 24

def initialize(params={})
  DMM.options.each do |key, value|
    # fall back to `DMM::Configuration` module defaults
    send("#{key}=", params[key] || value)
  end

  # Symbolize keys
  params = params.inject({}) do |hash, (key, value)|
    hash.merge(key.to_sym => value)
  end

  @params = {
    :api_id       => ENV['DMM_API_ID']        || params[:api_id],       # your own api_id
    :affiliate_id => ENV['DMM_AFFILIATE_ID']  || params[:affiliate_id], # your own affiliate_id
    :operation    => nil,
    :version      => DEFAULT_API_VERSION,
    :timestamp    => Time.now.strftime("%F %T"),
    :site         => DEFAULT_SITE,
    :result_only  => false, # Set true to get response.result only.
  }.merge(params)
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



22
23
24
# File 'lib/ruby-dmm/client.rb', line 22

def params
  @params
end

Instance Method Details

#allObject



50
51
52
# File 'lib/ruby-dmm/client.rb', line 50

def all
  @params[:operation] ? get('/', @params) : nil
end

#last_responseObject



54
55
56
# File 'lib/ruby-dmm/client.rb', line 54

def last_response
  @last_response
end

#operation(value) ⇒ Object



46
47
48
# File 'lib/ruby-dmm/client.rb', line 46

def operation(value)
  @params.update(:operation => value)
end