hotel_price 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efe90b37dbfce28221680cc53d48028075f6554675211d77ec3cfe4f5bb3a751
4
- data.tar.gz: cda8a6f66d6646b4e381b5dbd2a56e2caa535a4afed7a4b0a26c21d02a189183
3
+ metadata.gz: 8271fc1ad3a22ae3308a9a9fc6e4b71e2b75bbc04b27e9f9fb380dcba14d6d5f
4
+ data.tar.gz: 57f8bb20af2a5b0b8024b1c341060da9c03f5b99070be2b45ffe8502b5025988
5
5
  SHA512:
6
- metadata.gz: 30b4fa66f015dbe664ff31192ce4aa323058d901db965d9bf559f83dd6d7d7cbddb2f73f8d9b36d30dd0f055ea0d1075c092770d8979c66e58701ca76629d16a
7
- data.tar.gz: d283d178c4af4f5f34093c71aa462252d11e7e18e6d13a9ff7daf625e1a71bb2c7adbc37c59808d2a5ec63210b229497e0afe0429e4f7f97ca7274b7e4b055f8
6
+ metadata.gz: 6b895ba6069ad8042362ad936ad0b4275ca2034a57e3d07159041e915181fa6a99acf8096b1ab582697c7294ad45f466403a031d3119a2b13679b7ae1f77e613
7
+ data.tar.gz: 0e006edc3409af3fe1e00b6f8cb0acfb95e63ef91bd60b7438e86848639d3703bef32fbb5f54b1c7ffc918cfeecdd578d5357c84be5bb80aac4c1d52d22e7870
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.3.9)
4
+ hotel_price (0.4.1)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
@@ -99,7 +99,6 @@ module HotelPrice::Rakuten
99
99
  uri = URI.parse("https://app.rakuten.co.jp/services/api/Travel/HotelDetailSearch/20131024?hotelNo=" + @config[:rakuten_hotel_id].to_s + "&applicationId=" + @config[:rakuten_api_key].to_s + "&datumType=1&responseType=large")
100
100
  json = Net::HTTP.get(uri)
101
101
  result = JSON.parse(json)
102
- puts uri
103
102
  return "ホテル情報がありませんでした。" if result["error"] == "not_found"
104
103
  return result["error_description"] if result["error"] == "wrong_parameter"
105
104
  result["hotels"][0].each do |_key, field|
@@ -164,12 +163,23 @@ module HotelPrice::Rakuten
164
163
  @data_hash
165
164
  end
166
165
 
167
- def search_ranking(params = {})
166
+ def get_area_rank
167
+ body = get_page_num
168
+ (1..body[:page_num]).each do |i|
169
+ body[:page_num] = i
170
+ rank = search_ranking(body)
171
+ return rank if rank[:status] == "found"
172
+ end
173
+ { status: "not_found" }
174
+ end
175
+
176
+ def search_ranking params
168
177
  body = {
169
178
  middle_class_code: params[:middle_class_code],
170
179
  small_class_code: params[:small_class_code],
171
180
  detail_class_code: params[:detail_class_code],
172
- page_num: params[:page_num]
181
+ page_num: params[:page_num],
182
+ area_name: params[:area_name]
173
183
  }
174
184
  url = "https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426?applicationId=#{@config[:rakuten_api_key]}&largeClassCode=japan&middleClassCode=#{body[:middle_class_code]}&smallClassCode=#{body[:small_class_code]}&detailClassCode=#{body[:detail_class_code]}&page=#{body[:page_num]}"
175
185
  uri = URI.parse(url)
@@ -179,9 +189,13 @@ module HotelPrice::Rakuten
179
189
  result["hotels"].each do |key, _value|
180
190
  if @config[:rakuten_hotel_id] == key["hotel"][0]["hotelBasicInfo"]["hotelNo"].to_s
181
191
  return {
182
- area_rank: i.to_i + ((body[:page_num].to_i - 1) * 30),
192
+ status: "found",
183
193
  hotel_name: key["hotel"][0]["hotelBasicInfo"]["hotelName"],
184
- status: "found"
194
+ area_name: body[:area_name],
195
+ area_rank: i.to_i + ((body[:page_num].to_i - 1) * 30),
196
+ middle_class_code: body[:middle_class_code],
197
+ small_class_code: body[:small_class_code],
198
+ detail_class_code: body[:detail_class_code]
185
199
  }
186
200
  end
187
201
  i += 1
@@ -189,18 +203,20 @@ module HotelPrice::Rakuten
189
203
  { status: "not_found" }
190
204
  end
191
205
 
192
- def get_page_num(params = {})
193
- body = {
194
- middle_class_code: hotel.middle_class_code,
195
- small_class_code: hotel.small_class_code,
196
- detail_class_code: hotel.detail_class_code
197
- }
198
- url = "https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426?applicationId=#{@config[:rakuten_api_key]}&largeClassCode=japan&middleClassCode=#{body[:middle_class_code]}&smallClassCode=#{body[:small_class_code]}&detailClassCode=#{body[:detail_class_code]}"
199
- puts url
206
+ def get_page_num
207
+ detail_class_code = HotelPrice::Rakuten::RakutenScraper.get_detail_class_code(@config[:rakuten_hotel_id])[:detail_class_code]
208
+ hotel = hotel_info
209
+ url = "https://app.rakuten.co.jp/services/api/Travel/SimpleHotelSearch/20170426?applicationId=#{@config[:rakuten_api_key]}&largeClassCode=japan&middleClassCode=#{hotel[:middle_class_code]}&smallClassCode=#{hotel[:small_class_code]}&detailClassCode=#{detail_class_code}"
200
210
  uri = URI.parse(url)
201
211
  json = Net::HTTP.get(uri)
202
212
  result = JSON.parse(json)
203
- result["pagingInfo"]["pageCount"]
213
+ {
214
+ small_class_code: hotel[:small_class_code],
215
+ middle_class_code: hotel[:middle_class_code],
216
+ detail_class_code: detail_class_code,
217
+ area_name: hotel[:area_name].to_s,
218
+ page_num: result["pagingInfo"]["pageCount"].to_i
219
+ }
204
220
  end
205
221
  end
206
222
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotel_price
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki