hotel_price 0.3.9 → 0.4.0

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: 0f785c18b6a55388aa61ae8580d92e2ad24c5eee8edf6f996bb5b188b16af1d0
4
- data.tar.gz: fc8915c693cde72347f71461deb09bd7ef54e89574d928b9220ca1a7f59ae1b2
3
+ metadata.gz: 29b85ee0e8478b226d95b31d1f1eb18ce0d9165bf5cb7cf4d4f3165e906c35f8
4
+ data.tar.gz: cff34413dc55092d53228bc8048c2d669f26357887deeb264d178d54e4fef048
5
5
  SHA512:
6
- metadata.gz: ce184e34ebc4394c1ff7f6f27d951afa5cc0f3b7bb1c78de35a029e14ebf01a50b16256cbae16c1579fc91f1ce3f36f077a9fc352be4f7ede01bde517f137710
7
- data.tar.gz: 4b61029941a79252166d53ad2015e55ecddc0dc26396cae1616397a14de39544d685eaea17577634434ef339e60cde9d0b202cdb42743dd77569879579630b92
6
+ metadata.gz: 930bf9bd9fad63ed2655567a5baf09fab6f5b6b866f1b95e2470fa0dca922bbd886cd9e72133d40d974bc72ed64ace90170bee92e7c2b32b49ca009e860fbcd1
7
+ data.tar.gz: dd6bb55154eb12b56d87f21dda4580fcb7d361e6def1fd13a6c762f20a67993607534d977b2f9d407037f46288b8f9154cfbd05483e995a8dee4074ad886b0df
data/.rubocop.yml CHANGED
@@ -223,4 +223,7 @@ Lint/NonDeterministicRequireOrder:
223
223
  Enabled: false
224
224
 
225
225
  Style/RescueModifier:
226
+ Enabled: false
227
+
228
+ Style/RegexpLiteral:
226
229
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.3.8)
4
+ hotel_price (0.3.9)
5
5
  activesupport (~> 6.0.2.1)
6
6
  json (~> 2.3.0)
7
7
  nokogiri (~> 1.10.9)
@@ -99,6 +99,7 @@ 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
102
103
  return "ホテル情報がありませんでした。" if result["error"] == "not_found"
103
104
  return result["error_description"] if result["error"] == "wrong_parameter"
104
105
  result["hotels"][0].each do |_key, field|
@@ -174,18 +175,32 @@ module HotelPrice::Rakuten
174
175
  uri = URI.parse(url)
175
176
  json = Net::HTTP.get(uri)
176
177
  result = JSON.parse(json)
177
- @i = 1
178
+ i = 1
178
179
  result["hotels"].each do |key, _value|
179
180
  if @config[:rakuten_hotel_id] == key["hotel"][0]["hotelBasicInfo"]["hotelNo"].to_s
180
181
  return {
181
- area_rank: @i.to_i + ((body[:page_num].to_i - 1) * 30),
182
+ area_rank: i.to_i + ((body[:page_num].to_i - 1) * 30),
182
183
  hotel_name: key["hotel"][0]["hotelBasicInfo"]["hotelName"],
183
184
  status: "found"
184
185
  }
185
186
  end
186
- @i += 1
187
+ i += 1
187
188
  end
188
- { status: "no" }
189
+ { status: "not_found" }
190
+ end
191
+
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
200
+ uri = URI.parse(url)
201
+ json = Net::HTTP.get(uri)
202
+ result = JSON.parse(json)
203
+ result["pagingInfo"]["pageCount"]
189
204
  end
190
205
  end
191
206
  end
@@ -61,13 +61,27 @@ module HotelPrice::Rakuten
61
61
  plan_num.size
62
62
  end
63
63
 
64
+ def self.get_detail_class_code rakuten_hotel_id
65
+ driver = self.get_selenium_driver
66
+ driver.get "https://hotel.travel.rakuten.co.jp/hinfo/?f_no=#{rakuten_hotel_id}"
67
+ {
68
+ status: "found",
69
+ detail_class_code: driver.find_element(id: "breadcrumbs-detail").attribute("href").match(/\/.\./).to_s.gsub("/", "").gsub(".", "")
70
+ }
71
+ rescue
72
+ {
73
+ status: "not_found",
74
+ detail_class_code: ""
75
+ }
76
+ end
77
+
64
78
  def self.get_selenium_driver
65
79
  # firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
66
80
  # @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
67
-
81
+
68
82
  options = Selenium::WebDriver::Firefox::Options.new
69
83
  options.add_argument("-headless")
70
- Selenium::WebDriver.for :firefox#, options: options
84
+ Selenium::WebDriver.for :firefox, options: options
71
85
  end
72
86
 
73
87
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.0"
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.3.9
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki