hotel_price 0.2.0 → 0.2.1

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: 46062e452bbaf140402021de2e18bbfab7d75f263817d1e9e390fe1a75992c22
4
- data.tar.gz: b3b82149d0d899bc52146174be0ab0b63e13b89338d8fb95ab6476d2bd9e2310
3
+ metadata.gz: 87c91d285ca9f23c4fd9315ae10ae7d34a07a52160ddb8c827079f281426ab81
4
+ data.tar.gz: ff3b1565cba8b422318729e610bcaf592c171f57c2bb6d10278b4f03123bd7c7
5
5
  SHA512:
6
- metadata.gz: 96187515114012df0d4c0c5430d4db0a72816cf017cb4dda5a076b3b2e70b1a190bc73549e4950bbfd6d21a32c775a51fe221c08479f25c6cd395c5d17c6e377
7
- data.tar.gz: '09da4b388b9d72406510b14986dcc8c0c13ae0f768f665494f20307939f6777243086c6c1aea35d3ff0d9e3b94c7a2462e3e346695167ccd469425bcc1e1dc53'
6
+ metadata.gz: 705a64bade5aeff929bed833d4193f3b61b138657b13bbdbe992dc6a1d4aa42345149d0487a19d2f457e2bd31907d25b5d099f7c1ded0dee21daaba65081b7b0
7
+ data.tar.gz: 41fd30af0bb60ce2a2658615de090e1f773034cec4e02a78efa4652ddd2483cbed6d4fcd6a6852210006e90cad2a13bd0c64e07b0e79e3308dc5d89b641491a5
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.envrc
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -0,0 +1,218 @@
1
+ # target_version:
2
+ # rubocop v0.34.2
3
+
4
+ # 自動生成されるものはチェック対象から除外する
5
+ AllCops:
6
+ Exclude:
7
+ - "vendor/**/*" # rubocop config/default.yml
8
+ - "db/schema.rb"
9
+ - "db/migrate/*"
10
+ DisplayCopNames: true
11
+ TargetRubyVersion: 2.6.5
12
+
13
+ ##################### Style ##################################
14
+
15
+ # redirect_to xxx and return のイディオムを維持したい
16
+ Style/AndOr:
17
+ EnforcedStyle: conditionals
18
+
19
+ # 日本語のコメントを許可する
20
+ Style/AsciiComments:
21
+ Enabled: false
22
+
23
+ # do .. end から更にメソッドチェーンすると見づらいので
24
+ # auto-correct せず、自分で修正する
25
+ # spec 内は見た目が綺麗になるので許可
26
+ Style/BlockDelimiters:
27
+ AutoCorrect: false
28
+ Exclude:
29
+ - "spec/**/*"
30
+
31
+ # option 等、明示的にハッシュにした方が分かりやすい場合もある
32
+ Style/BracesAroundHashParameters:
33
+ Enabled: false
34
+
35
+ # Style/CollectionMethods 自体は無効になっているのだが、
36
+ # https://github.com/bbatsov/rubocop/issues/1084
37
+ # https://github.com/bbatsov/rubocop/issues/1334
38
+ # Performance/Detect がこの設定値を見るので PreferredMethods だけ変更しておく。
39
+ #
40
+ # デフォルト値から変えたのは
41
+ # find -> detect
42
+ # ActiveRecord の find と間違えやすいため
43
+ # reduce -> inject
44
+ # detect, reject, select と並べたときに韻を踏んでいるため。
45
+ # collect -> map を維持しているのは文字数が圧倒的に少ないため。
46
+ Style/CollectionMethods:
47
+ PreferredMethods:
48
+ detect: "detect"
49
+ find: "detect"
50
+ inject: "inject"
51
+ reduce: "inject"
52
+
53
+ # ドキュメントの無い public class を許可する
54
+ Style/Documentation:
55
+ Enabled: false
56
+
57
+ # !! のイディオムは積極的に使う
58
+ Style/DoubleNegation:
59
+ Enabled: false
60
+
61
+ # MethodDefParentheses:
62
+ # EnforcedStyle: require_no_parentheses
63
+
64
+ # メソッドチェーンの改行は末尾に . を入れる
65
+ # REPL に貼り付けた際の暴発を防ぐため
66
+ Layout/DotPosition:
67
+ EnforcedStyle: trailing
68
+
69
+ Layout/LineLength:
70
+ Enabled: false
71
+
72
+ Layout/EmptyLineAfterGuardClause:
73
+ Enabled: false
74
+
75
+ # 明示的に else で nil を返すのは分かりやすいので許可する
76
+ Style/EmptyElse:
77
+ EnforcedStyle: empty
78
+
79
+ # 桁揃えが綺麗にならないことが多いので migration は除外
80
+ Layout/ExtraSpacing:
81
+ Exclude:
82
+ - "db/migrate/*.rb"
83
+
84
+ # いずれかに揃えるのならば `sprintf` や `format` より String#% が好きです
85
+ Style/FormatString:
86
+ EnforcedStyle: percent
87
+
88
+ # if 文の中に 3 行程度のブロックを書くぐらいは許容した方が現実的
89
+ Style/GuardClause:
90
+ MinBodyLength: 5
91
+
92
+ # rake タスクの順序の hash は rocket を許可する
93
+ Style/HashSyntax:
94
+ Exclude:
95
+ - "**/*.rake"
96
+ - "Rakefile"
97
+
98
+ # 条件式の方を意識させたい場合には後置の if/unless を使わない方が分かりやすい
99
+ Style/IfUnlessModifier:
100
+ Enabled: false
101
+
102
+ # private/protected は一段深くインデントする
103
+ Style/PreferredHashMethods:
104
+ EnforcedStyle: short
105
+
106
+ # scope 等は複数行でも lambda ではなく ->{} で揃えた方が見た目が綺麗
107
+ Style/Lambda:
108
+ Enabled: false
109
+
110
+ # 1_000_000 と区切り文字が 2 個以上必要になる場合のみ _ 区切りを必須にする
111
+ Style/NumericLiterals:
112
+ MinDigits: 7
113
+
114
+ # 正規表現にマッチさせた時の特殊変数の置き換えは Regex.last_match ではなく
115
+ # 名前付きキャプチャを使って参照したいので auto-correct しない
116
+ Style/PerlBackrefs:
117
+ AutoCorrect: false
118
+
119
+ # has_ から始まるメソッドは許可する
120
+ Naming/PredicateName:
121
+ ForbiddenPrefixes:
122
+ - "is_"
123
+ - "have_"
124
+ NamePrefix:
125
+ - "is_"
126
+ - "have_"
127
+
128
+ # 特に model 内において、ローカル変数とメソッド呼び出しの区別をつけた方が分かりやすい場合が多い
129
+ Style/RedundantSelf:
130
+ Enabled: false
131
+
132
+ Style/FrozenStringLiteralComment:
133
+ Enabled: false
134
+
135
+ # 受け取り側で multiple assignment しろというのを明示
136
+ Style/RedundantReturn:
137
+ AllowMultipleReturnValues: true
138
+
139
+ # spec 内は見た目が綺麗になるので許可
140
+ Style/Semicolon:
141
+ Exclude:
142
+ - "spec/**/*"
143
+
144
+ # fail と使い分ける必要ナシ
145
+ Style/SignalException:
146
+ EnforcedStyle: only_raise
147
+
148
+ Style/MethodDefParentheses:
149
+ Enabled: false
150
+
151
+ # `||` も align に使うことがあるので追加する
152
+ # Style/SpaceAroundOperators:
153
+ # MultiSpaceAllowedForOperators:
154
+ # - "="
155
+ # - "=>"
156
+ # - "||"
157
+
158
+ # * 式展開したい場合に書き換えるのが面倒
159
+ # * 文章ではダブルクォートよりもシングルクォートの方が頻出する
160
+ # ことから EnforcedStyle: double_quotes 推奨
161
+ Style/StringLiterals:
162
+ EnforcedStyle: double_quotes
163
+
164
+ # auto-correct 時に Style/StringLiterals とカニバって無限ループになる (v0.28.0)
165
+ Style/StringLiteralsInInterpolation:
166
+ Enabled: false
167
+
168
+ # いくらなんでも inject { |a, e| } は短すぎるので分かりやすい名前をつけたい
169
+ Style/SingleLineBlockParams:
170
+ Enabled: false
171
+
172
+ # * migrate
173
+ # * jbuilder
174
+ # * model の association
175
+ # * controller の callback
176
+ # 辺りの桁揃えで引っかかるので全体的にチェックしない
177
+ # Style/SingleSpaceBeforeFirstArg:
178
+ # Enabled: false
179
+
180
+
181
+ ##################### Lint ##################################
182
+
183
+ # * 同名のメソッドがある場合にローカル変数に `_` を付ける
184
+ # * 一時変数として `_` を付ける
185
+ # というテクニックは頻出する
186
+ Lint/UnderscorePrefixedVariableName:
187
+ Enabled: false
188
+
189
+ # 子クラスで実装させるつもりのメソッドで引っかかるので
190
+ Lint/UnusedMethodArgument:
191
+ Enabled: false
192
+
193
+ ##################### Metrics ##################################
194
+
195
+ Metrics/AbcSize:
196
+ Enabled: false
197
+
198
+ # 6 は強すぎるので緩める
199
+ Metrics/CyclomaticComplexity:
200
+ Max: 10
201
+
202
+ Metrics/PerceivedComplexity:
203
+ Enabled: false
204
+
205
+ Metrics/BlockLength:
206
+ Enabled: false
207
+
208
+ Metrics/MethodLength:
209
+ Enabled: false
210
+
211
+ Metrics/ClassLength:
212
+ Enabled: false
213
+
214
+ Naming/HeredocDelimiterNaming:
215
+ Enabled: false
216
+
217
+ Naming/AccessorMethodName:
218
+ Enabled: false
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hotel_price (0.2.0)
4
+ hotel_price (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "bundler", "~> 2.0"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "selenium-webdriver", "~> 3.141"
34
35
  end
@@ -1,5 +1,6 @@
1
1
  require "hotel_price/version"
2
2
  require "selenium-webdriver"
3
+ require "net/http"
3
4
 
4
5
  module HotelPrice
5
6
  class Error < StandardError; end
@@ -10,7 +11,7 @@ module HotelPrice
10
11
  options.add_argument("-headless")
11
12
  driver = Selenium::WebDriver.for :firefox, options: options
12
13
  rakuten_travel_hotel_id = 7770
13
- driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_travel_hotel_id.to_s}/review.html")
14
+ driver.get("https://travel.rakuten.co.jp/HOTEL/#{rakuten_travel_hotel_id}/review.html")
14
15
  sleep 2
