hotel_price 0.2.2 → 0.2.3

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: 7a4c5a3f6cbbe65473cb75159bffe08427d56715d6c7658c80ddd43be4d6fb2e
4
- data.tar.gz: c430e764095d019bfe233172e26afa84aba5d8ddc097b26dd53e0f2e2e6875fc
3
+ metadata.gz: 3c9d7a1e1951f2c204dd858f69763db0b532ab041c2f86b3467654343f4e49df
4
+ data.tar.gz: 3049419b19b1ea0e952eb327af9366e7e508d7cc45a551fd0c6454aa2d45bf5b
5
5
  SHA512:
6
- metadata.gz: 8438a25ced4479c39e48f88f35fc3bc56bdf269fa1423706e7820d29b6a9b8a5060a854ecc58f950964753f3b403972fc8995d580840b70b33506bdeac2cd11f
7
- data.tar.gz: b36957e05bc1b67a702714e92ce227131c63fd764934c99aedd4efbdd46517a18874488ccdbc7b890aa5f4fb08a50f507827ba86327cbbba7742c7d3776a2d07
6
+ metadata.gz: 2e4d6f1152410739ab1b03aa4018ed74ff9870f6cfa76a83ce19807246478d976a894b0ed12ea1f830e3bc53921aa6544d07cef0b3c14fb2a6fe14ac315412d8
7
+ data.tar.gz: 8d76ffa7b0ba2cd6103bb87b5fb94fe2f9aaae6a313b7e776557fb398e82ffb7adcd5b71ef82e9fcc7c7db40146290bb2d1de2f142fa58d47029c8b5bd524e92
data/.gitignore CHANGED
@@ -7,6 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.envrc
10
+ .idea
10
11
 
11
12
  # rspec failure tracking
12
13
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.2.1)
4
+ hotel_price (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/hotel_price CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'hotel_price'
2
+ require "hotel_price"
3
3
 
4
- puts HotelPrice.rakuten_travel
4
+ puts HotelPrice.rakuten_travel
@@ -1,4 +1,4 @@
1
- module Jalan
1
+ module HotelPrice::Jalan
2
2
  class JalanAPI
3
3
  def initialize api_key
4
4
  @api_key = api_key
@@ -0,0 +1,6 @@
1
+ require_relative "./jalan/jalan_api"
2
+
3
+ module HotelPrice
4
+ module Jalan
5
+ end
6
+ end
@@ -0,0 +1,78 @@
1
+ module HotelPrice::Rakuten
2
+ class RakutenAPI
3
+ def initialize params
4
+ @config = {
5
+ rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
6
+ rakuten_api_key: params[:rakuten_api_key] ||= ENV["RT_API_KEY"]
7
+ }
8
+ end
9
+
10
+ def hotel_info
11
+ 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")
12
+ json = Net::HTTP.get(uri)
13
+ @result = JSON.parse(json)
14
+ return "ホテル情報がありませんでした。" if @result["error"] == "not_found"
15
+ return @result["error_description"] if @result["error"] == "wrong_parameter"
16
+ @result["hotels"][0].each do |_key, field|
17
+ field[0].each do |_, value|
18
+ @data_hash = {
19
+ rakuten_hotel_id: value["hotelNo"],
20
+ hotel_name: value["hotelName"],
21
+ room_price_min: value["hotelMinCharge"],
22
+ lat: value["latitude"],
23
+ lon: value["longitude"],
24
+ tel: value["telephoneNo"],
25
+ zip_code: value["postalCode"],
26
+ prefecture: value["address1"],
27
+ address1: value["address2"],
28
+ fax: value["faxNo"],
29
+ access: value["access"],
30
+ parking_info: value["parkingInformation"],
31
+ near_station: value["nearestStation"],
32
+ hotel_img_url: value["hotelImageUrl"],
33
+ rakuten_review_count: value["reviewCount"],
34
+ rakuten_review_avg: value["reviewAverage"].to_f
35
+ }
36
+ end
37
+ end
38
+ @result["hotels"][0].each do |_key, field|
39
+ field[1].each do |_, value|
40
+ @data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
41
+ @data_hash["rakuten_location_review"] = value["locationAverage"].to_f
42
+ @data_hash["rakuten_room_review"] = value["roomAverage"].to_f
43
+ @data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
44
+ @data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
45
+ @data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
46
+ end
47
+ end
48
+ @result["hotels"][0].each do |_key, field|
49
+ field[2].each do |_, value|
50
+ @data_hash["middle_class_code"] = value["middleClassCode"].to_s
51
+ @data_hash["small_class_code"] = value["smallClassCode"].to_s
52
+ @data_hash["area_name"] = value["areaName"].to_s
53
+ @data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
54
+ @data_hash["checkin_time"] = value["checkinTime"].to_s
55
+ @data_hash["checkout_time"] = value["checkoutTime"].to_s
56
+ @data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
57
+ end
58
+ end
59
+ @result["hotels"][0].each do |_key, field|
60
+ field[3].each do |_, value|
61
+ @data_hash["total_room_num"] = value["hotelRoomNum"].to_s
62
+ room_facilities = []
63
+ value["roomFacilities"].each_with_index do |f, i|
64
+ room_facilities[i] = f["item"]
65
+ end
66
+ @data_hash["room_facilities"] = room_facilities
67
+ end
68
+ end
69
+ @result["hotels"][0].each do |_key, field|
70
+ field[4].each do |_, value|
71
+ @data_hash["hotel_policy_note"] = value["note"].to_s
72
+ @data_hash["cancel_policy"] = value["cancelPolicy"].to_s
73
+ end
74
+ end
75
+ @data_hash
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,12 @@
1
+ module HotelPrice::Rakuten
2
+ class RakutenConsole
3
+ def initialize params
4
+ @config = {
5
+ login_id: params[:login_id],
6
+ login_pw: params[:login_pw],
7
+ chain: params[:chain] ||= false,
8
+ rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
9
+ }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require_relative "./rakuten/rakuten_api"
2
+ require_relative "./rakuten/rakuten_console"
3
+
4
+ module HotelPrice
5
+ module Rakuten
6
+ def self.review rakuten_hotel_id
7
+ driver = self.get_selenium_driver
8
+ driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id.to_s}/review.html")
9
+ sleep 2
10
+ comment_area = driver.find_elements(:class_name, "commentBox")
11
+ data = comment_area.map do |f|
12
+ {
13
+ date: f.find_element(class_name: "time").text,
14
+ rakuten_hotel_id: rakuten_hotel_id,
15
+ comment: f.find_element(class_name: "commentSentence").text
16
+ }
17
+ end
18
+ driver.quit
19
+ data
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/hotel_price.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  require "hotel_price/version"
2
+ require "hotel_price/rakuten"
3
+ require "hotel_price/jalan"
2
4
  require "selenium-webdriver"
