├── .gitattributes ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.en.md ├── README.md ├── autoload.php ├── composer.json ├── lib └── RakutenRws │ ├── Api │ ├── ApiInterface.php │ ├── AppRakutenApi.php │ ├── Base.php │ └── Definition │ │ ├── AuctionGenreIdSearch.php │ │ ├── AuctionGenreKeywordSearch.php │ │ ├── AuctionItemCodeSearch.php │ │ ├── AuctionItemSearch.php │ │ ├── BooksBookSearch.php │ │ ├── BooksCDSearch.php │ │ ├── BooksDVDSearch.php │ │ ├── BooksForeignBookSearch.php │ │ ├── BooksGameSearch.php │ │ ├── BooksGenreSearch.php │ │ ├── BooksMagazineSearch.php │ │ ├── BooksSoftwareSearch.php │ │ ├── BooksTotalSearch.php │ │ ├── FavoriteBookmarkAdd.php │ │ ├── FavoriteBookmarkDelete.php │ │ ├── FavoriteBookmarkList.php │ │ ├── GoraGoraGolfCourseDetail.php │ │ ├── GoraGoraGolfCourseSearch.php │ │ ├── GoraGoraPlanSearch.php │ │ ├── HighCommissionShopList.php │ │ ├── IchibaGenreSearch.php │ │ ├── IchibaItemRanking.php │ │ ├── IchibaItemSearch.php │ │ ├── IchibaTagSearch.php │ │ ├── KoboEbookSearch.php │ │ ├── KoboGenreSearch.php │ │ ├── ProductSearch.php │ │ ├── RecipeCategoryList.php │ │ ├── RecipeCategoryRanking.php │ │ ├── TravelGetAreaClass.php │ │ ├── TravelGetHotelChainList.php │ │ ├── TravelHotelDetailSearch.php │ │ ├── TravelHotelRanking.php │ │ ├── TravelKeywordHotelSearch.php │ │ ├── TravelSimpleHotelSearch.php │ │ └── TravelVacantHotelSearch.php │ ├── ApiResponse.php │ ├── ApiResponse │ └── AppRakutenResponse.php │ ├── Autoloader.php │ ├── Client.php │ ├── Exception.php │ ├── HttpClient.php │ ├── HttpClient │ ├── BasicHttpClient.php │ ├── CurlHttpClient.php │ └── PearHttpClient.php │ └── HttpResponse.php └── sample ├── bookmark.php ├── config.php.sample ├── helper.php ├── index.php └── style.css /.gitattributes: -------------------------------------------------------------------------------- 1 | test export-ignore 2 | phpunit.xml.dist export-ignore 3 | .travis.yml export-ignore 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | sample/config.php 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | * 1.1.0 (2015-06-08) 5 | 6 | * 1bfe43a: `IchibaItem/Search` のように `/` の入った操作も受け入れるように変更。また、バージョン番号に関しては、`2014-02-22` のような指定だけでなく、`20140222` のような形でも受け入れるように変更 7 | * dff5ab1: composer branch alias 追加 8 | * 11ddfb1: 旧バージョンAPIに関わるコードの削除・バージョン更新 9 | 10 | * 1.0.6 (2014-03-31) 11 | 12 | * 702b60d: 楽天市場系APIのバージョン更新 13 | 14 | * 1.0.5 (2013-11-29) 15 | 16 | * 9d57904: 楽天KoboAPIの定義追加 17 | * 16fe639: Travel APIのバージョン更新 18 | * 4065571: GORA APIのバージョン更新 19 | * dc9fc9b: IchibaItem/Search のバージョン更新 20 | * ebc823c: AuctionItem/Search のバージョン更新 21 | * b092f3e: Travis CI 上での PHP5.5 対応 (Thanks to sasezaki!) 22 | * 5cbf725: CurlHttpClient においてオプションを受け入れるように変更 23 | * ドキュメントの修正 24 | 25 | * 1.0.4 (2013-05-30) 26 | 27 | * 03f116d: Books新APIの登録 28 | 29 | * 1.0.3 (2013-04-25) 30 | 31 | * 8ceb433: 現時点でのAPI情報の更新 32 | * 24e85f5: sample/config.php.sample の誤り修正 (Thanks to shindows!) 33 | 34 | * 1.0.2 (2012-10-03) 35 | 36 | * 21dab15: IchibaItemRanking 定義追加 37 | 38 | * 1.0.1 (2012-09-12) 39 | 40 | * 4d339d2: サンプルコードのデザイン的改善 41 | * 07e012a: レスポンスが処理できない原因となるリクエストパラメータの除去 42 | * 408c91f: RakutenRws_Client::setAffiliateId() の追加 (Thanks to hamadata!) 43 | * 6bbd2bb: composer.json に推奨依存として ext-curl 追加 44 | * 4d68f0d: README.md でセミコロンが抜けている誤りの修正 45 | * c72ff1c: PHPDoc コメントのスペルミス修正 (Thanks to shinodogg!) 46 | 47 | * 1.0.0 (2012-07-26) 48 | 49 | * 最初のリリース 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2014 Rakuten, Inc 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. 20 | -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | Rakuten Web Service SDK for PHP 2 | =============================== 3 | 4 | [](http://travis-ci.org/rakuten-ws/rws-php-sdk) 5 | 6 | Rakuten Web Service SDK for PHP is a library to make it easy to connect to the Rakuten APIs. 7 | 8 | Requirement 9 | ----------- 10 | 11 | - PHP5.2.3+ (Recommended: PHP5.2.10+ with [curl extension](http://php.net/manual/en/book.curl.php)) 12 | - If you want to use this library on PHP5.2.10-, please install [HTTP_Client](http://pear.php.net/manual/en/package.http.http-client.php) on PEAR 13 | or curl extension. 14 | 15 | Download 16 | -------- 17 | 18 | You can download SDK from following links. 19 | 20 | - [Stable 1.1.0 - zip](https://github.com/rakuten-ws/rws-php-sdk/archive/1.1.0.zip) 21 | - [Source Code (Github)](https://github.com/rakuten-ws/rws-php-sdk) 22 | 23 | RWS PHP SDK is registered at [Packagist](http://packagist.org/). 24 | Therefore, you can get and manage the library with [Composer](http://getcomposer.org). 25 | 26 | Get composer 27 | 28 | curl -s http://getcomposer.org/installer | php 29 | 30 | Create *composer.json* file in the project root: 31 | 32 | 33 | { 34 | "require": { 35 | "rakuten-ws/rws-php-sdk": "1.*" 36 | } 37 | } 38 | 39 | Install 40 | 41 | php composer.phar install 42 | 43 | 44 | Basic Usage 45 | ----------- 46 | 47 | Please register your application using our Web Service site (http://webservice.rakuten.co.jp). 48 | 49 | Next, load *autoload.php* in your application. 50 | The *autoload.php* file is in the same directory as this readme file. 51 | Now you can use the library. 52 | 53 | For APIs that don't need user authorization, like IchibaItemSearch API and Books API, 54 | you can fetch data by following this sample code. 55 | 56 | ```php 57 | setApplicationId('YOUR_APPLICATION_ID'); 64 | 65 | // Please set your Affiliate ID (Optional) 66 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 67 | 68 | // Search for "うどん" with the IchibaItemSearch API 69 | $response = $client->execute('IchibaItemSearch', array( 70 | 'keyword' => 'うどん' 71 | )); 72 | 73 | // You can check that the response status is correct 74 | if ($response->isOk()) { 75 | // You can access the response as an array 76 | var_dump($response['Body']); 77 | } else { 78 | echo 'Error:'.$response->getMessage(); 79 | } 80 | ``` 81 | You can pass "API Name (string)", "Request Paramters (array)", and 82 | "version" to *RakutenRws_Client::execute()* method. 83 | "version" is an optional parameter. If you don't specify the "version" then the library will 84 | auotmatically select the latest version. 85 | 86 | The following APIs support [Iterator (http://php.net/manual/en/class.iterator.php)], 87 | so you can access each item's data with a foreach statement. 88 | 89 | * AuctionGenreKeywordSearch 90 | * AuctionItemCodeSearch 91 | * AuctionItemSearch 92 | * BooksBookSearch 93 | * BooksCDSearch 94 | * BooksDVDSearch 95 | * BooksForeignBookSearch 96 | * BooksGameSearch 97 | * BooksMagazineSearch 98 | * BooksSoftwareSearch 99 | * BooksTotalSearch 100 | * FavoriteBookmarkList 101 | * GoraGolfCourseDetail 102 | * GoraGolfCourseSearch 103 | * GoraPlanSearch 104 | * HighCommissionShopList 105 | * IchibaItemRanking 106 | * IchibaItemSearch 107 | * KoboEbookSearch 108 | * ProductSearch 109 | * RecipeCategoryRanking 110 | * TravelHotelDetailSearch 111 | * TravelKeywordHotelSearch 112 | * TravelSimpleHotelSearch 113 | * TravelVacantHotelSearch 114 | 115 | Example: 116 | 117 | ```php 118 | setApplicationId('YOUR_APPLICATION_ID'); 124 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 125 | 126 | $response = $client->execute('ItemSearch', array( 127 | 'keyword' => 'うどん' 128 | )); 129 | 130 | if ($response->isOk()) { 131 | // You can access data using foreach 132 | foreach ($response as $item) { 133 | echo $item['itemName']."\n"; 134 | } 135 | } else { 136 | echo 'Error:'.$response->getMessage(); 137 | } 138 | ``` 139 | 140 | To access APIs that need user's authorization, like the RakutenBookmark API, 141 | you need to get an *access_token* in advance. 142 | 143 | First, send the user to the authorization page. You can get the authorization page URL with the following code. 144 | At the same time, please don't forget the scope in *RakutenRws_Client::getAuthorizeUrl()*. 145 | 146 | ```php 147 | setApplicationId('YOUR_APPLICATION_ID'); 154 | // Set Application Secret 155 | $client->setSecret('YOUR_APPLICATION_SECRET'); 156 | // Set Callback URL 157 | $client->setRedirectUrl('CALLBACK_URL'); 158 | 159 | // Get authorization page URL with a scope 160 | echo $client->getAuthorizeUrl('rakuten_favoritebookmark_read'); 161 | ``` 162 | 163 | If you authorize users, the user's browser is redirected to CALLBACK_URL with code 164 | parameter. Then please exchange code to *access_token*. 165 | You can access API by this *access_token*. 166 | 167 | ```php 168 | setApplicationId('YOUR_APPLICATION_ID'); 175 | // Set Application Secret 176 | $client->setSecret('YOUR_APPLICATION_SECRET'); 177 | // Set Affiliate ID (Optinal) 178 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 179 | // Set Callback URL 180 | $client->setRedirectUrl('CALLBACK_URL'); 181 | 182 | // Convert code to access_token 183 | // If the request fails, this method's response is null 184 | if (!$client->fetchAccessTokenFromCode()) { 185 | echo "Error: Failed to get access_token"; 186 | die(); 187 | } 188 | 189 | // Get list from FavoriteBookmarkList API 190 | $client->execute('FavoriteBookmarkList', array( 191 | 'hits' => 10 192 | )); 193 | 194 | if ($response->isOk()) { 195 | foreach ($response as $item) { 196 | echo $item['itemName']."\n"; 197 | } 198 | } else { 199 | echo 'Error:'.$response->getMessage(); 200 | } 201 | ``` 202 | 203 | Proxy Configuration 204 | ------------------- 205 | 206 | You can use this API with a proxy. Please set proxy information with *RakutenRws_Client::setProxy()*. 207 | 208 | Example: 209 | 210 | ```php 211 | setProxy('proxy-host.example.com:port'); 218 | $client->setApplicationId('YOUR_APPLICATION_ID'); 219 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 220 | 221 | // This request is executed via proxy. 222 | $response = $client->execute('ItemSearch', array( 223 | 'keyword' => 'うどん' 224 | )); 225 | ``` 226 | 227 | 228 | Sample Code 229 | ----------- 230 | 231 | - There is sample code in the [sample] (https://github.com/rakuten-ws/rws-php-sdk/tree/master/sample) directory. 232 | - Please rename *config.php.sample* and set Application ID, Application Secret and Affiliate ID. 233 | 234 | Official API Document 235 | --------------------- 236 | 237 | - http://webservice.rakuten.co.jp 238 | 239 | 240 | SDK API Document 241 | ---------------- 242 | 243 | - [API Docs](http://webservice.rakuten.co.jp/sdkapi/php/) 244 | 245 | License 246 | ------- 247 | 248 | - MIT License 249 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rakuten Web Service SDK for PHP 2 | =============================== 3 | 4 | There is an English version in [here](https://github.com/rakuten-ws/rws-php-sdk/blob/master/README.en.md). 5 | 6 | [](http://travis-ci.org/rakuten-ws/rws-php-sdk) 7 | 8 | Rakuten Web Service SDK for PHP は、PHPアプリケーションから 9 | 楽天が提供しているAPIに、簡単にアクセスすることができるSDK 10 | (Software Development Kit)です。 11 | 12 | 動作要件 13 | -------- 14 | 15 | - PHP5.2.3以上 (PHP5.2.10以上, [curl拡張](http://php.net/manual/ja/book.curl.php) 導入を推奨) 16 | - PHP5.2.10未満を利用する場合、PEAR の [HTTP_Client](http://pear.php.net/manual/ja/package.http.http-client.php) 17 | か curl拡張の導入が必要です。 18 | 19 | ダウンロード 20 | ------------ 21 | 22 | 以下からSDKをダウンロードすることができます。 23 | 24 | - [最新版 1.1.0 - zipアーカイブ](https://github.com/rakuten-ws/rws-php-sdk/archive/1.1.0.zip) 25 | - [ソースコード (Github)](https://github.com/rakuten-ws/rws-php-sdk) 26 | 27 | また、RWS PHP SDK は、[Packagist](http://packagist.org/) にパッケージ登録を行っています。 28 | そのため、 [Composer](http://getcomposer.org/) を通してパッケージを入手することができます。 29 | 30 | composer を入手します 31 | 32 | curl -s http://getcomposer.org/installer | php 33 | 34 | あなたの開発プロジェクトのルートに composer.json を作成します。 35 | 36 | { 37 | "require": { 38 | "rakuten-ws/rws-php-sdk": "1.*" 39 | } 40 | } 41 | 42 | composer を通してパッケージを入手します 43 | 44 | php composer.phar install 45 | 46 | 47 | 基本的な使い方 48 | -------------- 49 | 50 | 事前に、楽天ウェブサービスのドキュメントページ(http://webservice.rakuten.co.jp) 51 | にて、アプリ登録を行ってください。 52 | 53 | このドキュメントと同じディレクトリにある *autoload.php* を読み込むことにより、 54 | SDK の利用準備が整います。 55 | 56 | ユーザ認証の必要のない、APIについては、以下のように情報を取得することができます。 57 | 58 | ```php 59 | setApplicationId('YOUR_APPLICATION_ID'); 66 | 67 | // アフィリエイトID をセットします(任意) 68 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 69 | 70 | // IchibaItem/Search API から、keyword=うどん を検索します 71 | $response = $client->execute('IchibaItemSearch', array( 72 | 'keyword' => 'うどん' 73 | )); 74 | 75 | // レスポンスが正しいかを isOk() で確認することができます 76 | if ($response->isOk()) { 77 | // 配列アクセスによりレスポンスにアクセスすることができます。 78 | var_dump($response['hits']); 79 | } else { 80 | echo 'Error:'.$response->getMessage(); 81 | } 82 | ``` 83 | 84 | *RakutenRws_Client::execute()* には、API名、パラメータ、バージョンを 85 | 指定します。そのうち、バージョンについては省略することが可能で、 86 | 省略した場合、自動的にSDKが指定した最新バージョンを選択します。 87 | 88 | 以下のAPIはレスポンスが、Iterator に対応しているため 89 | foreach で 情報(商品情報・施設情報など) を順次取得することが可能です。 90 | 91 | * AuctionGenreKeywordSearch 92 | * AuctionItemCodeSearch 93 | * AuctionItemSearch 94 | * BooksBookSearch 95 | * BooksCDSearch 96 | * BooksDVDSearch 97 | * BooksForeignBookSearch 98 | * BooksGameSearch 99 | * BooksMagazineSearch 100 | * BooksSoftwareSearch 101 | * BooksTotalSearch 102 | * FavoriteBookmarkList 103 | * GoraGolfCourseDetail 104 | * GoraGolfCourseSearch 105 | * GoraPlanSearch 106 | * HighCommissionShopList 107 | * IchibaItemRanking 108 | * IchibaItemSearch 109 | * KoboEbookSearch 110 | * ProductSearch 111 | * RecipeCategoryRanking 112 | * TravelHotelDetailSearch 113 | * TravelKeywordHotelSearch 114 | * TravelSimpleHotelSearch 115 | * TravelVacantHotelSearch 116 | 117 | 以下が例です。 118 | 119 | ```php 120 | setApplicationId('YOUR_APPLICATION_ID'); 126 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 127 | 128 | $response = $client->execute('IchibaItemSearch', array( 129 | 'keyword' => 'うどん' 130 | )); 131 | 132 | if ($response->isOk()) { 133 | // レスポンスを foreach でアクセスできます 134 | foreach ($response as $item) { 135 | echo $item['itemName']."\n"; 136 | } 137 | } else { 138 | echo 'Error:'.$response->getMessage(); 139 | } 140 | ``` 141 | 142 | FavoriteBookmarkAPI (楽天ブックマーク系API) のようなユーザ認証が必要な 143 | APIを使う場合は、 *access_token* を取得する必要があります。 144 | 145 | まず、ユーザを認証ページに誘導してください。認証ページのURLは、以下のように取得することができます。 146 | この時、 *RakutenRws_Client::getAuthorizeUrl()* には、API利用スコープを設定することを忘れないください。 147 | 148 | ```php 149 | setApplicationId('YOUR_APPLICATION_ID'); 156 | // Secret をセットします 157 | $client->setSecret('YOUR_APPLICATION_SECRET'); 158 | // リダイレクトURL (ログイン後に戻ってくるURL) をセットします 159 | $client->setRedirectUrl('CALLBACK_URL'); 160 | 161 | // 認証ページへのURLを取得します 162 | // APIドキュメントを参照の上、利用スコープを指定してください 163 | echo $client->getAuthorizeUrl('rakuten_favoritebookmark_read'); 164 | ``` 165 | 166 | 認証が成功すると、CALLBACK_URL に code というパラメータ付きで 167 | 戻されます。以下のように、code から access_token を取得することができます。 168 | 169 | ```php 170 | setApplicationId('YOUR_APPLICATION_ID'); 177 | // Secret をセットします 178 | $client->setSecret('YOUR_APPLICATION_SECRET'); 179 | // アフィリエイトID をセットします (任意) 180 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 181 | // リダイレクトURL (ログイン後に戻ってくるURL) をセットします 182 | $client->setRedirectUrl('CALLBACK_URL'); 183 | 184 | // code から access_token を取得します 185 | // 失敗すると null となります 186 | if (!$client->fetchAccessTokenFromCode()) { 187 | echo "Error: アクセストークン取得失敗"; 188 | die(); 189 | } 190 | 191 | // FavoriteBookmarkList で お気に入りブックマークを 192 | // 10件取得します 193 | $client->execute('FavoriteBookmarkList', array( 194 | 'hits' => 10 195 | )); 196 | 197 | if ($response->isOk()) { 198 | foreach ($response as $item) { 199 | echo $item['itemName']."\n"; 200 | } 201 | } else { 202 | echo 'Error:'.$response->getMessage(); 203 | } 204 | ``` 205 | 206 | プロキシの設定 207 | -------------- 208 | 209 | *RakutenRws_Client::setProxy()* で、プロキシを通してAPIにアクセスすることができます。 210 | 211 | 以下が利用例になります 212 | 213 | ```php 214 | setProxy('proxy-host.example.com:port'); 220 | $client->setApplicationId('YOUR_APPLICATION_ID'); 221 | $client->setAffiliateId('YOUR_AFFILIATE_ID'); 222 | 223 | // このリクエストは、プロキシを通して行われます。 224 | $response = $client->execute('IchibaItemSearch', array( 225 | 'keyword' => 'うどん' 226 | )); 227 | ``` 228 | 229 | 旧バージョンからのバージョンアップ 230 | ---------------------------------- 231 | 232 | バージョン1.1 では、APIの廃止に伴い、以下の操作ができなくなりました。 233 | 234 | 代わりに、新バージョン・統合されたバージョンを利用することができます。 235 | 236 | * ItemSearch (IchibaItemSearch が利用できます) 237 | * ItemCodeSearch (IchibaItemSearch が利用できます) 238 | * ItemRanking (IchibaItemRanking が利用できます) 239 | * ProductDetail (ProductSearch が利用できます) 240 | * ProductGenreInfo (ProductSearch が利用できます) 241 | * ProductMakerInfo 242 | * GetAreaClass (TravelGetAreaClass が利用できます) 243 | * GetHotelChainList (TravelGetHoralChainList が利用できます) 244 | * HotelDetailSearch (TravelHotelDetailSearch が利用できます) 245 | * HotelRanking (TravelHotelRanking が利用できます) 246 | * KeywordHotelSearch (TravelHotelSearch が利用できます) 247 | * SimpleHotelSearch (TravelSimpleHotelSearch が利用できます) 248 | * VacantHotelSearch (TravelVacantHotelSearch が利用できます) 249 | * GoraGolfCourseSearch (GoraGoraGolfCourseSearch が利用できます) 250 | * GoraGolfCourseDetail (GoraGoraGolfCourseDetail が利用できます) 251 | * GoraPlanSearch (GoraGoraPlanSearch が利用できます) 252 | * HighCommissionShop (HighCommissionShopList が利用できます) 253 | 254 | サンプルコード 255 | ------------- 256 | 257 | - [sample] (https://github.com/rakuten-ws/rws-php-sdk/tree/master/sample) ディレクトリにサンプルを用意しています。 258 | - config.php.sample を config.php にリネームし、アプリID, application_secret をセットすることで動作します。 259 | 260 | 公開APIドキュメント 261 | ------------------- 262 | 263 | - http://webservice.rakuten.co.jp 264 | 265 | SDK API Document 266 | ---------------- 267 | 268 | - [API Docs](http://webservice.rakuten.co.jp/sdkapi/php/) 269 | 270 | ライセンス 271 | ---------- 272 | 273 | - MIT License 274 | 275 | バグ報告・コントリビュート 276 | -------------------------- 277 | 278 | この SDK は、オープンソースです。 MIT License の下で利用することができます。 279 | 280 | もし、あなたがSDK中に間違えを見つけた場合は、[こちら](https://github.com/rakuten-ws/rws-php-sdk/issues)から 281 | バグ報告を行ってください。 282 | 283 | また、Pull Request を歓迎しております。 284 | Pull Request を行う場合は、[こちらのレポジトリ](https://github.com/rakuten-ws/rws-php-sdk) に対して、 285 | 送信してください。 286 | -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | =5.2.3", 16 | "ext-openssl": "*" 17 | }, 18 | "suggest": { 19 | "ext-curl": "*", 20 | "pear-pear/HTTP_Client": "*" 21 | }, 22 | "autoload": { 23 | "psr-0": {"RakutenRws_": "lib/"} 24 | }, 25 | "extra": { 26 | "branch-alias": { 27 | "dev-master": "1.1.x-dev" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/ApiInterface.php: -------------------------------------------------------------------------------- 1 | getService(); 35 | $url .= '/'.$this->getOperation(); 36 | $url .= '/'.$this->versionMap[$this->version]; 37 | 38 | return $url; 39 | } 40 | 41 | public function getMethod() 42 | { 43 | return 'GET'; 44 | } 45 | 46 | public function execute($parameter) 47 | { 48 | $url = $this->genUrl(); 49 | 50 | if ($this->isRequiredAccessToken) { 51 | $parameter['access_token'] = $this->client->getAccessToken(); 52 | } else { 53 | $parameter['applicationId'] = $this->client->getApplicationId(); 54 | } 55 | 56 | if ($this->client->getAffiliateId()) { 57 | $parameter['affiliateId'] = $this->client->getAffiliateId(); 58 | } 59 | 60 | unset($parameter['callback']); 61 | unset($parameter['format']); 62 | 63 | $client = $this->client->getHttpClient(); 64 | $method = 'get'; 65 | if (strtoupper($this->getMethod()) !== 'GET') { 66 | $method = 'post'; 67 | } 68 | 69 | $response = $client->$method($url, $parameter); 70 | 71 | $appresponse = new RakutenRws_ApiResponse_AppRakutenResponse($this->getOperationName(), $response); 72 | 73 | if ($this->autoSetIterator && $appresponse->isOk()) { 74 | $data = $appresponse->getData(); 75 | if (!isset($data[$this->arrayName])) { 76 | throw new RakutenRws_Exception(); 77 | } 78 | 79 | $items = array(); 80 | foreach ($data[$this->arrayName] as $item) { 81 | $items[] = $item[$this->entityName]; 82 | } 83 | 84 | $appresponse->setIterator($items); 85 | } 86 | 87 | return $appresponse; 88 | } 89 | 90 | public function setVersion($version) 91 | { 92 | $version = preg_replace( 93 | '/^(\d{4})(\d{2})(\d{2})$/', 94 | '\\1-\\2-\\3', 95 | $version 96 | ); 97 | 98 | parent::setVersion($version); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Base.php: -------------------------------------------------------------------------------- 1 | options = $options; 30 | $this->client = $client; 31 | $this->version = $this->getLatestVersion(); 32 | } 33 | 34 | public function getAvailableVersions() 35 | { 36 | return array_keys($this->versionMap); 37 | } 38 | 39 | public function getOperationName() 40 | { 41 | $className = explode('_', get_class($this)); 42 | return end($className); 43 | } 44 | 45 | public function getVersion() 46 | { 47 | return $this->version; 48 | } 49 | 50 | public function getLatestVersion() 51 | { 52 | foreach ($this->versionMap as $version => $versionValue) { 53 | return $version; 54 | } 55 | 56 | throw new LogicException('There is no version definition in this API.'); 57 | } 58 | 59 | public function setVersion($version) 60 | { 61 | if (!in_array($version, $this->getAvailableVersions())) { 62 | throw new RakutenRws_Exception(sprintf('version %s is not defined.', $version)); 63 | } 64 | 65 | $this->version = $version; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/AuctionGenreIdSearch.php: -------------------------------------------------------------------------------- 1 | '20120927' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'AuctionGenreId'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'Search'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/AuctionGenreKeywordSearch.php: -------------------------------------------------------------------------------- 1 | '20120927' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'AuctionGenreKeyword'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'Search'; 34 | } 35 | 36 | public function execute($parameter) 37 | { 38 | $appresponse = parent::execute($parameter); 39 | 40 | if ($appresponse->isOk()) { 41 | $data = $appresponse->getData(); 42 | if (!isset($data['auctionGenreList'])) { 43 | throw new RakutenRws_Exception(); 44 | } 45 | 46 | $appresponse->setIterator($data['auctionGenreList']); 47 | } 48 | 49 | return $appresponse; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/AuctionItemCodeSearch.php: -------------------------------------------------------------------------------- 1 | '20121010' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'AuctionItemCode'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'Search'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/AuctionItemSearch.php: -------------------------------------------------------------------------------- 1 | '20130905', 25 | '2013-01-10' => '20130110', 26 | '2013-10-10' => '20131010' 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'AuctionItem'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'Search'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksBookSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksBook'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksCDSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksCD'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksDVDSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksDVD'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksForeignBookSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksForeignBook'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksGameSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksGame'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksGenreSearch.php: -------------------------------------------------------------------------------- 1 | '20121128' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'BooksGenre'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'Search'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksMagazineSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksMagazine'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksSoftwareSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksSoftware'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/BooksTotalSearch.php: -------------------------------------------------------------------------------- 1 | '20130522', 25 | '2012-11-28' => '20121128' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'BooksTotal'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'Search'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/FavoriteBookmarkAdd.php: -------------------------------------------------------------------------------- 1 | '20120627' 23 | ); 24 | 25 | public function getService() 26 | { 27 | return 'FavoriteBookmark'; 28 | } 29 | 30 | public function getOperation() 31 | { 32 | return 'Add'; 33 | } 34 | 35 | public function getMethod() 36 | { 37 | return 'POST'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/FavoriteBookmarkDelete.php: -------------------------------------------------------------------------------- 1 | '20120627' 23 | ); 24 | 25 | public function getService() 26 | { 27 | return 'FavoriteBookmark'; 28 | } 29 | 30 | public function getOperation() 31 | { 32 | return 'Delete'; 33 | } 34 | 35 | public function getMethod() 36 | { 37 | return 'POST'; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/FavoriteBookmarkList.php: -------------------------------------------------------------------------------- 1 | '20120627' 23 | ); 24 | 25 | public function getService() 26 | { 27 | return 'FavoriteBookmark'; 28 | } 29 | 30 | public function getOperation() 31 | { 32 | return 'List'; 33 | } 34 | 35 | public function execute($parameter) 36 | { 37 | $response = parent::execute($parameter); 38 | 39 | if ($response->isOk()) { 40 | $data = $response->getData(); 41 | if (!isset($data['items'])) { 42 | throw new RakutenRws_Exception(); 43 | } 44 | 45 | $items = array(); 46 | foreach ($data['items'] as $item) { 47 | $items[] = $item['item']; 48 | } 49 | 50 | $response->setIterator($items); 51 | } 52 | 53 | return $response; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/GoraGoraGolfCourseDetail.php: -------------------------------------------------------------------------------- 1 | '20131113', 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Gora'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'GoraGolfCourseDetail'; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/GoraGoraGolfCourseSearch.php: -------------------------------------------------------------------------------- 1 | '20131113', 25 | ); 26 | 27 | public function getService() 28 | { 29 | return 'Gora'; 30 | } 31 | 32 | public function getOperation() 33 | { 34 | return 'GoraGolfCourseSearch'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/GoraGoraPlanSearch.php: -------------------------------------------------------------------------------- 1 | '20131113' 25 | ); 26 | 27 | public function getService() 28 | { 29 | return 'Gora'; 30 | } 31 | 32 | public function getOperation() 33 | { 34 | return 'GoraPlanSearch'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/HighCommissionShopList.php: -------------------------------------------------------------------------------- 1 | '20131205', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'HighCommissionShop'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'List'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/IchibaGenreSearch.php: -------------------------------------------------------------------------------- 1 | '20140222', 24 | '2012-07-23' => '20120723' 25 | ); 26 | 27 | public function getService() 28 | { 29 | return 'IchibaGenre'; 30 | } 31 | 32 | public function getOperation() 33 | { 34 | return 'Search'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/IchibaItemRanking.php: -------------------------------------------------------------------------------- 1 | '20120927' 25 | ); 26 | 27 | public function getService() 28 | { 29 | return 'IchibaItem'; 30 | } 31 | 32 | public function getOperation() 33 | { 34 | return 'Ranking'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/IchibaItemSearch.php: -------------------------------------------------------------------------------- 1 | '20140222', 25 | '2013-08-05' => '20130805', 26 | '2013-04-24' => '20130424', 27 | '2012-07-23' => '20120723' 28 | ); 29 | 30 | public function getService() 31 | { 32 | return 'IchibaItem'; 33 | } 34 | 35 | public function getOperation() 36 | { 37 | return 'Search'; 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/IchibaTagSearch.php: -------------------------------------------------------------------------------- 1 | '20140222' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'IchibaTag'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'Search'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/KoboEbookSearch.php: -------------------------------------------------------------------------------- 1 | '20140811', 25 | '2013-10-10' => '20131010' 26 | ); 27 | 28 | public function getService() 29 | { 30 | return 'Kobo'; 31 | } 32 | 33 | public function getOperation() 34 | { 35 | return 'EbookSearch'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/KoboGenreSearch.php: -------------------------------------------------------------------------------- 1 | '20131010' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Kobo'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'GenreSearch'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/ProductSearch.php: -------------------------------------------------------------------------------- 1 | '20140305', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'Product'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'Search'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/RecipeCategoryList.php: -------------------------------------------------------------------------------- 1 | '20121121' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Recipe'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'CategoryList'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/RecipeCategoryRanking.php: -------------------------------------------------------------------------------- 1 | '20121121' 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Recipe'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'CategoryRanking'; 34 | } 35 | 36 | public function execute($parameter) 37 | { 38 | $appresponse = parent::execute($parameter); 39 | 40 | if ($appresponse->isOk()) { 41 | $data = $appresponse->getData(); 42 | if (!isset($data['result'])) { 43 | throw new RakutenRws_Exception(); 44 | } 45 | 46 | $appresponse->setIterator($data['result']); 47 | } 48 | 49 | return $appresponse; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelGetAreaClass.php: -------------------------------------------------------------------------------- 1 | '20131024', 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Travel'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'GetAreaClass'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelGetHotelChainList.php: -------------------------------------------------------------------------------- 1 | '20131024', 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Travel'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'GetHotelChainList'; 34 | } 35 | } -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelHotelDetailSearch.php: -------------------------------------------------------------------------------- 1 | '20131024', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'Travel'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'HotelDetailSearch'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelHotelRanking.php: -------------------------------------------------------------------------------- 1 | '20131024', 24 | ); 25 | 26 | public function getService() 27 | { 28 | return 'Travel'; 29 | } 30 | 31 | public function getOperation() 32 | { 33 | return 'HotelRanking'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelKeywordHotelSearch.php: -------------------------------------------------------------------------------- 1 | '20131024', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'Travel'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'KeywordHotelSearch'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelSimpleHotelSearch.php: -------------------------------------------------------------------------------- 1 | '20131024', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'Travel'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'SimpleHotelSearch'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/Api/Definition/TravelVacantHotelSearch.php: -------------------------------------------------------------------------------- 1 | '20131024', 27 | ); 28 | 29 | public function getService() 30 | { 31 | return 'Travel'; 32 | } 33 | 34 | public function getOperation() 35 | { 36 | return 'VacantHotelSearch'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/RakutenRws/ApiResponse.php: -------------------------------------------------------------------------------- 1 | operation = $operation; 39 | $this->httpResponse = $response; 40 | 41 | $this->handleResponse(); 42 | } 43 | 44 | abstract protected function handleResponse(); 45 | 46 | /** 47 | * Returns if request is successful. 48 | * 49 | * @return boolean 50 | */ 51 | public function isOk() { 52 | return $this->isOk; 53 | } 54 | 55 | /** 56 | * Gets the operation 57 | * 58 | * @return string 59 | */ 60 | public function getOperation() 61 | { 62 | return $this->operation; 63 | } 64 | 65 | /** 66 | * Gets the HttpResponse 67 | * 68 | * @return RakutenRws_HttpResponse 69 | */ 70 | public function getHttpResponse() 71 | { 72 | return $this->httpResponse; 73 | } 74 | 75 | /** 76 | * Gets the status code 77 | * 78 | * @return int 79 | */ 80 | public function getCode() 81 | { 82 | if ($this->code === null) { 83 | return $this->httpResponse->getCode(); 84 | } 85 | 86 | return $this->code; 87 | } 88 | 89 | /** 90 | * Sets iterator 91 | * 92 | * @param array|Iterator 93 | * @throws BadMethodCallException 94 | */ 95 | public function setIterator($data) 96 | { 97 | if (is_array($data)) { 98 | $this->iterator = new ArrayIterator($data); 99 | 100 | return; 101 | } else if ($data instanceof Iterator) { 102 | $this->iterator = $data; 103 | 104 | return; 105 | } 106 | 107 | throw new BadMethodCallException(); 108 | } 109 | 110 | /** 111 | * Check response has the iterator 112 | * 113 | * @return boolean 114 | */ 115 | public function hasIterator() 116 | { 117 | return null !== $this->iterator; 118 | } 119 | 120 | /** 121 | * Gets the iterator 122 | * 123 | * @return Iterator 124 | */ 125 | public function getIterator() 126 | { 127 | return $this->iterator; 128 | } 129 | 130 | 131 | /** 132 | * Gets response data 133 | * 134 | * @return mixed 135 | */ 136 | public function getData() 137 | { 138 | return $this->data; 139 | } 140 | 141 | /** 142 | * Gets the response message 143 | * 144 | * @return string 145 | */ 146 | public function getMessage() 147 | { 148 | return $this->message; 149 | } 150 | 151 | public function offsetExists($offset) 152 | { 153 | return isset($this->data[$offset]); 154 | } 155 | 156 | public function offsetGet($offset) 157 | { 158 | return $this->data[$offset]; 159 | } 160 | 161 | public function offsetSet($offset, $value) 162 | { 163 | throw new LogicException("Cannot set data"); 164 | } 165 | 166 | public function offsetUnset($offset) 167 | { 168 | throw new LogicException("Cannot unset data"); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /lib/RakutenRws/ApiResponse/AppRakutenResponse.php: -------------------------------------------------------------------------------- 1 | httpResponse->getCode() != 200) { 23 | $this->isOk = false; 24 | 25 | $errorData = json_decode($this->httpResponse->getContents(), true); 26 | if (isset($errorData['error']) && isset($errorData['error_description'])) { 27 | $this->message = $errorData['error'].': '.$errorData['error_description']; 28 | } 29 | } 30 | 31 | $rawData = json_decode($this->httpResponse->getContents(), true); 32 | 33 | if (null === $rawData) 34 | { 35 | throw new RakutenRws_Exception(); 36 | } 37 | 38 | $this->data = $rawData; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/RakutenRws/Autoloader.php: -------------------------------------------------------------------------------- 1 | = 0) { 54 | $httpClient = new RakutenRws_HttpClient_BasicHttpClient(); 55 | } else { 56 | if (!@include('HTTP/Client.php')) { 57 | throw new RakutenRws_Exception('Failed to include Pear HTTP_Client'); 58 | } 59 | 60 | $httpClient = new RakutenRws_HttpClient_PearHttpClient(); 61 | } 62 | // @codeCoverageIgnoreEnd 63 | } 64 | 65 | $this->httpClient = $httpClient; 66 | $this->options = $options; 67 | } 68 | 69 | 70 | /** 71 | * Sets the DeveloperID 72 | * 73 | * @param string $developerId The DeveloperID 74 | */ 75 | public function setApplicationId($developerId) 76 | { 77 | $this->developerId = $developerId; 78 | } 79 | 80 | /** 81 | * Gets DeveloperID 82 | * 83 | * @return string|null The DeveloperID 84 | */ 85 | public function getApplicationId() 86 | { 87 | return $this->developerId; 88 | } 89 | 90 | /** 91 | * Sets the AffiliateID 92 | * 93 | * @param string $affiliateId The AffiliateID 94 | */ 95 | public function setAffiliateId($affiliateId) 96 | { 97 | $this->affiliateId = $affiliateId; 98 | } 99 | 100 | /** 101 | * Gets AffilateID 102 | * 103 | * @return string|null The AffiliateID 104 | */ 105 | public function getAffiliateId() 106 | { 107 | return $this->affiliateId; 108 | } 109 | 110 | /** 111 | * Sets Application Secret 112 | * 113 | * @param string $secret The Application Secret 114 | */ 115 | public function setSecret($secret) 116 | { 117 | $this->secret = $secret; 118 | } 119 | 120 | /** 121 | * Sets Redirect Url 122 | * 123 | * @param string $redirectUrl The Redirect URL 124 | */ 125 | public function setRedirectUrl($redirectUrl) 126 | { 127 | $this->redirectUrl = $redirectUrl; 128 | } 129 | 130 | /** 131 | * Gets OAuth2 Authorize URL 132 | * 133 | * @param string $scope The scopes that is separated by ',' 134 | * @return string The Authorize URL 135 | */ 136 | public function getAuthorizeUrl($scope) 137 | { 138 | $url = 'https://app.rakuten.co.jp/services/authorize'; 139 | $parameter = array(); 140 | $parameter = array( 141 | 'response_type' => 'code', 142 | 'client_id' => $this->developerId, 143 | 'redirect_uri' => $this->redirectUrl, 144 | 'scope' => $scope 145 | ); 146 | 147 | return $url.'?'.http_build_query($parameter); 148 | } 149 | 150 | /** 151 | * Gets OAuth2 Access Token URL 152 | * 153 | * @return string The OAuth2 Access Token URL 154 | */ 155 | public function getAccessTokenUrl() 156 | { 157 | return 'https://app.rakuten.co.jp/services/token'; 158 | } 159 | 160 | /** 161 | * Fetches OAuth2 AccessToken from Code 162 | * 163 | * @param string $code The Code 164 | * @return string The Access Token, If response is invalid return null 165 | * @throws LogicException 166 | */ 167 | public function fetchAccessTokenFromCode($code = null) 168 | { 169 | if ($code === null) { 170 | if (!isset($_GET['code'])) { 171 | throw new LogicException("A parameter code is not set."); 172 | } 173 | 174 | $code = $_GET['code']; 175 | } 176 | 177 | $url = $this->getAccessTokenUrl(); 178 | $parameter = array( 179 | 'grant_type' => 'authorization_code', 180 | 'client_id' => $this->developerId, 181 | 'client_secret' => $this->secret, 182 | 'code' => $code, 183 | 'redirect_uri' => $this->redirectUrl 184 | ); 185 | 186 | $response = $this->httpClient->post( 187 | $url, 188 | $parameter 189 | ); 190 | 191 | if ($response->getCode() == 200) { 192 | $this->accessTokenInfo = json_decode($response->getContents(), true); 193 | if (isset($this->accessTokenInfo['access_token'])) { 194 | $this->accessToken = $this->accessTokenInfo['access_token']; 195 | 196 | return $this->accessToken; 197 | } 198 | } 199 | 200 | return null; 201 | } 202 | 203 | /** 204 | * Gets the fetched AccessToken 205 | * 206 | * @return string|null The AccessToken 207 | */ 208 | public function getAccessToken() 209 | { 210 | return $this->accessToken; 211 | } 212 | 213 | /** 214 | * Gets Http Client instance 215 | * 216 | * @return RakutenRws_HttpClient The Http Client 217 | */ 218 | public function getHttpClient() 219 | { 220 | return $this->httpClient; 221 | } 222 | 223 | /** 224 | * Sets the proxy to use connect rakuten service 225 | * 226 | * @param string $proxy The proxy 227 | */ 228 | public function setProxy($proxy) 229 | { 230 | $this->httpClient->setProxy($proxy); 231 | } 232 | 233 | /** 234 | * Executes API 235 | * 236 | * @param string $operation The operation name 237 | * @param array $parameter The request parameter 238 | * @param string $version The API version 239 | * @throws LogicException 240 | * @throws RakutenRws_Exception 241 | */ 242 | public function execute($operation, $parameter = array(), $version = null) 243 | { 244 | // remove '/' from operation 245 | $operation = preg_replace('/\//', '', $operation); 246 | 247 | $className = 'RakutenRws_Api_Definition_'.$operation; 248 | if (!class_exists($className)) { 249 | throw new LogicException('Operation is not definied.'); 250 | } 251 | 252 | $api = new $className($this, $this->options); 253 | if ($version !== null) { 254 | $api->setVersion($version); 255 | } 256 | 257 | return $api->execute($parameter); 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /lib/RakutenRws/Exception.php: -------------------------------------------------------------------------------- 1 | proxy = $proxy; 25 | } 26 | 27 | public function getProxy() 28 | { 29 | return $this->proxy; 30 | } 31 | 32 | public function setTimeout($timeout) 33 | { 34 | $this->timeout = $timeout; 35 | } 36 | 37 | public function getTimeout() 38 | { 39 | return $this->timeout; 40 | } 41 | 42 | abstract public function get($url, $params = array()); 43 | 44 | abstract public function post($url, $params = array()); 45 | } 46 | -------------------------------------------------------------------------------- /lib/RakutenRws/HttpClient/BasicHttpClient.php: -------------------------------------------------------------------------------- 1 | = PHP5.2.10 15 | * 16 | * @package RakutenRws 17 | * @subpackage HttpClient 18 | */ 19 | class RakutenRws_HttpClient_BasicHttpClient extends RakutenRws_HttpClient 20 | { 21 | protected function getStreamContext($url, $params, $method = 'GET') 22 | { 23 | $httpConf = array( 24 | 'method' => $method, 25 | 'request_fulluri' => true, 26 | 'ignore_errors' => true, 27 | 'timeout' => $this->timeout 28 | ); 29 | 30 | $headers = array( 31 | 'header' => 'User-Agent: RakutenWebService SDK for PHP-'.RakutenRws_Client::VERSION, 32 | ); 33 | 34 | if ($method === 'POST') { 35 | if (count($params) >= 1) { 36 | $contents = http_build_query($params); 37 | $headers[] = 'Content-Type: application/x-www-form-urlencoded'; 38 | $headers[] = 'Content-Length: '.strlen($contents); 39 | $httpConf['content'] = $contents; 40 | } 41 | } 42 | 43 | $httpConf['header'] = implode("\r\n", $headers)."\r\n"; 44 | 45 | if ($this->proxy !== null) { 46 | $httpConf['proxy'] = $httpConf['proxy'] = preg_replace( 47 | array('/^http:/', '/^https:/'), 48 | array('tcp:', 'ssl:'), 49 | $this->proxy 50 | ); 51 | } 52 | 53 | return stream_context_create(array('http' => $httpConf)); 54 | } 55 | 56 | protected function parseHeader($responseHeader) 57 | { 58 | $code = null; 59 | $headers = array(); 60 | if (isset($responseHeader) && is_array($responseHeader)) { 61 | foreach ($responseHeader as $header) { 62 | $token = explode(' ', $header); 63 | if (0 === strpos($token[0], 'HTTP/')) { 64 | $headers = array(); 65 | $code = $token[1]; 66 | } 67 | 68 | $headers[] = $header; 69 | } 70 | } 71 | 72 | return array('code' => $code, 'headers' => $headers); 73 | } 74 | 75 | public function get($url, $params = array()) 76 | { 77 | $context = $this->getStreamContext($url, $params); 78 | 79 | $requestUrl = $url; 80 | if (count($params)) { 81 | $requestUrl .= false === strpos($requestUrl, '?') ? '?' : '&'; 82 | $requestUrl .= http_build_query($params); 83 | } 84 | 85 | $contents = @file_get_contents($requestUrl, false, $context); 86 | $headerInfo = $this->parseHeader($http_response_header); 87 | 88 | return new RakutenRws_HttpResponse( 89 | $url, 90 | $params, 91 | $headerInfo['code'], 92 | $headerInfo['headers'], 93 | $contents 94 | ); 95 | } 96 | 97 | public function post($url, $params = array()) 98 | { 99 | $context = $this->getStreamContext($url, $params, 'POST'); 100 | $contents = @file_get_contents($url, false, $context); 101 | $headerInfo = $this->parseHeader($http_response_header); 102 | 103 | return new RakutenRws_HttpResponse( 104 | $url, 105 | $params, 106 | $headerInfo['code'], 107 | $headerInfo['headers'], 108 | $contents); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /lib/RakutenRws/HttpClient/CurlHttpClient.php: -------------------------------------------------------------------------------- 1 | curlOptions = $options; 26 | } 27 | 28 | protected function getHandler() 29 | { 30 | $ch = curl_init(); 31 | 32 | curl_setopt_array($ch, $this->curlOptions); 33 | if ($this->proxy !== null) { 34 | curl_setopt($ch, CURLOPT_PROXY, $this->proxy); 35 | } 36 | 37 | curl_setopt($ch, CURLOPT_USERAGENT, 'RakutenWebService SDK for PHP-'.RakutenRws_Client::VERSION); 38 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 39 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 40 | curl_setopt($ch, CURLOPT_HEADER, true); 41 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); 42 | 43 | 44 | return $ch; 45 | } 46 | 47 | protected function makeResponse($url, $params, $curl) 48 | { 49 | $rawResponse = curl_exec($curl); 50 | 51 | if ($rawResponse === false) { 52 | $msg = curl_error($curl); 53 | throw new RakutenRws_Exception('http reqeust error: '.$msg); 54 | } 55 | 56 | $parts = preg_split('/((?:\\r?\\n){2})/', $rawResponse, -1, PREG_SPLIT_DELIM_CAPTURE); 57 | for ($i = count($parts) - 3; $i >= 0; $i -= 2) { 58 | if (preg_match('/^http\//i', $parts[$i])) { 59 | $rawHeaders = $parts[$i]; 60 | $contents = implode('', array_slice($parts, $i+2)); 61 | break; 62 | } 63 | } 64 | 65 | $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); 66 | curl_close($curl); 67 | 68 | $headers = array(); 69 | foreach (preg_split('/\r?\n/', $rawHeaders) as $header) { 70 | if (!$header) { 71 | continue; 72 | } 73 | 74 | $token = explode(' ', $header); 75 | if (1 === strpos($token[0], 'HTTP/')) { 76 | $headers = array(); 77 | } 78 | 79 | $headers[] = $header; 80 | } 81 | 82 | return new RakutenRws_HttpResponse( 83 | $url, 84 | $params, 85 | $code, 86 | $headers, 87 | $contents 88 | ); 89 | } 90 | 91 | public function getCurlOptions($options) 92 | { 93 | return $this->curlOptions; 94 | } 95 | 96 | public function setCurlOptions($options) 97 | { 98 | $this->curlOptions = $options; 99 | } 100 | 101 | public function get($url, $params = array()) 102 | { 103 | $requestUrl = $url; 104 | if (count($params)) { 105 | $requestUrl .= false === strpos($requestUrl, '?') ? '?' : '&'; 106 | $requestUrl .= http_build_query($params); 107 | } 108 | 109 | $ch = $this->getHandler(); 110 | 111 | curl_setopt($ch, CURLOPT_URL, $requestUrl); 112 | 113 | return $this->makeResponse($url, $params, $ch); 114 | } 115 | 116 | public function post($url, $params = array()) 117 | { 118 | $ch = $this->getHandler(); 119 | 120 | curl_setopt($ch, CURLOPT_URL, $url); 121 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); 122 | 123 | return $this->makeResponse($url, $params, $ch); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /lib/RakutenRws/HttpClient/PearHttpClient.php: -------------------------------------------------------------------------------- 1 | client === null) { 29 | $this->client = new Http_Client(); 30 | } 31 | 32 | if ($this->proxy !== null) { 33 | $parsedUrl = parse_url($this->proxy); 34 | $this->client->setRequestParameter('proxy_host', $parsedUrl['host']); 35 | 36 | if (isset($parsedUrl['port'])) { 37 | $this->client->setRequestParameter('proxy_port', $parsedUrl['port']); 38 | } 39 | 40 | if (isset($parsedUrl['user'])) { 41 | $this->client->setRequestParameter('proxy_user', $parsedUrl['user']); 42 | } 43 | 44 | if (isset($parsedUrl['pass'])) { 45 | $this->client->setRequestParameter('proxy_pass', $parsedUrl['pass']); 46 | } 47 | } 48 | 49 | $this->client->setRequestParameter('timeout', $this->timeout); 50 | 51 | $this->client->setDefaultHeader('User-Agent', 'RakutenWebService SDK for PHP-'.RakutenRws_Client::VERSION); 52 | 53 | return $this->client; 54 | } 55 | 56 | public function get($url, $params = array()) 57 | { 58 | $client = $this->getHttpClient(); 59 | 60 | $client->get($url, $params); 61 | 62 | $response = $client->currentResponse(); 63 | 64 | return new RakutenRws_HttpResponse( 65 | $url, 66 | $params, 67 | $response['code'], 68 | $response['headers'], 69 | $response['body'] 70 | ); 71 | } 72 | 73 | public function post($url, $params = array()) 74 | { 75 | $client = $this->getHttpClient(); 76 | 77 | $client->post($url, $params); 78 | 79 | $response = $client->currentResponse(); 80 | 81 | return new RakutenRws_HttpResponse( 82 | $url, 83 | $params, 84 | $response['code'], 85 | $response['headers'], 86 | $response['body'] 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lib/RakutenRws/HttpResponse.php: -------------------------------------------------------------------------------- 1 | requestUrl = $requestUrl; 29 | $this->parameter = $parameter; 30 | $this->code = $code; 31 | $this->headers = $headers; 32 | $this->contents = $contents; 33 | } 34 | 35 | public function getUrl() { 36 | return $this->requestUrl; 37 | } 38 | 39 | public function getParameter() { 40 | return $this->parameter; 41 | } 42 | 43 | public function getCode() 44 | { 45 | return $this->code; 46 | } 47 | 48 | public function getHeaders() 49 | { 50 | return $this->headers; 51 | } 52 | 53 | public function getContents() 54 | { 55 | return $this->contents; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sample/bookmark.php: -------------------------------------------------------------------------------- 1 | setApplicationId(RAKUTEN_APP_ID); 34 | // Secretをセット 35 | $rwsclient->setSecret(RAKUTEN_APP_SECRET); 36 | // アフィリエイトIDをセット (任意) 37 | $rwsclient->setAffiliateId(RAKUTEN_APP_AFFILITE_ID); 38 | // 認証時リダイレクトURLをセット 39 | $rwsclient->setRedirectUrl($url); 40 | 41 | // リクエストに 'code' があった場合、アクセストークンを取得し 42 | // API を実行します。 43 | // If a request has 'code', get access_token and execute API 44 | if ($_GET['code']) { 45 | 46 | // アクセストークンを取得します。 47 | if ($rwsclient->fetchAccessTokenFromCode()) { 48 | 49 | // Bookmark追加APIを実行します (http://webservice.rakuten.co.jp/api/favoritebookmarkadd/) 50 | $response = $rwsclient->execute('FavoriteBookmarkAdd', array( 51 | 'itemCode' => $_GET['itemCode'] 52 | )); 53 | } 54 | 55 | // 検索画面へ戻ります 56 | header('Location: index.php?keyword='.urlencode($keyword).'&page='.urlencode($page).'&m=1'); 57 | exit; 58 | } 59 | 60 | // パラメーターに 'code' がない場合は、rakuten_favoritebookmark_update scope の 61 | // 承認画面へ遷移します 62 | header('Location: '.$rwsclient->getAuthorizeUrl('rakuten_favoritebookmark_update')); 63 | exit; 64 | -------------------------------------------------------------------------------- /sample/config.php.sample: -------------------------------------------------------------------------------- 1 | 100) { 29 | $lastPage = 100; 30 | } 31 | 32 | $first = 2; 33 | if ($lastPage > $size) { 34 | if ($currentPage > $size + 2) { 35 | $first = $currentPage - $size; 36 | } 37 | } 38 | 39 | for ($i = $first; $i <= $lastPage && $i <= $currentPage + $size; $i++) { 40 | $pages[] = $i; 41 | } 42 | 43 | if ($currentPage + $size < $lastPage) { 44 | $pages[] = $lastPage; 45 | } 46 | 47 | $list = array(); 48 | 49 | if ($currentPage != 1) { 50 | $list[] = '