rakuten 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ spec/ids.rb
5
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rakuten.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rakuten (0.1.0)
5
+ activesupport
6
+ i18n
7
+ json (>= 1.4.6)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (3.0.3)
13
+ diff-lcs (1.1.2)
14
+ i18n (0.5.0)
15
+ json (1.4.6)
16
+ rspec (2.4.0)
17
+ rspec-core (~> 2.4.0)
18
+ rspec-expectations (~> 2.4.0)
19
+ rspec-mocks (~> 2.4.0)
20
+ rspec-core (2.4.0)
21
+ rspec-expectations (2.4.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.4.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ activesupport
30
+ i18n
31
+ json (>= 1.4.6)
32
+ rakuten!
33
+ rspec (>= 2.3.0)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Tomonori Kusanagi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # rakuten : Simple Rakuten API client for Ruby
2
+
3
+ シンプルな楽天APIクライアント.
4
+ Ruby 1.8.7, 1.9.2 で動作確認.
5
+
6
+ ## インストール
7
+
8
+ % gem install rakuten
9
+
10
+ ## SYNOPSYS
11
+
12
+ [楽天WEB SERVICE](http://webservice.rakuten.co.jp/) の各種APIを簡単に使うための gem です.
13
+ 文字コードには UTF-8 を使用してください.
14
+
15
+ ## サンプル
16
+
17
+ ### 楽天市場系API, 楽天ブックス系API, 楽天オークション系API
18
+
19
+ 以下のようにして、楽天WEB SERVICE APIを呼び出すことができます.
20
+
21
+ client = Rakuten::Client.new('DEVELOPER_ID', 'AFFILIATE_ID(オプション)')
22
+ result = client.item_search('2010-09-15', {:keyword => '福袋', :sort => '+itemPrice'})
23
+
24
+ Rakuten::Client オブジェクトに対して呼び出すメソッド名は、楽天APIの operation パラメーターの名前を小文字にしてアンダースコアでつないだ者です.
25
+ 例えば、楽天商品検索API(operation名は"ItemSearch")の呼び出しの場合、メソッド名は "item_search" になります.
26
+ 第一引数は、APIのバージョンです. APIのバージョンは、operation 毎に異なりますので注意してください.
27
+ 楽天WEB SERVICE API に送信するパラメーター(operationとversionを除く)は、ハッシュにした上で第二引数としてメソッドに渡してください.
28
+ APIのバージョンやパラメーターについては、楽天WEB SERVICEの [ドキュメント](http://webservice.rakuten.co.jp/) を参照してください.
29
+
30
+ 結果は、レスポンスJSONからハッシュの形で取得します.
31
+
32
+ cnt = result['count']
33
+ items = result['Items']['Item']
34
+
35
+ 形式は呼び出したAPIによって様々です. 楽天WEB SERVICEの [ドキュメント](http://webservice.rakuten.co.jp/) の、各APIの解説にある出力パラメーターの欄を参照してください.
36
+
37
+ エラーが発生した場合は、Rakuten::ApiError が発生します.
38
+ Rakuten::ApiError から、エラーの種類とメッセージを取得することができます.
39
+
40
+ その他のAPIの呼び出し例については、[spec](https://github.com/xanagi/rakuten/blob/master/spec/rakuten_spec.rb) を参照してください.
41
+
42
+ ### 楽天トラベル系API
43
+
44
+ 楽天トラベル系APIは、以下のように Rakuten::TravelClient を使って呼び出します.
45
+
46
+ client = Rakuten::TravelClient.new('DEVELOPER_ID', 'AFFILIATE_ID(オプション)')
47
+ result = client.simple_hotel_search('2009-10-20', {:largeClassCode => 'japan',
48
+ :middleClassCode => 'akita',
49
+ :smallClassCode => 'tazawa'})
50
+ 使い方は、Rakuten::Client と同じです.
51
+ その他のAPIの呼び出し例については、[spec](https://github.com/xanagi/rakuten/blob/master/spec/rakuten_travel_spec.rb) を参照してください.
52
+
53
+ ### 楽天ダイナミックアドAPI, 楽天ダイナミックアドAPIトラベル
54
+
55
+ 楽天ダイナミックアドAPI, 楽天ダイナミックアドAPIトラベルを呼び出す場合には、Rakuten::DynamicAdClient を使います.
56
+
57
+ # 楽天ダイナミックアドAPI
58
+ client = Rakuten::DynamicAdClient.new('DEVELOPER_ID', 'AFFILIATE_ID(オプション)')
59
+ result = client.dynamic_ad(nil, {:url => 'http://plaza.rakuten.co.jp/isblog/diary/200705230001/'})
60
+
61
+ # 楽天ダイナミックアドAPIトラベル
62
+ client = Rakuten::DynamicAdClient.new('DEVELOPER_ID', 'AFFILIATE_ID(オプション)')
63
+ result = client.dynamic_ad_travel(nil, {:url => 'http://plaza.rakuten.co.jp/travelblog02/diary/200706140000/'})
64
+
65
+
66
+ ## ライセンス
67
+
68
+ The MIT License
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ module Rakuten
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rakuten.rb ADDED
@@ -0,0 +1,122 @@
1
+ # -*- coding: utf-8 -*-
2
+ # = Rakuten
3
+ # シンプルな楽天APIクライアント.
4
+ #
5
+ require 'cgi'
6
+ require 'open-uri'
7
+ require 'active_support/inflector'
8
+ require 'json'
9
+ require 'i18n'
10
+
11
+ module Rakuten
12
+ class Client
13
+ attr_reader :raw_response
14
+
15
+ def initialize(developer_id, affiliate_id = nil)
16
+ @developer_id, @affiliate_id = developer_id, affiliate_id
17
+ end
18
+
19
+ # リクエストを実行して結果を返す.
20
+ # 結果はJSONをパーズしたHash.
21
+ # リクエストに失敗したら例外をスローする.
22
+ def request(operation, version = nil, params = {})
23
+ response = open(request_url(operation, version, params)) do |f|
24
+ @raw_response = f.read
25
+ JSON.parse(@raw_response)
26
+ end
27
+ unless response['Header']['Status'] == 'Success'
28
+ raise ApiError.new(response['Header']['Status'], response['Header']['StatusMsg'])
29
+ end
30
+ extract_result(response, operation)
31
+ end
32
+
33
+ # リクエストURLを返す.
34
+ def request_url(operation, version = nil, params = {})
35
+ url = "#{host(operation)}?developerId=#{@developer_id}&operation=#{operation}&version=#{version}"
36
+ url += "&affiliateId=#{@affiliate_id}" if @affiliate_id && @affiliate_id != ''
37
+ if params
38
+ params.each do |k, v|
39
+ url += "&#{k}=" + CGI::escape(v.to_s)
40
+ end
41
+ end
42
+ #puts url
43
+ url
44
+ end
45
+
46
+ # リクエスト送信先ホストを返す.
47
+ def host(operation)
48
+ 'http://api.rakuten.co.jp/rws/3.0/json'
49
+ end
50
+
51
+ # レスポンスから結果データを抽出する.
52
+ def extract_result(response, operation)
53
+ # Body の子要素は通常は操作名をキーとする要素1つだけのハッシュだが、
54
+ # ProductPriceInfo の場合だけは、キーがItemSearchになっている(バグ?).
55
+ #puts "#{operation}: #{response['Body'].keys.to_s}"
56
+ response['Body'].values[0]
57
+ #response['Body'][operation]
58
+ end
59
+
60
+ # 楽天APIにリクエストを送信する.
61
+ # メソッド名が item_ranking であれば、camel case に変換した上で操作名としてリクエストに含める.
62
+ # 第1引数はバージョン文字列、第2引数はパラメターHashであるとする.
63
+ def method_missing(method_id, *params)
64
+ request(method_id.id2name.camelize, params[0], params[1])
65
+ end
66
+ end
67
+
68
+ # 楽天トラベル用APIクライアント
69
+ class TravelClient < Client
70
+ def host(operation)
71
+ if ['GetAreaClass', 'GetHotelChainList', 'HotelRanking'].include? operation
72
+ 'http://api.rakuten.co.jp/rws/2.0/json'
73
+ else
74
+ super
75
+ end
76
+ end
77
+
78
+ def extract_result(response, operation)
79
+ if ['VacantHotelSearch'].include? operation
80
+ response['Body']
81
+ else
82
+ super
83
+ end
84
+ end
85
+ end
86
+
87
+ # 楽天ダイナミックアド用APIクライアント
88
+ class DynamicAdClient < Client
89
+ def request_url(operation, version = nil, params = {})
90
+ url = case(operation)
91
+ when 'DynamicAd'
92
+ 'http://dynamic.rakuten.co.jp/rcm/1.0/i/json'
93
+ when 'DynamicAdTravel'
94
+ 'http://dynamic.rakuten.co.jp/rcm/1.0/t/json'
95
+ end
96
+ url += "?developerId=#{@developer_id}"
97
+ url += "&affiliateId=#{@affiliate_id}" if @affiliate_id && @affiliate_id != ''
98
+ if params
99
+ params.each do |k, v|
100
+ url += "&#{k}=" + CGI::escape(v.to_s)
101
+ end
102
+ end
103
+ #puts url
104
+ url
105
+ end
106
+
107
+ def extract_result(response, operation)
108
+ response['Body']
109
+ end
110
+ end
111
+
112
+ class ApiError < StandardError
113
+ attr_reader :status, :message
114
+ def initialize(status, message)
115
+ @status, @message = status, message
116
+ end
117
+
118
+ def to_s
119
+ "#{self.status}:#{self.message}"
120
+ end
121
+ end
122
+ end
data/rakuten.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rakuten/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rakuten"
7
+ s.version = Rakuten::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Tomonori Kusanagi"]
10
+ s.email = ["kusanagi@banana-systems.com"]
11
+ s.homepage = "https://github.com/xanagi/rakuten"
12
+ s.summary = %q{Simple Rakuten API client.}
13
+ s.description = %q{Simple Rakuten API client.}
14
+
15
+ s.add_dependency "i18n"
16
+ s.add_dependency "activesupport"
17
+ s.add_dependency "json", ">=1.4.6"
18
+ s.add_development_dependency "rspec", ">=2.3.0"
19
+
20
+ s.rubyforge_project = "rakuten"
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ["lib"]
26
+ end
@@ -0,0 +1,4 @@
1
+ # -*- coding: utf-8 -*-
2
+ # テストを実行するには、デベロッパーIDとアフィリエイトIDを書き換え、ids.rb という名前で保存してください.
3
+ DEVELOPER_ID = 'Your developer id'
4
+ AFFILIATE_ID = 'Your affiliate id'
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rakuten'
3
+ require 'date'
4
+ require 'pp'
5
+ require File.dirname(__FILE__) + '/ids.rb'
6
+
7
+ # see http://webservice.rakuten.co.jp/document/index.html
8
+
9
+ # テストを実行するには、ids.rb.sample のデベロッパーIDとアフィリエイトIDを書き換え、
10
+ # ids.rb という名前で保存してください.
11
+ describe Rakuten::DynamicAdClient do
12
+
13
+ before(:all) do
14
+ @developer_id = DEVELOPER_ID
15
+ @affiliate_id = AFFILIATE_ID
16
+ @client = Rakuten::DynamicAdClient.new(@developer_id, @affiliate_id)
17
+ end
18
+
19
+ it "楽天ダイナミックアドAPIの呼び出しが可能であること" do
20
+ result = @client.dynamic_ad(nil, {:url => 'http://plaza.rakuten.co.jp/isblog/diary/200705230001/'})
21
+ result['Ads']['Ad'].should_not be_empty
22
+ end
23
+
24
+ it "楽天GORAダイナミックAPIトラベルの呼び出しが可能であること" do
25
+ result = @client.dynamic_ad_travel(nil, {:url => 'http://plaza.rakuten.co.jp/travelblog02/diary/200706140000/'})
26
+ result['Ads']['Ad'].should_not be_empty
27
+ end
28
+
29
+ end
@@ -0,0 +1,242 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rakuten'
3
+ require 'date'
4
+ require 'pp'
5
+ require File.dirname(__FILE__) + '/ids.rb'
6
+
7
+ # see http://webservice.rakuten.co.jp/document/index.html
8
+
9
+ # テストを実行するには、ids.rb.sample のデベロッパーIDとアフィリエイトIDを書き換え、
10
+ # ids.rb という名前で保存してください.
11
+ describe Rakuten::Client do
12
+
13
+ before(:all) do
14
+ @developer_id = DEVELOPER_ID
15
+ @affiliate_id = AFFILIATE_ID
16
+ @client = Rakuten::Client.new(@developer_id, @affiliate_id)
17
+ end
18
+
19
+ it "API URLを正しく構築できること" do
20
+ url = @client.request_url('ItemRanking', '2010-08-05', {})
21
+ url.should == "http://api.rakuten.co.jp/rws/3.0/json?developerId=#{@developer_id}&operation=ItemRanking&version=2010-08-05&affiliateId=#{@affiliate_id}"
22
+ end
23
+
24
+ it "developerIdが無効であれば、例外が発生すること" do
25
+ client = Rakuten::Client.new('invalid_developer_id')
26
+ lambda{client.item_ranking('2010-08-15')}.should raise_error(Rakuten::ApiError)
27
+ end
28
+
29
+ it "versionが不正であれば、例外が発生すること" do
30
+ lambda{@client.item_ranking('2010-08-01')}.should raise_error(Rakuten::ApiError)
31
+ end
32
+
33
+ #
34
+ # 楽天市場系API
35
+ #
36
+
37
+ it "楽天商品検索APIを呼び出し可能であること" do
38
+ result = @client.item_search('2010-09-15', {:keyword => '福袋', :sort => '+itemPrice'})
39
+ (result['count'] > 0).should be_true
40
+ result['Items']['Item'].should_not be_nil
41
+ end
42
+
43
+ it "モバイル用の呼び出しが可能であること" do
44
+ result = @client.item_search('2010-09-15', {:keyword => '福袋', :carrier => 1})
45
+ (result['count'] > 0).should be_true
46
+ result['Items']['Item'].should_not be_nil
47
+ end
48
+
49
+ it "楽天ジャンル検索APIの呼び出しが可能であること(ルートレベル)" do
50
+ result = @client.genre_search('2007-04-11', {:genreId => 0})
51
+ result['child'].should_not be_empty
52
+ result['child'][0]['genreLevel'].should == 1
53
+ result['child'][0]['genreName'].should_not be_nil
54
+ result['child'][0]['genreId'].should_not be_nil
55
+ end
56
+
57
+ it "楽天ジャンル検索APIの呼び出しが可能であること(食品ジャンル)" do
58
+ result = @client.genre_search('2007-04-11', {:genreId => 100227})
59
+ result['child'].should_not be_empty
60
+ result['child'][0]['genreLevel'].should == 2
61
+ result['child'][0]['genreName'].should_not be_nil
62
+ result['child'][0]['genreId'].should_not be_nil
63
+ end
64
+
65
+ it "楽天商品コード検索APIの呼び出しが可能であること" do
66
+ sample = @client.item_search('2010-09-15', {:keyword => '福袋', :hits => 1})
67
+ item_code = sample['Items']['Item'][0]['itemCode']
68
+ # 楽天商品コード検索API呼び出し.
69
+ result = @client.item_code_search('2010-08-05', {:itemCode => item_code})
70
+ result['Items']['Item'].should_not be_empty
71
+ end
72
+
73
+ it "楽天カタログ検索APIの呼び出しが可能であること" do
74
+ result = @client.catalog_search('2009-04-15', {:keyword => '液晶テレビ', :sort => '-reviewCount'})
75
+ (result['count'] > 0).should be_true
76
+ result['Catalogs']['Catalog'].should_not be_empty
77
+ end
78
+
79
+ it "楽天商品ランキングAPIの呼び出しが可能であること" do
80
+ result = @client.item_ranking('2010-08-05')
81
+ result['title'].should_not be_nil
82
+ result['lastBuildDate'].should_not be_nil
83
+ result['Items']['Item'].should_not be_empty
84
+ end
85
+
86
+ it "楽天プロダクト製品検索APIの呼び出しができること" do
87
+ result = @client.product_search('2010-11-18', {:keyword => 'ノートパソコン', :genreId => 100040})
88
+ result['Items']['Item'].should_not be_empty
89
+ end
90
+
91
+ it "楽天プロダクト製品詳細APIの呼び出しが可能であること" do
92
+ sample = @client.product_search('2010-11-18', {:keyword => 'ノートパソコン', :genreId => 100040, :hits => 1})
93
+ product_id = sample['Items']['Item'][0]['productId']
94
+ # 楽天プロダクト製品詳細API呼び出し.
95
+ result = @client.product_detail('2010-11-18', {:productId => product_id, :detailFlag => 1})
96
+ result['Item'].should_not be_empty
97
+ end
98
+
99
+ it "楽天プロダクトジャンル情報APIの呼び出しが可能であること" do
100
+ result = @client.product_genre_info('2010-11-18', {:genreId => 500740, :makerHits => 10, :satisfiedHits => 5, :satisfiedPage => 3})
101
+ result['NewProductInformation'].should be_nil
102
+ result['SatisfiedInformation']['satisfier'].should_not be_empty
103
+ result['SellerInformation'].should be_nil
104
+ result['GenreInformation'].should_not be_empty
105
+ result['MakerInformation']['maker'].should_not be_empty
106
+ end
107
+
108
+ it "楽天プロダクトメーカー情報APIの呼び出しが可能であること" do
109
+ result = @client.product_maker_info('2010-11-18', {:makerCode => 104901780})
110
+ result['makerName'].should_not be_nil
111
+ end
112
+
113
+ it "楽天プロダクト価格比較情報APIの呼び出しが可能であること" do
114
+ sample = @client.product_search('2010-11-18', {:keyword => 'ノートパソコン', :genreId => 100040, :hits => 1})
115
+ product_id = sample['Items']['Item'][0]['productId']
116
+ # 楽天プロダクトか各比較情報API呼び出し.
117
+ result = @client.product_price_info('2010-11-18', {:productId => product_id, :availability => 1, :creditCardFlag => 1})
118
+ (result['count'] > 0).should be_true
119
+ result['Items']['Item'].should_not be_empty
120
+ end
121
+
122
+ #
123
+ # 楽天ブックス系API
124
+ #
125
+
126
+ it "楽天ブックス総合検索APIの呼び出しが可能であること" do
127
+ result = @client.books_total_search('2010-03-18', {:keyword => 'ガンダム', :NGKeyword => '予約', :sort => '+itemPrice'})
128
+ (result['count'] > 0).should be_true
129
+ result['Items']['Item'].should_not be_empty
130
+ end
131
+
132
+ it "楽天ブックス書籍検索APIの呼び出しが可能であること" do
133
+ result = @client.books_book_search('2010-03-18', {:title => '太陽', :booksGenreId => '001004008', :sort => '+itemPrice'})
134
+ (result['count'] > 0).should be_true
135
+ result['Items']['Item'].should_not be_empty
136
+ end
137
+
138
+ it "楽天ブックスCD検索APIの呼び出しが可能であること" do
139
+ result = @client.books_CD_search('2010-03-18', {:artistName => 'サザンオールスターズ', :sort => '+itemPrice'})
140
+ (result['count'] > 0).should be_true
141
+ result['Items']['Item'].should_not be_empty
142
+ end
143
+
144
+ it "楽天ブックスDVD検索APIの呼び出しが可能であること" do
145
+ result = @client.books_DVD_search('2010-03-18', {:title => 'ガンダム', :sort => '+itemPrice'})
146
+ (result['count'] > 0).should be_true
147
+ result['Items']['Item'].should_not be_empty
148
+ end
149
+
150
+ it "楽天ブックス洋書検索APIの呼び出しが可能であること" do
151
+ result = @client.books_foreign_book_search('2010-03-18', {:title => 'HarryPotter', :booksGenreId => '005407', :sort => '+itemPrice'})
152
+ (result['count'] > 0).should be_true
153
+ result['Items']['Item'].should_not be_empty
154
+ end
155
+
156
+ it "楽天ブックス雑誌検索APIの呼び出しが可能であること" do
157
+ result = @client.books_magazine_search('2010-03-18', {:title => '週刊 経済', :booksGenreId => '007604001', :sort => '+itemPrice'})
158
+ (result['count'] > 0).should be_true
159
+ result['Items']['Item'].should_not be_empty
160
+ end
161
+
162
+ it "楽天ブックスゲーム検索APIの呼び出しが可能であること" do
163
+ result = @client.books_game_search('2010-03-18', {:title => 'マリオ', :hardware => 'Wii', :sort => '+itemPrice'})
164
+ (result['count'] > 0).should be_true
165
+ result['Items']['Item'].should_not be_empty
166
+ end
167
+
168
+ it "楽天ブックスソフトウェア検索APIの呼び出しが可能であること" do
169
+ result = @client.books_software_search('2010-03-18', {:title => '会計', :os => 'Mac', :sort => '+itemPrice'})
170
+ (result['count'] > 0).should be_true
171
+ result['Items']['Item'].should_not be_empty
172
+ end
173
+
174
+ it "楽天ブックスジャンル検索APIの呼び出しが可能であること" do
175
+ result = @client.books_genre_search('2009-03-26', {:booksGenreId => '000'})
176
+ result['child'].should_not be_empty
177
+ result['child'][0]['genreLevel'].should == 1
178
+ result['child'][0]['genreName'].should_not be_nil
179
+ result['child'][0]['genreId'].should_not be_nil
180
+ end
181
+
182
+ it "楽天ブックスジャンル検索APIの呼び出しが可能であること(DVD)" do
183
+ result = @client.books_genre_search('2009-03-26', {:booksGenreId => '003'})
184
+ result['child'].should_not be_empty
185
+ result['child'][0]['genreLevel'].should == 2
186
+ result['child'][0]['genreName'].should_not be_nil
187
+ result['child'][0]['genreId'].should_not be_nil
188
+ end
189
+
190
+ #
191
+ # 楽天オークション系API
192
+ #
193
+
194
+ it "楽天オークション商品検索APIの呼び出しが可能であること" do
195
+ result = @client.auction_item_search('2010-09-15', {:keyword => '福袋', :sort => '+itemPrice'})
196
+ (result['count'] > 0).should be_true
197
+ result['Items']['Item'].should_not be_empty
198
+ end
199
+
200
+ it "楽天オークション商品コード検索APIの呼び出しが可能であること" do
201
+ sample = @client.auction_item_search('2010-09-15', {:keyword => '福袋', :hits => 1})
202
+ item_code = sample['Items']['Item'][0]['itemCode']
203
+ # 楽天オークション商品コード検索API呼び出し.
204
+ result = @client.auction_item_code_search('2010-09-15', {:itemCode => item_code})
205
+ result['Items']['Item'].should_not be_empty
206
+ end
207
+
208
+ it "楽天オークションジャンル検索APIの呼び出しが可能であること" do
209
+ result = @client.auction_genre_search('2010-09-15', {:auctionGenreId => '0'})
210
+ result['child'].should_not be_empty
211
+ result['child'][0]['genreLevel'].should == 1
212
+ result['child'][0]['auctionGenreName'].should_not be_nil
213
+ result['child'][0]['auctionGenreId'].should_not be_nil
214
+ end
215
+
216
+ it "楽天オークションジャンル検索APIの呼び出しが可能であること(レディースファッション)" do
217
+ result = @client.auction_genre_search('2010-09-15', {:auctionGenreId => '1010000000'})
218
+ result['child'].should_not be_empty
219
+ result['child'][0]['genreLevel'].should == 2
220
+ result['child'][0]['auctionGenreName'].should_not be_nil
221
+ result['child'][0]['auctionGenreId'].should_not be_nil
222
+ end
223
+
224
+ #
225
+ # その他のAPI
226
+ #
227
+
228
+ it "楽天GORAゴルフ場検索APIの呼び出しが可能であること" do
229
+ result = @client.gora_golf_course_search('2010-06-30', {:keyword => '天然温泉', :sort => '50on'})
230
+ result['Items']['Item'].should_not be_empty
231
+ result['count'].should_not be_nil
232
+ end
233
+
234
+ it "楽天GORAゴルフ場詳細APIの呼び出しが可能であること" do
235
+ sample = @client.gora_golf_course_search('2010-06-30', {:keyword => '天然温泉', :hits => 1})
236
+ golf_course_id = sample['Items']['Item'][0]['golfCourseId']
237
+ # 楽天GORAゴルフ場詳細APIの呼び出し
238
+ result = @client.gora_golf_course_detail('2010-06-30', {:golfCourseId => golf_course_id})
239
+ result['Item'].should_not be_empty
240
+ end
241
+
242
+ end
@@ -0,0 +1,85 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rakuten'
3
+ require 'date'
4
+ require 'pp'
5
+ require File.dirname(__FILE__) + '/ids.rb'
6
+
7
+ # see http://webservice.rakuten.co.jp/document/index.html
8
+
9
+ # テストを実行するには、ids.rb.sample のデベロッパーIDとアフィリエイトIDを書き換え、
10
+ # ids.rb という名前で保存してください.
11
+ describe Rakuten::TravelClient do
12
+
13
+ before(:all) do
14
+ @developer_id = DEVELOPER_ID
15
+ @affiliate_id = AFFILIATE_ID
16
+ @client = Rakuten::TravelClient.new(@developer_id, @affiliate_id)
17
+ end
18
+
19
+ #
20
+ # 楽天トラベル系API
21
+ #
22
+
23
+ it "楽天トラベル施設検索APIの呼び出しが可能であること" do
24
+ result = @client.simple_hotel_search('2009-10-20', {:largeClassCode => 'japan', :middleClassCode => 'akita', :smallClassCode => 'tazawa'})
25
+ (result['pagingInfo'][0]['recordCount'] > 0).should be_true
26
+ result['hotel'].should_not be_empty
27
+
28
+ result = @client.simple_hotel_search('2009-10-20', {:latitude => 128440.51, :longitude => 503172.21, :searchRadius => 1})
29
+ (result['pagingInfo'][0]['recordCount'] > 0).should be_true
30
+ result['hotel'].should_not be_empty
31
+
32
+ result = @client.simple_hotel_search('2009-10-20', {:hotelNo => '2763,4624'})
33
+ (result['pagingInfo'][0]['recordCount'] > 0).should be_true
34
+ result['hotel'].should_not be_empty
35
+ end
36
+
37
+ it "楽天トラベル施設情報APIの呼び出しが可能であること" do
38
+ result = @client.hotel_detail_search('2009-09-09', {:hotelNo => '2763'})
39
+ result['hotel'][0]['hotelRatingInfo'].should_not be_nil
40
+ end
41
+
42
+ it "楽天トラベル空室検索APIの呼び出しが可能であること" do
43
+ result = @client.vacant_hotel_search('2009-10-20', {:largeClassCode => 'japan', :middleClassCode => 'akita', :smallClassCode => 'tazawa', :checkinDate => (Date.today + 1).to_s, :checkoutDate => (Date.today + 3).to_s, :adultNum => 2})
44
+ result['hotel'].should_not be_empty
45
+ result['pagingInfo']['recordCount'].should_not be_nil
46
+
47
+ result = @client.vacant_hotel_search('2009-10-20', {:latitude => 128440.51, :longitude => 503172.21, :searchRadius => 1, :checkinDate => (Date.today + 1).to_s, :checkoutDate => (Date.today + 3).to_s, :adultNum => 2})
48
+ result['hotel'].should_not be_empty
49
+ result['pagingInfo']['recordCount'].should_not be_nil
50
+
51
+ result = @client.vacant_hotel_search('2009-10-20', {:hotelNo => '2763,4624', :checkinDate => (Date.today + 1).to_s, :checkoutDate => (Date.today + 3).to_s, :maxCharge => 8500})
52
+ result['hotel'].should_not be_empty
53
+ result['pagingInfo']['recordCount'].should_not be_nil
54
+ end
55
+
56
+ it "楽天トラベル地区コードAPIの呼び出しが可能であること" do
57
+ result = @client.get_area_class('2009-03-26')
58
+ result['largeClass']['middleClass'].should_not be_empty
59
+ end
60
+
61
+ it "楽天トラベルキーワード検索APIの呼び出しが可能であること" do
62
+ result = @client.keyword_hotel_search('2009-10-20', {:keyword => '品川シーサイド'})
63
+ result['hotel'].should_not be_empty
64
+ result['pagingInfo'][0]['recordCount'].should_not be_nil
65
+ end
66
+
67
+ it "楽天トラベルホテルチェーンAPIの呼び出しが可能であること" do
68
+ result = @client.get_hotel_chain_list('2009-05-12')
69
+ result['hotelChainList'].should_not be_empty
70
+ end
71
+
72
+ it "楽天トラベルランキングAPIの呼び出しが可能であること" do
73
+ result = @client.hotel_ranking('2009-06-25', {:genre => 'all'})
74
+ result['ranking'][0]['hotelRankInfo'].should_not be_empty
75
+ result['ranking'][0]['lastBuildDate'].should_not be_nil
76
+
77
+ result = @client.hotel_ranking('2009-06-25', {:genre => 'onsen'})
78
+ result['ranking'][0]['hotelRankInfo'].should_not be_empty
79
+ result['ranking'][0]['lastBuildDate'].should_not be_nil
80
+
81
+ result = @client.hotel_ranking('2009-06-25', {:genre => 'all,onsen'})
82
+ result['ranking'][0]['hotelRankInfo'].should_not be_empty
83
+ result['ranking'][0]['lastBuildDate'].should_not be_nil
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rakuten
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Tomonori Kusanagi
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-12 00:00:00 +09:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: i18n
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 1
56
+ - 4
57
+ - 6
58
+ version: 1.4.6
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 2
71
+ - 3
72
+ - 0
73
+ version: 2.3.0
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: Simple Rakuten API client.
77
+ email:
78
+ - kusanagi@banana-systems.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files: []
84
+
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - Gemfile.lock
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - lib/rakuten.rb
93
+ - lib/rakuten/version.rb
94
+ - rakuten.gemspec
95
+ - spec/ids.rb.sample
96
+ - spec/rakuten_dynamic_ad_spec.rb
97
+ - spec/rakuten_spec.rb
98
+ - spec/rakuten_travel_spec.rb
99
+ has_rdoc: true
100
+ homepage: https://github.com/xanagi/rakuten
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options: []
105
+
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project: rakuten
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Simple Rakuten API client.
131
+ test_files:
132
+ - spec/ids.rb.sample
133
+ - spec/rakuten_dynamic_ad_spec.rb
134
+ - spec/rakuten_spec.rb
135
+ - spec/rakuten_travel_spec.rb