3
5
  require "net/http"
4
6
 
5
7
  module HotelPrice
6
8
  class Error < StandardError; end
7
9
  def self.rakuten_travel
8
- # firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
9
- # @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
10
- options = Selenium::WebDriver::Firefox::Options.new
11
- options.add_argument("-headless")
12
- driver = Selenium::WebDriver.for :firefox, options: options
10
+ driver = self.get_selenium_driver
13
11
  rakuten_travel_hotel_id = 128552
14
12
  driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_travel_hotel_id.to_s}/review.html")
15
13
  sleep 2
@@ -24,123 +22,14 @@ module HotelPrice
24
22
  end
25
23
  end
26
24
 
27
- require "jalan"
25
+ private
28
26
 
29
- module RakutenTravel
30
- def self.review rakuten_hotel_id
31
- # firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
32
- # @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
33
- options = Selenium::WebDriver::Firefox::Options.new
34
- options.add_argument("-headless")
35
- driver = Selenium::WebDriver.for :firefox, options: options
36
- driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_hotel_id.to_s}/review.html")
37
- sleep 2
38
- comment_area = driver.find_elements(:class_name, "commentBox")
39
- data = comment_area.map do |f|
40
- {
41
- date: f.find_element(class_name: "time").text,
42
- rakuten_hotel_id: rakuten_hotel_id,
43
- comment: f.find_element(class_name: "commentSentence").text
44
- }
45
- end
46
- driver.quit
47
- data
48
- end
49
-
50
- class RakutenConsole
51
- def initialize params
52
- @config = {
53
- login_id: params[:login_id],
54
- login_pw: params[:login_pw],
55
- chain: params[:chain] ||= false,
56
- rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
57
- }
58
- end
59
-
60
- def test
61
- @config
62
- end
63
- end
64
-
65
- class RakutenAPI
66
- def initialize params
67
- @config = {
68
- rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
69
- rakuten_api_key: params[:rakuten_api_key] ||= ENV["RT_API_KEY"]
70
- }
71
- end
72
-
73
- def test
74
- @config
75
- end
27
+ def self.get_selenium_driver
28
+ # firefox_capabilities = Selenium::WebDriver::Remote::Capabilities.firefox
29
+ # @driver = Selenium::WebDriver.for(:remote, url: "http://hub:4444/wd/hub", desired_capabilities: firefox_capabilities)
76
30
 