15
16
  comment_area = driver.find_elements(:class_name, "commentReputationBoth")
16
17
  data = comment_area.map do |f|
@@ -21,7 +22,121 @@ module HotelPrice
21
22
  comment: f.find_element(class_name: "commentSentence").text
22
23
  }
23
24
  end
24
- driver.quit
25
- data
25
+ end
26
+
27
+ module Jalan
28
+ class JalanConsole
29
+ def initialize params
30
+ @config = {
31
+ login_id: params[:login_id],
32
+ login_pw: params[:login_pw],
33
+ chain: params[:chain] ||= false,
34
+ jalan_hotel_id: params[:jalan_hotel_id] ||= 0,
35
+ jalan_api_key: params[:jalan_api_key] ||= ENV["JALAN_API_KEY"]
36
+ }
37
+ end
38
+
39
+ def test
40
+ @config
41
+ end
42
+ end
43
+ end
44
+
45
+ module RakutenTravel
46
+ class RakutenConsole
47
+ def initialize params
48
+ @config = {
49
+ login_id: params[:login_id],
50
+ login_pw: params[:login_pw],
51
+ chain: params[:chain] ||= false,
52
+ rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
53
+ }
54
+ end
55
+
56
+ def test
57
+ @config
58
+ end
59
+ end
60
+
61
+ class RakutenAPI
62
+ def initialize params
63
+ @config = {
64
+ rakuten_hotel_id: params[:rakuten_hotel_id] ||= 0,
65
+ rakuten_api_key: params[:rakuten_api_key] ||= ENV["RT_API_KEY"]
66
+ }
67
+ end
68
+
69
+ def test
70
+ @config
71
+ end
72
+
73
+ def hotel_info
74
+ 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")
75
+ json = Net::HTTP.get(uri)
76
+ @result = JSON.parse(json)
77
+ return "ホテル情報がありませんでした。" if @result["error"] == "not_found"
78
+ return @result["error_description"] if @result["error"] == "wrong_parameter"
79
+ @result["hotels"][0].each do |_key, value|
80
+ value[0].each do |_key, value|
81
+ @data_hash = {
82
+ rakuten_hotel_id: value["hotelNo"],
83
+ hotel_name: value["hotelName"],
84
+ room_price_min: value["hotelMinCharge"],
85
+ lat: value["latitude"],
86
+ lon: value["longitude"],
87
+ tel: value["telephoneNo"],
88
+ zip_code: value["postalCode"],
89
+ prefecture: value["address1"],
90
+ address1: value["address2"],
91
+ fax: value["faxNo"],
92
+ access: value["access"],
93
+ parking_info: value["parkingInformation"],
94
+ near_station: value["nearestStation"],
95
+ hotel_img_url: value["hotelImageUrl"],
96
+ rakuten_review_count: value["reviewCount"],
97
+ rakuten_review_avg: value["reviewAverage"].to_f
98
+ }
99
+ end
100
+ end
101
+ @result["hotels"][0].each do |_key, value|
102
+ value[1].each do |_key, value|
103
+ @data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
104
+ @data_hash["rakuten_location_review"] = value["locationAverage"].to_f
105
+ @data_hash["rakuten_room_review"] = value["roomAverage"].to_f
106
+ @data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
107
+ @data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
108
+ @data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
109
+ end
110
+ end
111
+ @result["hotels"][0].each do |_key, value|
112
+ value[2].each do |_key, value|
113
+ @data_hash["middle_class_code"] = value["middleClassCode"].to_s
114
+ @data_hash["small_class_code"] = value["smallClassCode"].to_s
115
+ @data_hash["area_name"] = value["areaName"].to_s
116
+ @data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
117
+ @data_hash["checkin_time"] = value["checkinTime"].to_s
118
+ @data_hash["checkout_time"] = value["checkoutTime"].to_s
119
+ @data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
120
+ end
121
+ end
122
+ @result["hotels"][0].each do |_key, value|
123
+ value[3].each do |_key, value|
124
+ @data_hash["total_room_num"] = value["hotelRoomNum"].to_s
125
+ room_facilities = []
126
+ value["roomFacilities"].each_with_index do |f, i|
127
+ room_facilities[i] = f["item"]
128
+ end
129
+ @data_hash["room_facilities"] = room_facilities
130
+ end
131
+ end
132
+ @result["hotels"][0].each do |_key, value|
133
+ value[4].each do |_key, value|
134
+ @data_hash["hotel_policy_note"] = value["note"].to_s
135
+ @data_hash["cancel_policy"] = value["cancelPolicy"].to_s
136
+ end
137
+ end
138
+ @data_hash
139
+ end
140
+ end
26
141
  end
