Class: ApiBucket::Rakuten::Client

Inherits:
Object
  • Object
show all
Includes:
Http
Defined in:
lib/api_bucket/rakuten/client.rb,
lib/api_bucket/rakuten/client/http.rb

Defined Under Namespace

Modules: Http

Constant Summary collapse

REQUEST_URL =
'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20120723'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base::Client::Http

#prepare_query, #send_request

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
40
41
42
43
# File 'lib/api_bucket/rakuten/client.rb', line 35

def initialize(options={})
  options             = ApiBucket::Rakuten.options.merge(options)
  self.page           = options[:page]    || 1
  self.limit          = options[:limit]   || 20

  self.format         = options[:format]  || 'json'
  self.application_id  = options[:application_id]
  self.affiliate_id    = options[:affiliate_id]
end

Instance Attribute Details

#affiliate_idObject

Returns the value of attribute affiliate_id.



9
10
11
# File 'lib/api_bucket/rakuten/client.rb', line 9

def affiliate_id
  @affiliate_id
end

#application_idObject

Returns the value of attribute application_id.



9
10
11
# File 'lib/api_bucket/rakuten/client.rb', line 9

def application_id
  @application_id
end

#formatObject

Returns the value of attribute format.



9
10
11
# File 'lib/api_bucket/rakuten/client.rb', line 9

def format
  @format
end

#limitObject

Returns the value of attribute limit.



9
10
11
# File 'lib/api_bucket/rakuten/client.rb', line 9

def limit
  @limit
end

#pageObject

Returns the value of attribute page.



9
10
11
# File 'lib/api_bucket/rakuten/client.rb', line 9

def page
  @page
end

Instance Method Details

#categoriesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/api_bucket/rakuten/client.rb', line 13

def categories
  {
    :ALL      => 'ALL',
    :'101240' => 'CD・DVD/BD・楽器',

    :'100371' => 'レディースファッション',
    :'551177' => 'メンズファッション',
    :'558885' => '靴',
    :'216131' => 'バッグ・小物・ブランド雑貨',

    :'100804' => 'インテリア・寝具・収納',
    :'211742' => '家電・AV・カメラ',
    :'402853' => 'デジタルコンテンツ',

    :'100227' => '食品',
    :'100000' => '百貨店・総合通販・ギフト',

    :'101381' => '旅行・出張・チケット',
    :'100939' => '美容・コスメ・香水',
  }
end

#lookup(id, params = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/api_bucket/rakuten/client.rb', line 66

def lookup(id, params={})
  options = {
    itemCode:   id,
    operation:  'ItemCodeSearch',
    version:    '2010-08-05',

    applicationId: self.application_id,
    affiliateId: self.affiliate_id,
  }
  options.merge!(params)

  ApiBucket::Rakuten::Response.new(send_request(options, REQUEST_URL))
end

#search(keywords, params = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/api_bucket/rakuten/client.rb', line 45

def search(keywords, params={})
  options = {
    hits:  self.limit,
    page:  self.page,

    genreId: params[:search_index],
    keyword: keywords,

    applicationId: self.application_id,
    affiliateId:   self.affiliate_id,
  }
  options.merge!(params)

  # delete no needed keys
  options.delete(:keywords)
  options.delete(:search_index)
  options[:genreId] = '0' if options[:genreId] == 'ALL'

  ApiBucket::Rakuten::Response.new(send_request(options, REQUEST_URL))
end