rakuten_web_service 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTMxYmJkZDY4MjE0MDI0MDIzZDIyOTRkN2EyMGU1NjRhMDMzMDg5NA==
4
+ ZjUxOTgxNTFiYTgyOGJhZTAyMDk5YTg3YzdlZGMyZTdmNGVlNjJkNw==
5
5
  data.tar.gz: !binary |-
6
- ODY4NjQ2MGI2Mzc0OTE4ZDE0OWE4ZmIwNTZiNGYyN2UxMTFmOWJmNQ==
6
+ NGI5NGMyZDg5OGFiNTQwMmRiN2E4ZDg0ZGIxNzdmZjdmNjM5NzY0Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2ZhY2UzYmY0ZjlhZDAwNWY3OThkMWIzODVkZDZhMmUyNDczYjY0NDRjNzM3
10
- M2IzYjM1NzY1NzBlNWFjODhlNWRiNTkyYjE4NmQ3ODE3MjI0ZjEwMWMwY2E3
11
- NzNhM2YxZGZkYTQwYjA2MWUyMWJhZmQ2MGE2YmIyNzdkYzJjZjk=
9
+ Yzk0NzQxMzM1MmJmN2M5NTFmODFkMzEzMzdhZTRmOWY4NDBlZTUwYzE0NTJi
10
+ OWYyNTM1MzRmMGQyODNjYTI5MWFhZDUxMDA5MTUwN2QwMzcwNjBiNDFjODQ4
11
+ M2Q2NjZiNzdhNDA1YjgwMzQ2MmU4NDE2YmNlYmI1OTk4ZmYxODA=
12
12
  data.tar.gz: !binary |-
13
- OGNjNzQzNWFlNTBhNjg1ZTZkNWYyMjk0ZjcyODcwMGM5ZDg5YzQ5MTVkOTBi
14
- N2E0NTViMjc3MTg3MTAwNTkxYzZmMjhkMTQzODE0NjE0ZGEzNWFjYTY0NjNj
15
- NWQ0MDJhYzZkMzMwMDc4MzUzMWE0YjUwZGRlMGYxM2FiMjQyZWU=
13
+ ZjEyYjRmMWNmOWMzMTM2MzIwMDIwZTE3YjgxNTI1MTRlNTU1NzQ1ZjliMzky
14
+ MjUxOWQ5MzVmMGQ4N2FmYTk0ODc0NzliNzY3MDdkYWM1MWJkZDY5ZGRmZGM5
15
+ MDIyM2Q4ODRiNzhmYzVkMGYwMWY5N2I3ZWFhZWVlMmMzMjNmOWY=
data/README.md CHANGED
@@ -6,7 +6,9 @@
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'rakuten_web_service'
9
+ ```ruby
10
+ gem 'rakuten_web_service'
11
+ ```
10
12
 
11
13
  And then execute:
12
14
 
@@ -18,7 +20,54 @@ Or install it yourself as:
18
20
 
19
21
  ## Usage
20
22
 
21
- TODO: Write usage instructions here
23
+ Now rakuten\_web\_service is supporting the following APIs:
24
+
25
+ * [Rakuten Ichiba Item Search API](http://webservice.rakuten.co.jp/api/ichibaitemsearch/)
26
+ * [Rakuten Ichiba Genre Search API](http://webservice.rakuten.co.jp/api/ichibagenresearch/)
27
+ * [Rakuten Ichiba Ranking API](http://webservice.rakuten.co.jp/api/ichibaitemranking/)
28
+
29
+ ### Configuration
30
+
31
+ `RakutenWebService.configuration` allows you to specify your application's key called application\_id and your affiliate id(optional).
32
+
33
+ ```ruby
34
+ RakutenWebService.configuration do |c|
35
+ c.application_id = YOUR_APPLICATION_ID
36
+ c.affiliate_id = YOUR_AFFILIATE_ID
37
+ end
38
+ ```
39
+
40
+ ### Search Ichiba Items
41
+
42
+ ```ruby
43
+ items = RakutenWebService::Ichiba::Item.search(:keyword => 'Ruby') # This returns Enamerable object
44
+ items.first(10).each do |item|
45
+ puts "#{item['itemName']}, #{item.price} yen" # You can refer to values as well as Hash.
46
+ end
47
+ ```
48
+
49
+ ### Genre
50
+
51
+ Genre class provides an interface to traverse sub genres.
52
+
53
+ ```ruby
54
+ root = RakutenWebService::Ichiba::Genre.root # root genre
55
+ # children returns sub genres
56
+ root.children.each do |child|
57
+ puts "[#{child.id}] #{child.name}"
58
+ end
59
+
60
+ # Use genre id to fetch genre object
61
+ RakutenWebService::Ichiba::Genre[100316].name # => "水・ソフトドリンク"
62
+ ```
63
+
64
+
65
+ ### Ichiba Item Ranking
66
+
67
+ ```ruby
68
+ RakutenWebService::Ichiba::Item.ranking(:age => 30, :sex => 0) # returns the TOP 30 items for Male in 30s
69
+ RakutenWebService::Ichiba::Genre[100316].ranking # the TOP 30 items in "水・ソフトドリンク" genre
70
+ ```
22
71
 
23
72
  ## Contributing
24
73
 
@@ -3,6 +3,7 @@ require 'rakuten_web_service/configuration'
3
3
  require 'rakuten_web_service/client'
4
4
  require 'rakuten_web_service/search_result'
5
5
  require 'rakuten_web_service/resource'
6
+ require 'rakuten_web_service/ichiba/shop'
6
7
  require 'rakuten_web_service/ichiba/item'
7
8
  require 'rakuten_web_service/ichiba/genre'
8
9
  require 'rakuten_web_service/ichiba/ranking'
@@ -24,13 +24,21 @@ module RakutenWebService
24
24
  :affiliateRate,
25
25
  :startTime, :endTime,
26
26
  :reviewCount, :reviewAverage,
27
- :pointRate, :pointRateStartTime, :pointRateEndTime<
27
+ :pointRate, :pointRateStartTime, :pointRateEndTime,
28
28
  :shopName, :shopCode, :shopUrl,
29
29
  :genreId
30
30
 
31
31
  def genre
32
32
  Genre[self.genre_id]
33
33
  end
34
+
35
+ def shop
36
+ Shop.new({
37
+ 'shopName' => self.shop_name,
38
+ 'shopCode' => self.shop_code,
39
+ 'shopUrl' => self.shop_url
40
+ })
41
+ end
34
42
  end
35
43
  end
36
44
  end
@@ -0,0 +1,12 @@
1
+ module RakutenWebService
2
+ module Ichiba
3
+ class Shop < Resource
4
+ attribute :shopName, :shopCode, :shopUrl
5
+
6
+ def items(options={})
7
+ options = options.merge(:shop_code => self.code)
8
+ RakutenWebService::Ichiba::Item.search(options)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -5,7 +5,7 @@ module RakutenWebService
5
5
  class << self
6
6
  def attribute(*attributes)
7
7
  attributes.each do |attribute|
8
- method_name = attribute.to_s.gsub(/([a-z]+)([A-Z]{1})/) do
8
+ method_name = attribute.to_s.gsub(/([a-z]+)([A-Z]{1})/) do |matched|
9
9
  "#{$1}_#{$2.downcase}"
10
10
  end
11
11
  method_name = method_name.sub(/^#{resource_name}_(\w+)$/) { $1 }
@@ -1,3 +1,3 @@
1
1
  module RakutenWebService
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -101,4 +101,24 @@ describe RakutenWebService::Ichiba::Item do
101
101
  expect { subject }.to_not raise_error
102
102
  end
103
103
  end
104
+
105
+ describe '#shop' do
106
+ let(:response) { JSON.parse(fixture('ichiba/item_search_with_keyword_Ruby.json')) }
107
+ let(:expected_item) { response['Items'][0]['Item'] }
108
+
109
+ before do
110
+ stub_request(:get, endpoint).with(:query => expected_query).
111
+ to_return(:body => response.to_json)
112
+ end
113
+
114
+ subject do
115
+ RakutenWebService::Ichiba::Item.search(:keyword => 'Ruby').first.shop
116
+ end
117
+
118
+ specify 'responds Shop object' do
119
+ expect(subject.name).to eq(expected_item['shopName'])
120
+ expect(subject.code).to eq(expected_item['shopCode'])
121
+ expect(subject.url).to eq(expected_item['shopUrl'])
122
+ end
123
+ end
104
124
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'rakuten_web_service'
3
+
4
+ describe RakutenWebService::Ichiba::Shop do
5
+ let(:params) do
6
+ { 'shopName' => 'Hoge Shop',
7
+ 'shopCode' => 'hogeshop',
8
+ 'shopUrl' => 'http://www.rakuten.co.jp/hogeshop' }
9
+ end
10
+ let(:shop) { RakutenWebService::Ichiba::Shop.new(params) }
11
+ let(:endpoint) { 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20130805' }
12
+ let(:affiliate_id) { 'dummy_affiliate_id' }
13
+ let(:application_id) { 'dummy_application_id' }
14
+ let(:expected_query) do
15
+ {
16
+ 'affiliateId' => affiliate_id,
17
+ 'applicationId' => application_id,
18
+ 'shopCode' => 'hogeshop'
19
+ }
20
+ end
21
+
22
+ before do
23
+ RakutenWebService.configuration do |c|
24
+ c.affiliate_id = affiliate_id
25
+ c.application_id = application_id
26
+ end
27
+ end
28
+
29
+ describe '.new' do
30
+ specify 'returned object should have methods to fetch values' do
31
+ expect(shop.name).to eq('Hoge Shop')
32
+ expect(shop.code).to eq('hogeshop')
33
+ expect(shop.url).to eq('http://www.rakuten.co.jp/hogeshop')
34
+ end
35
+ end
36
+
37
+ describe '#items' do
38
+ let(:response) do
39
+ { 'Items' => [] }
40
+ end
41
+
42
+ before do
43
+ @expected_request = stub_request(:get, endpoint).
44
+ with(:query => expected_query).to_return(:body => response.to_json)
45
+ end
46
+
47
+ specify 'call the endpoint with the shopCode' do
48
+ shop.items.first
49
+
50
+ expect(@expected_request).to have_been_made
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rakuten_web_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuya Sato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-29 00:00:00.000000000 Z
11
+ date: 2013-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -128,6 +128,7 @@ files:
128
128
  - lib/rakuten_web_service/ichiba/genre.rb
129
129
  - lib/rakuten_web_service/ichiba/item.rb
130
130
  - lib/rakuten_web_service/ichiba/ranking.rb
131
+ - lib/rakuten_web_service/ichiba/shop.rb
131
132
  - lib/rakuten_web_service/resource.rb
132
133
  - lib/rakuten_web_service/search_result.rb
133
134
  - lib/rakuten_web_service/version.rb
@@ -140,6 +141,7 @@ files:
140
141
  - spec/rakuten_web_service/ichiba/genre_spec.rb
141
142
  - spec/rakuten_web_service/ichiba/item_spec.rb
142
143
  - spec/rakuten_web_service/ichiba/ranking_spec.rb
144
+ - spec/rakuten_web_service/ichiba/shop_spec.rb
143
145
  - spec/spec_helper.rb
144
146
  - spec/support/fixture_suppot.rb
145
147
  homepage: http://webservice.rakuten.co.jp/
@@ -175,5 +177,6 @@ test_files:
175
177
  - spec/rakuten_web_service/ichiba/genre_spec.rb
176
178
  - spec/rakuten_web_service/ichiba/item_spec.rb
177
179
  - spec/rakuten_web_service/ichiba/ranking_spec.rb
180
+ - spec/rakuten_web_service/ichiba/shop_spec.rb
178
181
  - spec/spec_helper.rb
179
182
  - spec/support/fixture_suppot.rb