27
142
  end
@@ -1,3 +1,3 @@
1
1
  module HotelPrice
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,85 @@
1
+ module RakutenTravel
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
+ rakuten_api_key: params[:rakuten_api_key] ||= ENV["RT_API_KEY"]
10
+ }
11
+ end
12
+
13
+ def test
14
+ @config
15
+ end
16
+
17
+ def hotel_info
18
+ 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")
19
+ json = Net::HTTP.get(uri)
20
+ @result = JSON.parse(json)
21
+ return "ホテル情報がありませんでした。" if @result["error"] == "not_found"
22
+ return @result["error_description"] if @result["error"] == "wrong_parameter"
23
+ @result["hotels"][0].each do |_key, value|
24
+ value[0].each do |_key, value|
25
+ @data_hash = {
26
+ rakuten_hotel_id: value["hotelNo"],
27
+ hotel_name: value["hotelName"],
28
+ room_price_min: value["hotelMinCharge"],
29
+ lat: value["latitude"],
30
+ lon: value["longitude"],
31
+ tel: value["telephoneNo"],
32
+ zip_code: value["postalCode"],
33
+ prefecture: value["address1"],
34
+ address1: value["address2"],
35
+ fax: value["faxNo"],
36
+ access: value["access"],
37
+ parking_info: value["parkingInformation"],
38
+ near_station: value["nearestStation"],
39
+ hotel_img_url: value["hotelImageUrl"],
40
+ rakuten_review_count: value["reviewCount"],
41
+ rakuten_review_avg: value["reviewAverage"].to_f
42
+ }
43
+ end
44
+ end
45
+ @result["hotels"][0].each do |_key, value|
46
+ value[1].each do |_key, value|
47
+ @data_hash["rakuten_service_review"] = value["serviceAverage"].to_f
48
+ @data_hash["rakuten_location_review"] = value["locationAverage"].to_f
49
+ @data_hash["rakuten_room_review"] = value["roomAverage"].to_f
50
+ @data_hash["rakuten_equipment_review"] = value["equipmentAverage"].to_f
51
+ @data_hash["rakuten_bath_review"] = value["bathAverage"].to_f
52
+ @data_hash["rakuten_meal_review"] = value["mealAverage"].to_f
53
+ end
54
+ end
55
+ @result["hotels"][0].each do |_key, value|
56
+ value[2].each do |_key, value|
57
+ @data_hash["middle_class_code"] = value["middleClassCode"].to_s
58
+ @data_hash["small_class_code"] = value["smallClassCode"].to_s
59
+ @data_hash["area_name"] = value["areaName"].to_s
60
+ @data_hash["hotel_class_code"] = value["hotelClassCode"].to_s
61
+ @data_hash["checkin_time"] = value["checkinTime"].to_s
62
+ @data_hash["checkout_time"] = value["checkoutTime"].to_s
63
+ @data_hash["last_checkin_time"] = value["lastCheckinTime"].to_s
64
+ end
65
+ end
66
+ @result["hotels"][0].each do |_key, value|
67
+ value[3].each do |_key, value|
68
+ @data_hash["total_room_num"] = value["hotelRoomNum"].to_s
69
+ room_facilities = []
70
+ value["roomFacilities"].each_with_index do |f, i|
71
+ room_facilities[i] = f["item"]
72
+ end
73
+ @data_hash["room_facilities"] = room_facilities
74
+ end
75
+ end
76
+ @result["hotels"][0].each do |_key, value|
77
+ value[4].each do |_key, value|
78
+ @data_hash["hotel_policy_note"] = value["note"].to_s
79
+ @data_hash["cancel_policy"] = value["cancelPolicy"].to_s
80
+ end
81
+ end
82
+ @data_hash
83
+ end
84
+ end
85
+ 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.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fumitake Kawasaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-03 00:00:00.000000000 Z
11
+ date: 2020-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: selenium-webdriver
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.141'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.141'
55
69
  description: 'Empower World Travel Information Technology '
56
70
  email:
57
71
  - fumitake.kawasaki@el-soul.com
@@ -63,6 +77,7 @@ extra_rdoc_files: []
63
77
  files:
64
78
  - ".gitignore"
65
79
  - ".rspec"
80
+ - ".rubocop.yml"
66
81
  - ".travis.yml"
67
82
  - CODE_OF_CONDUCT.md
68
83
  - Gemfile
@@ -77,6 +92,7 @@ files:
77
92
  - hotel_price.gemspec
78
93
  - lib/hotel_price.rb
79
94
  - lib/hotel_price/version.rb
95
+ - lib/rakuten_travel.rb
80
96
  - lib/rakuten_travel_review.rb
81
97
  homepage: https://github.com/el-fudo/hotel_price
82
98
  licenses: