rakuten_web_service 0.6.3 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.travis.yml +19 -3
  4. data/CHANGELOG.md +14 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +5 -0
  7. data/README.ja.md +133 -0
  8. data/README.md +129 -48
  9. data/examples/books_item_search.rb +24 -0
  10. data/examples/gora_search.rb +48 -0
  11. data/examples/ichiba_item_search.rb +1 -3
  12. data/lib/rakuten_web_service.rb +2 -0
  13. data/lib/rakuten_web_service/all_proxy.rb +20 -0
  14. data/lib/rakuten_web_service/client.rb +6 -13
  15. data/lib/rakuten_web_service/configuration.rb +28 -4
  16. data/lib/rakuten_web_service/gora.rb +3 -0
  17. data/lib/rakuten_web_service/gora/course.rb +17 -0
  18. data/lib/rakuten_web_service/gora/course_detail.rb +55 -0
  19. data/lib/rakuten_web_service/gora/plan.rb +47 -0
  20. data/lib/rakuten_web_service/ichiba/item.rb +5 -4
  21. data/lib/rakuten_web_service/ichiba/shop.rb +1 -1
  22. data/lib/rakuten_web_service/kobo/ebook.rb +2 -2
  23. data/lib/rakuten_web_service/recipe.rb +28 -0
  24. data/lib/rakuten_web_service/recipe/category.rb +60 -0
  25. data/lib/rakuten_web_service/resource.rb +9 -1
  26. data/lib/rakuten_web_service/search_result.rb +43 -19
  27. data/lib/rakuten_web_service/version.rb +1 -1
  28. data/rakuten_web_service.gemspec +2 -2
  29. data/spec/fixtures/gora/course_detail_search.json +1 -0
  30. data/spec/fixtures/gora/course_search_with_Karuizawa.json +1 -0
  31. data/spec/fixtures/gora/plan_search_with_area_code.json +1 -0
  32. data/spec/fixtures/recipe/category.json +1 -0
  33. data/spec/fixtures/recipe/ranking.json +1 -0
  34. data/spec/rakuten_web_service/books/book_spec.rb +1 -2
  35. data/spec/rakuten_web_service/books/cd_spec.rb +1 -2
  36. data/spec/rakuten_web_service/books/dvd_spec.rb +1 -2
  37. data/spec/rakuten_web_service/books/foreign_book_spec.rb +1 -2
  38. data/spec/rakuten_web_service/books/game_spec.rb +1 -2
  39. data/spec/rakuten_web_service/books/genre_spec.rb +1 -2
  40. data/spec/rakuten_web_service/books/magazine_spec.rb +1 -2
  41. data/spec/rakuten_web_service/books/software_spec.rb +1 -2
  42. data/spec/rakuten_web_service/books/total_spec.rb +1 -2
  43. data/spec/rakuten_web_service/client_spec.rb +3 -3
  44. data/spec/rakuten_web_service/configuration_spec.rb +45 -4
  45. data/spec/rakuten_web_service/gora/course_detail_spec.rb +60 -0
  46. data/spec/rakuten_web_service/gora/course_spec.rb +108 -0
  47. data/spec/rakuten_web_service/gora/plan_spec.rb +62 -0
  48. data/spec/rakuten_web_service/ichiba/genre_spec.rb +1 -2
  49. data/spec/rakuten_web_service/ichiba/item_spec.rb +53 -8
  50. data/spec/rakuten_web_service/ichiba/product_search_spec.rb +2 -3
  51. data/spec/rakuten_web_service/ichiba/ranking_spec.rb +1 -1
  52. data/spec/rakuten_web_service/ichiba/shop_spec.rb +2 -3
  53. data/spec/rakuten_web_service/kobo/ebook_spec.rb +2 -3
  54. data/spec/rakuten_web_service/kobo/genre_spec.rb +1 -2
  55. data/spec/rakuten_web_service/recipe/category_spec.rb +185 -0
  56. data/spec/rakuten_web_service/recipe_spec.rb +50 -0
  57. data/spec/spec_helper.rb +16 -6
  58. metadata +42 -11
  59. data/README.en.md +0 -108
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This is a sample script f Rakuten Books APIs.
4
+ # RWS Ruby SDK supports Books API. The inteface is similar to ones Ichiba API.
5
+ # If you want to search CDs dealt in Rakuten Books, you can do it with `RakutenWebService::Books::CD`.
6
+ # As for other resources, there are `RakutenWebService::Books::Book`, `RakutenWebService::Books::DVD` and so on.
7
+ # Please refer to the following documents if you want more detail of input/output parameters:
8
+ # http://webservice.rakuten.co.jp/document/
9
+ #
10
+
11
+ require 'rakuten_web_service'
12
+
13
+ application_id = ARGV.shift
14
+ keyword = ARGV[0..-1].join(' ')
15
+
16
+ RakutenWebService.configure do |c|
17
+ c.application_id = application_id
18
+ end
19
+
20
+ cds = RakutenWebService::Books::CD.search(:title => keyword)
21
+
22
+ cds.first(10).each do |cd|
23
+ puts "#{cd.title} (#{cd.title_kana}):\n\t #{cd.play_list}"
24
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ #
3
+ # This is a sample script f Rakuten Gora APIs.
4
+ # RWS Ruby SDK supports Gora API. The inteface is similar to ones Ichiba API.
5
+ # If you want to search courses dealt in Rakuten Gora, you can do it with `RakutenWebService::Gora::Course`.
6
+ # As for other resources, there are `RakutenWebService::Gora::CourseDetail`, `RakutenWebService::Gora::Plan` and so on.
7
+ # Please refer to the following documents if you want more detail of input/output parameters:
8
+ # http://webservice.rakuten.co.jp/document/
9
+ #
10
+
11
+ require 'rakuten_web_service'
12
+ require 'date'
13
+
14
+ application_id = ARGV.shift
15
+ keyword = ARGV.shift || '軽井沢'
16
+
17
+ RakutenWebService.configure do |c|
18
+ c.application_id = application_id
19
+ end
20
+
21
+ c = RakutenWebService::Gora::Course.search(:keyword => keyword).first
22
+ id = c.golf_course_id
23
+ puts id
24
+ puts c.golf_course_name
25
+ puts c.address
26
+
27
+ d = RakutenWebService::Gora::CourseDetail.find(id)
28
+ puts d.green
29
+ puts d.green_count
30
+ puts d.course_distance
31
+ puts d.long_driving_contest
32
+ puts d.near_pin
33
+ puts d.evaluation
34
+ d.new_plans.each do |p|
35
+ puts " #{p.month}: #{p.name}"
36
+ end
37
+
38
+ next_week = Date.today + 7
39
+ chiba_and_kanagawa = '12,14'
40
+ plans = RWS::Gora::Plan.search(:areaCode => chiba_and_kanagawa, :playDate => next_week.strftime('%Y-%m-%d'))
41
+ plans.first(5).each { |p|
42
+ puts "#{p.golf_course_id}, #{p.golf_course_name}"
43
+ p.plan_info.each { |pi|
44
+ puts " #{pi.plan_id}, #{pi.plan_name}, #{pi.price}"
45
+ ci = pi.call_info
46
+ puts " #{ci.play_date}, #{ci.stock_status}"
47
+ }
48
+ }
@@ -1,11 +1,9 @@
1
- # encoding: utf-8
2
-
3
1
  require 'rakuten_web_service'
4
2
 
5
3
  application_id = ARGV.shift
6
4
  keyword = ARGV[0..-1].join(' ')
7
5
 
8
- RakutenWebService.configuration do |c|
6
+ RakutenWebService.configure do |c|
9
7
  c.application_id = application_id
10
8
  end
11
9
 
@@ -4,3 +4,5 @@ RWS = RakutenWebService
4
4
  require 'rakuten_web_service/ichiba'
5
5
  require 'rakuten_web_service/books'
6
6
  require 'rakuten_web_service/kobo'
7
+ require 'rakuten_web_service/gora'
8
+ require 'rakuten_web_service/recipe'
@@ -0,0 +1,20 @@
1
+ module RakutenWebService
2
+ class AllProxy
3
+ include Enumerable
4
+
5
+ def initialize(search_result)
6
+ @search_result = search_result
7
+ end
8
+
9
+ def each
10
+ search_result = @search_result
11
+ loop do
12
+ search_result.each do |resource|
13
+ yield resource
14
+ end
15
+ break unless search_result.has_next_page?
16
+ search_result = search_result.next_page
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'faraday'
2
3
  require 'faraday_middleware'
3
4
 
@@ -20,10 +21,9 @@ module RakutenWebService
20
21
  @path = url.path
21
22
  end
22
23
 
23
- def get(query)
24
- query = RakutenWebService.configuration.generate_parameters.merge(query)
25
- query = convert_snake_key_to_camel_key(query)
26
- response = connection.get(path, query)
24
+ def get(params)
25
+ params = RakutenWebService.configuration.generate_parameters(params)
26
+ response = connection.get(path, params)
27
27
  case response.status