77
- def hotel_info
78
- 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")
79
- json = Net::HTTP.get(uri)
80
- @result = JSON.parse(json)
81
- return "ホテル情報がありませんでした。" if @result["error"] == "not_found"
82
- return @result["error_description"] if @result["error"] == "wrong_parameter"
83
- @result["hotels"][0].each do |_key, value|
84
- value[0].each do |_key, value|
85
- @data_hash = {
86
- rakuten_hotel_id: value["hotelNo"],
87
- hotel_name: value["hotelName"],
88
- room_price_min: value["hotelMinCharge"],
89
- lat: value["latitude"],
90
- lon: value["longitude"],
91
- tel: value["telephoneNo"],
92
- zip_code: value["postalCode"],
93
- prefecture: value["address1"],
94
- address1: value["address2"],
95
- fax: value["faxNo"],
96
- access: value["access"],
97
- parking_info: value["parkingInformation"],
98
- near_station: value["nearestStation"],
99
- hotel_img_url: value["hotelImageUrl"],
100
- rakuten_review_count: value["reviewCount"],
101
- rakuten_review_avg: value["reviewAverage"].to_f
102
- }
103
- end
104
- end
105
- @result["hotels"][0].each do |_key, value|
106
- value[1].each do |_key, value|
107
- @data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
108
- @data_hash["rakuten_location_review"] = value["locationAverage"].to_f
109
- @data_hash["rakuten_room_review"] = value["roomAverage"].to_f
110
- @data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
111
- @data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
112
- @data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
113
- end
114
- end
115
- @result["hotels"][0].each do |_key, value|
116
- value[2].each do |_key, value|
117
- @data_hash["middle_class_code"] = value["middleClassCode"].to_s
118
- @data_hash["small_class_code"] = value["smallClassCode"].to_s
119
- @data_hash["area_name"] = value["areaName"].to_s
120
- @data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
121
- @data_hash["checkin_time"] = value["checkinTime"].to_s
122
- @data_hash["checkout_time"] = value["checkoutTime"].to_s
123
- @data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
124
- end
125
- end
126
- @result["hotels"][0].each do |_key, value|
127
- value[3].each do |_key, value|
128
- @data_hash["total_room_num"] = value["hotelRoomNum"].to_s
129
- room_facilities = []
130
- value["roomFacilities"].each_with_index do |f, i|
131
- room_facilities[i] = f["item"]
132
- end
133
- @data_hash["room_facilities"] = room_facilities
134
- end
135
- end
136
- @result["hotels"][0].each do |_key, value|
137
- value[4].each do |_key, value|
138
- @data_hash["hotel_policy_note"] = value["note"].to_s
139
- @data_hash["cancel_policy"] = value["cancelPolicy"].to_s
140
- end
141
- end
142
- @data_hash
143
- end
144
- end
31
+ options = Selenium::WebDriver::Firefox::Options.new
32
+ options.add_argument("-headless")
33
+ Selenium::WebDriver.for :firefox, options: options
145
34
  end
146
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotel_price
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-19 00:00:00.000000000 Z
11
+ date: 2020-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,8 +89,12 @@ files:
89
89
  - exe/hotel_price
90
90
  - hotel_price.gemspec
91
91
  - lib/hotel_price.rb
92
+ - lib/hotel_price/jalan.rb
93
+ - lib/hotel_price/jalan/jalan_api.rb
94
+ - lib/hotel_price/rakuten.rb
95
+ - lib/hotel_price/rakuten/rakuten_api.rb
96
+ - lib/hotel_price/rakuten/rakuten_console.rb
92
97
  - lib/hotel_price/version.rb
93
- - lib/jalan.rb
94
98
  homepage: https://github.com/el-fudo/hotel_price
95
99
  licenses:
96
100
  - MIT