Class: ApiBucket::Yahooauction::Client

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

Defined Under Namespace

Modules: Http

Constant Summary collapse

REQUEST_URL =
'http://auctions.yahooapis.jp/AuctionWebService/V2/json/search'
REQUEST_URL_ITEM =
'http://auctions.yahooapis.jp/AuctionWebService/V2/json/auctionItem'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Http

#send_request

Methods included from Base::Client::Http

#prepare_query, #send_request

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



28
29
30
31
32
33
34
# File 'lib/api_bucket/yahooauction/client.rb', line 28

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

  self.appid          = options[:appid]
end

Instance Attribute Details

#appidObject

Returns the value of attribute appid.



8
9
10
# File 'lib/api_bucket/yahooauction/client.rb', line 8

def appid
  @appid
end

#limitObject

Returns the value of attribute limit.



8
9
10
# File 'lib/api_bucket/yahooauction/client.rb', line 8

def limit
  @limit
end

#pageObject

Returns the value of attribute page.



8
9
10
# File 'lib/api_bucket/yahooauction/client.rb', line 8

def page
  @page
end

Instance Method Details

#categoriesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/api_bucket/yahooauction/client.rb', line 13

def categories
  {
    :'----'  => 'ALL',
    :'25464' => 'おもちゃ、ゲーム',
    :'24242' => 'ホビー、カルチャー',
    :'20000' => 'アンティーク、コレクション',
    :'23000' => 'ファッション',
    :'42177' => 'ビューティー、ヘルスケア',
    :'24198' => '住まい、インテリア',
    :'23140' => 'アクセサリー、時計',
    :'2084032594' => 'タレントグッズ',
    :'2084043920' => 'チケット、金券、宿泊予約',
  }
end

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



55
56
57
58
59
60
61
62
63
# File 'lib/api_bucket/yahooauction/client.rb', line 55

def lookup(id, params={})
  options = {
    auctionID:   id,
    appid: self.appid
  }
  options.merge!(params)

  ApiBucket::Yahooauction::Response.new(send_request(options, REQUEST_URL_ITEM))
end

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/api_bucket/yahooauction/client.rb', line 36

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

    category: params[:search_index],
    query:    keywords,
    appid:    self.appid,
  }
  options.merge!(params)

  # delete no needed keys
  options.delete(:keywords)
  options.delete(:search_index)
  options[:category] = 'ALL' if options[:category].nil?

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