28
28
  when 200
29
29
  return RakutenWebService::Response.new(@resource_class, response.body)
@@ -46,16 +46,9 @@ module RakutenWebService
46
46
  @connection = Faraday.new(:url => url) do |conn|
47
47
  conn.request :url_encoded
48
48
  conn.response :json
49
+ conn.response :logger if RakutenWebService.configuration.debug
49
50
  conn.adapter Faraday.default_adapter
50
- conn.headers['User-Agent'] = "RakutenWebService SDK for Ruby-#{RWS::VERSION}"
51
- end
52
- end
53
-
54
- def convert_snake_key_to_camel_key(params)
55
- params.inject({}) do |h, (k, v)|
56
- k = k.to_s.gsub(/([a-z]{1})_([a-z]{1})/) { "#{$1}#{$2.capitalize}" }
57
- h[k] = v
58
- h
51
+ conn.headers['User-Agent'] = "RakutenWebService SDK for Ruby v#{RWS::VERSION}(ruby-#{RUBY_VERSION} [#{RUBY_PLATFORM}])"
59
52
  end
60
53
  end
61
54
  end
@@ -1,17 +1,36 @@
1
+ require 'logger'
2
+
1
3
  module RakutenWebService
2
4
  class Configuration
3
- attr_accessor :application_id, :affiliate_id, :max_retries
5
+ attr_accessor :application_id, :affiliate_id, :max_retries, :debug
4
6
 
5
7
  def initialize
6
8
  @max_retries = 5
7
9
  end
8
10
 
9
- def generate_parameters
11
+ def generate_parameters(params)
12
+ convert_snake_key_to_camel_key(default_parameters.merge(params))
13
+ end
14
+
15
+ def default_parameters
10
16
  { :application_id => application_id, :affiliate_id => affiliate_id }
11
17
  end
18
+
19
+ def debug_mode?
20
+ ENV.has_key?('RWS_SDK_DEBUG') || debug
21
+ end
22
+
23
+ private
24
+ def convert_snake_key_to_camel_key(params)
25
+ params.inject({}) do |h, (k, v)|
26
+ k = k.to_s.gsub(/([a-z]{1})_([a-z]{1})/) { "#{$1}#{$2.capitalize}" }
27
+ h[k] = v
28
+ h
29
+ end
30
+ end
12
31
  end
13
32
 
14
- def configuration(&block)
33
+ def configure(&block)
15
34
  @configuration ||= Configuration.new
16
35
  if block
17
36
  if block.arity != 1
@@ -22,5 +41,10 @@ module RakutenWebService
22
41
  return @configuration
23
42
  end
24
43
 
25
- module_function :configuration
44
+ def configuration(&block)
45
+ $stderr.puts "Warning: RakutenWebService.configuration is deprecated. Use RakutenWebService.configure." if block_given?
46
+ self.configure(&block)
47
+ end
48
+
49
+ module_function :configure, :configuration
26
50
  end
@@ -0,0 +1,3 @@
1
+ require 'rakuten_web_service/gora/course'
2
+ require 'rakuten_web_service/gora/course_detail'
3
+ require 'rakuten_web_service/gora/plan'
@@ -0,0 +1,17 @@
1
+ require 'rakuten_web_service/resource'
2
+
3
+ module RakutenWebService
4
+ module Gora
5
+ class Course < Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseSearch/20131113'
7
+
8
+ set_parser do |response|
9
+ response['Items'].map { |item| self.new(item['Item']) }
10
+ end
11
+
12
+ attribute :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
13
+ :address, :latitude, :longitude, :highway, :golfCourseDetailUrl, :reserveCalUrl, :ratingUrl,
14
+ :golfCourseImageUrl, :evaluation
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,55 @@
1
+ require 'rakuten_web_service/resource'
2
+
3
+ module RakutenWebService
4
+ module Gora
5
+ class CourseDetail < Resource
6
+ class << self
7
+ def find(golf_course_id)
8
+ search({golfCourseId: golf_course_id}).first
9
+ end
10
+ end
11
+
12
+ endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseDetail/20140410'
13
+
14
+ set_parser do |response|
15
+ [self.new(response['Item'])]
16
+ end
17
+
18
+ attribute :carrier, :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
19
+ :information, :highway, :ic, :icDistance, :latitude, :longitude, :postalCode, :address, :telephoneNo,
20
+ :faxNo, :openDay, :closeDay, :creditCard, :shoes, :dressCode, :practiceFacility, :lodgingFacility,
21
+ :otherFacility, :golfCourseImageUrl1, :golfCourseImageUrl2, :golfCourseImageUrl3, :golfCourseImageUrl4,
22
+ :golfCourseImageUrl5, :weekdayMinPrice, :baseWeekdayMinPrice, :holidayMinPrice, :baseHolidayMinPrice,
23
+ :designer, :courseType, :courseVerticalInterval, :dimension, :green, :greenCount, :holeCount, :parCount,
24
+ :courseName, :courseDistance, :longDrivingContest, :nearPin, :ratingNum, :evaluation, :staff, :facility,
25
+ :meal, :course, :costperformance, :distance, :fairway, :reserveCalUrl, :voiceUrl, :layoutUrl, :routeMapUrl
26
+
27
+ def ratings
28
+ get_attribute('ratings').map {|rating| Rating.new(rating['rating'])}
29
+ end
30
+
31
+ def new_plans
32
+ get_attribute('newPlans').map {|plan| Plan.new(plan['plan'])}
33
+ end
34
+
35
+ class Rating < Resource
36
+ class << self
37
+ def search(options)
38
+ raise 'There is no API endpoint for this resource.'
39
+ end
40
+ end
41
+ attribute :title, :nickName, :prefecture, :age, :sex, :times, :evaluation, :staff, :facility, :meal, :course,
42
+ :costperformance, :distance, :fairway, :comment
43
+ end
44
+
45
+ class Plan < Resource
46
+ class << self
47
+ def search(options)
48
+ raise 'There is no API endpoint for this resource.'
49
+ end
50
+ end
51
+ attribute :month, :planName, :planDate, :service, :price, :basePrice, :salesTax, :courseUseTax, :otherTax
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,47 @@
1
+ require 'rakuten_web_service/resource'
2
+
3
+ module RakutenWebService
4
+ module Gora
5
+ class Plan < Resource
6
+ endpoint 'https://app.rakuten.co.jp/services/api/Gora/GoraPlanSearch/20150706'
7
+
8
+ set_parser do |response|
9
+ response['Items'].map { |item| self.new(item['Item']) }
10
+ end
11
+
12
+ attribute :golfCourseId, :golfCourseName, :golfCourseAbbr, :golfCourseNameKana, :golfCourseCaption,
13
+ :address, :latitude, :longitude, :highway, :golfCourseDetailUrl, :reserveCalUrl, :ratingUrl,
14
+ :golfCourseImageUrl, :evaluation
15
+
16
+ def plan_info
17
+ get_attribute('planInfo').map {|plan| PlanInfo.new(plan['plan'])}
18
+ end
19
+
20
+ class PlanInfo < Resource
21
+ class << self
22
+ def search(options)
23
+ raise 'There is no API endpoint for this resource.'
24
+ end
25
+ end
26
+ attribute :planId, :planName, :planType, :limitedTimeFlag, :price, :basePrice, :salesTax, :courseUseTax,
27
+ :otherTax, :playerNumMin, :playerNumMax, :startTimeZone, :round, :caddie, :cart, :assu2sum,:addFee2bFlag,
28
+ :addFee2b, :assortment2bFlag, :addFee3bFlag, :addFee3b, :assortment3bFlag, :discount4sumFlag, :lunch,
29
+ :drink, :stay, :lesson, :planOpenCompe, :compePlayGroupMin, :compePlayMemberMin, :compePrivilegeFree,
30
+ :compeOption, :other, :pointFlag, :point
31
+
32
+ def call_info
33
+ CallInfo.new(get_attribute('callInfo'))
34
+ end
35
+
36
+ class CallInfo < Resource
37
+ class << self
38
+ def search(options)
39
+ raise 'There is no API endpoint for this resource.'
40
+ end
41
+ end
42
+ attribute :playDate, :stockStatus, :stockCount, :reservePageUrlPC, :reservePageUrlMobile
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -8,8 +8,8 @@ module RakutenWebService
8
8
  RakutenWebService::Ichiba::RankingItem.search(options)
9
9
  end
10
10
  end
11
-
12
- endpoint 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20130805'
11
+
12
+ endpoint 'https://app.rakuten.co.jp/services/api/IchibaItem/Search/20140222'
13
13
 
14
14
  set_parser do |response|
15
15
  response['Items'].map { |item| Item.new(item['Item']) }
@@ -27,7 +27,7 @@ module RakutenWebService
27
27
  :startTime, :endTime,
28
28
  :reviewCount, :reviewAverage,
29
29
  :pointRate, :pointRateStartTime, :pointRateEndTime,
30
- :shopName, :shopCode, :shopUrl,
30
+ :shopName, :shopCode, :shopUrl, :shopAffiliateUrl,
31
31
  :genreId
32
32
 
33
33
  def genre
@@ -38,7 +38,8 @@ module RakutenWebService
38
38
  Shop.new({
39
39
  'shopName' => self.shop_name,
40
40
  'shopCode' => self.shop_code,
41
- 'shopUrl' => self.shop_url
41
+ 'shopUrl' => self.shop_url,
42
+ 'shopAffiliateUrl' => self.shop_affiliate_url
42
43
  })
43
44
  end
44
45
  end
@@ -4,7 +4,7 @@ require 'rakuten_web_service/ichiba/item'
4
4
  module RakutenWebService
5
5
  module Ichiba
6
6
  class Shop < Resource
7
- attribute :shopName, :shopCode, :shopUrl
7
+ attribute :shopName, :shopCode, :shopUrl, :shopAffiliateUrl
8
8
 
9
9
  def items(options={})
10
10
  options = options.merge(:shop_code => self.code)
@@ -5,9 +5,9 @@ require 'rakuten_web_service/resource'
5
5
  module RakutenWebService
6
6
  module Kobo
7
7
  class Ebook < RakutenWebService::Resource
8
- endpoint 'https://app.rakuten.co.jp/services/api/Kobo/EbookSearch/20131010'
8
+ endpoint 'https://app.rakuten.co.jp/services/api/Kobo/EbookSearch/20140811'
9
9
 
10
- attribute :title, :titleKana, :subTitle,
10
+ attribute :title, :titleKana, :subTitle, :seriesName,
11
11
  :author, :authorKana, :publisherName,
12
12
  :itemNumber, :itemCaption,
13
13
  :salesDate, :itemPrice,
@@ -0,0 +1,28 @@
1
+ require 'rakuten_web_service/configuration'
2
+
3
+ require 'rakuten_web_service/recipe/category'
4
+
5
+ module RakutenWebService
6
+ class Recipe < Resource
7
+ endpoint 'https://app.rakuten.co.jp/services/api/Recipe/CategoryRanking/20121121'
8
+
9
+ attribute :recipeId, :recipeTitle, :recipeUrl,
10
+ :foodImageUrl, :mediumImageUrl, :smallImageUrl,
11
+ :pickup, :shop, :nickname,
12
+ :recipeDescription, :recipeMaterial,
13
+ :recipeIndication, :recipeCost,
14
+ :recipePublishday, :rank
15
+
16
+ set_parser do |response|
17
+ response['result'].map { |r| Recipe.new(r) }
18
+ end
19
+
20
+ def self.ranking(category)
21
+ self.search(category_id: category)
22
+ end
23
+
24
+ class << self
25
+ protected :search
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,60 @@
1
+ module RakutenWebService
2
+ class Recipe < Resource
3
+
4
+ def self.large_categories
5
+ categories('large')
6
+ end
7
+
8
+ def self.medium_categories
9
+ categories('medium')
10
+ end
11
+
12
+ def self.small_categories
13
+ categories('small')
14
+ end
15
+
16
+ def self.categories(category_type)
17
+ @categories ||= {}
18
+ @categories[category_type] ||= Category.search(category_type: category_type).response['result'][category_type].map do |category|
19
+ Category.new(category.merge(categoryType: category_type))
20
+ end
21
+ end
22
+
23
+ class << self
24
+ protected :search
25
+ end
26
+
27
+ class Category < Resource
28
+ endpoint 'https://app.rakuten.co.jp/services/api/Recipe/CategoryList/20121121'
29
+
30
+ attribute :categoryId, :categoryName, :categoryUrl, :parentCategoryId, :categoryType
31
+
32
+ def ranking
33
+ Recipe.ranking(absolute_category_id)
34
+ end
35
+
36
+ def parent_category
37
+ return nil if parent_category_type.nil?
38
+ Recipe.categories(parent_category_type).find { |c| c.id.to_i === parent_category_id.to_i }
39
+ end
40
+
41
+ def absolute_category_id
42
+ if parent_category
43
+ [parent_category.absolute_category_id, id.to_s].join('-')
44
+ else
45
+ id.to_s
46
+ end
47
+ end
48
+
49
+ private
50
+ def parent_category_type
51
+ case type
52
+ when 'small' then 'medium'
53
+ when 'medium' then 'large'
54
+ else
55
+ nil
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end