kenpo_api 0.1.1 → 0.1.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
  SHA1:
3
- metadata.gz: 5a4ff77a43e7c89020400373986953db37f012fe
4
- data.tar.gz: 625dfdf1b89e6c1a7406179e2c9c6929d8324937
3
+ metadata.gz: 56f484d8e49df945bc18578d6128d2946ed24d23
4
+ data.tar.gz: 542ca13d65a0016f15ba443923765c1204e3f934
5
5
  SHA512:
6
- metadata.gz: 2a0f466ef4cb958b65e59a5ef31402e156f1c1c31e391f1177651b662e14ac6d5164cc97fc982eb385379153a9ec6ab19cd3cc01c7b6954a27e152715119cacb
7
- data.tar.gz: 347cd979b86eb2b52cb240609163c00dbf5f7532e6bc4a51cc5eea8f20e847e6f21983982a8fb9aeef4248f156863d1150d37699829631f5b8d6720a4b3bce56
6
+ metadata.gz: a154c2cbe55dca226388bfbf8c1a68aefe8c69897e93b4f3bf881aa4f672357fa7e8afd1fb69141f276d292154b956df6ec59d3de9afb3cf24dfab9a23c5e8ae
7
+ data.tar.gz: 44fd1c0fcf38ae5d144744c9c8a5ddf4a6130338449379973e926c117c4add0aab87692301e6d1caf8c0f6de72863e6b9fecc195202202067b031bf84d8c061a
@@ -0,0 +1,4 @@
1
+ .git
2
+ .gitignore
3
+ .rspec
4
+ .ruby-version
@@ -0,0 +1 @@
1
+ 2.4.2
@@ -1,7 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 2.4.2
4
5
  - 2.3.3
5
6
  - 2.2.6
6
- - 2.1.10
7
7
  before_install: gem install bundler -v 1.13.6
data/README.md CHANGED
@@ -24,12 +24,21 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
+ *PLEASE DO NOT ABUSE THE RESERVATION!!*
28
+
29
+ ### Resort reservation by lottery
30
+
27
31
  ```ruby
28
- # Resort reservation
32
+ # Request email.
29
33
  resort_names = KenpoApi::Resort.resort_names
30
34
  KenpoApi::Resort.request_reservation_url(resort_name: 'トスラブ箱根和奏林', email: 'matsuno_osomatsu@example.com')
35
+
36
+ # Check email and copy the url in the email.
31
37
  url = 'https://as.its-kenpo.or.jp/apply/new?c=aaaaaaaa-bbbb-cccc-dddd-012345678901'
32
- criteria = KenpoApi::Resort.check_reservation_criteria(url)
38
+ # Check criteria.
39
+ criteria = KenpoApi::Resort.check_reservation_criteria(url, type: :lottery)
40
+
41
+ # Apply for the reservation by lottery.
33
42
  reservation_data = {
34
43
  sign_no: 6666,
35
44
  insured_no: 666,
@@ -44,20 +53,72 @@ reservation_data = {
44
53
  postal_code: '180-0004',
45
54
  state: 13,
46
55
  address: '武蔵野市本町666-666',
47
- join_time: '2017-04-15',
56
+ join_time: '2018-02-15',
48
57
  night_count: 1,
49
58
  stay_persons: 6,
50
59
  room_persons: 6, (1 room) # or [3, 3] (2 rooms) or [2, 2, 2] (3 rooms) ...
51
60
  meeting_dates: nil, # (none) or [1] (first day only) or [1, 2] (both days) ...
52
61
  must_meeting: false,
53
62
  }
54
- KenpoApi::Resort.apply_reservation(url, reservation_data)
63
+ KenpoApi::Resort.apply_reservation(url, reservation_data, type: :lottery)
64
+ ```
65
+
66
+ ### Resort reservation for vacant rooms
67
+
68
+ ```ruby
69
+ # Check criteria.
70
+ resort_name = 'トスラブ箱根和奏林'
71
+ KenpoApi::Resort.check_vacant_search_criteria(resort_name: resort_name)
72
+
73
+ # Search vacant rooms.
74
+ search_condition = {
75
+ join_time: '2018-02-27',
76
+ night_count: 1,
77
+ stay_persons: 6,
78
+ room_persons: 6, # (1 room) or [3, 3] (2 rooms) or [2, 2, 2] (3 rooms) ...
79
+ }
80
+ KenpoApi::Resort.search_vacant_rooms(resort_name: resort_name, search_condition: search_condition)
81
+
82
+ # Request email.
83
+ res = KenpoApi::Resort.request_reservation_url_for_vacant_rooms(resort_name: resort_name, search_condition: search_condition, vacant_room_id: 525968, email: 'matsuno_osomatsu@example.com')
84
+
85
+ # Check email and copy the url in the email.
86
+ url = 'https://as.its-kenpo.or.jp/apply/new?c=aaaaaaaa-bbbb-cccc-dddd-234567890123'
87
+ # Check criteria.
88
+ KenpoApi::Resort.check_reservation_criteria(url, type: :vacant)
89
+
90
+ # Apply for the reservation by lottery.
91
+ reservation_data = {
92
+ sign_no: 6666,
93
+ insured_no: 666,
94
+ office_name: '株式会社FLAG',
95
+ kana_name: 'マツノ オソマツ',
96
+ birth_year: 1962,
97
+ birth_month: 5,
98
+ birth_day: 24,
99
+ gender: :man,
100
+ relationship: :myself,
101
+ contact_phone: '666-6666-6666',
102
+ postal_code: '180-0004',
103
+ state: 13,
104
+ address: '武蔵野市本町666-666',
105
+ }
106
+ KenpoApi::Resort.apply_reservation(url, reservation_data, type: :vacant)
107
+ ```
108
+
109
+ ### Sport reservation by lottery
55
110
 
56
- # Sport reservation
111
+ ```ruby
112
+ # Request email.
57
113
  sport_names = KenpoApi::Sport.sport_names
58
114
  KenpoApi::Sport.request_reservation_url(sport_name: 'サマディ門前仲町', email: 'matsuno_osomatsu@example.com')
115
+
116
+ # Check email and copy the url in the email.
59
117
  url = 'https://as.its-kenpo.or.jp/apply/new?c=aaaaaaaa-bbbb-cccc-dddd-901234567890'
118
+ # Check criteria.
60
119
  criteria = KenpoApi::Sport.check_reservation_criteria(url)
120
+
121
+ # Apply for the reservation by lottery.
61
122
  reservation_data = {
62
123
  sign_no: 6666,
63
124
  insured_no: 666,
@@ -70,19 +131,46 @@ reservation_data = {
70
131
  postal_code: '180-0004',
71
132
  state: 13,
72
133
  address: '武蔵野市本町666-666',
73
- join_time: '2017-03-11',
134
+ join_time: '2018-03-11',
74
135
  use_time_from: '13:00',
75
136
  use_time_to: '15:00',
76
137
  }
77
138
  KenpoApi::Sport.apply_reservation(url, reservation_data)
78
139
  ```
79
140
 
141
+ ### Low-level APIs
142
+
143
+ ```ruby
144
+ categories = KenpoApi::ServiceCategory.list
145
+
146
+ category = KenpoApi::ServiceCategory.find(:resort_reserve)
147
+ category.available?
148
+ category.service_groups
149
+
150
+ group = KenpoApi::ServiceGroup.find(category, 'トスラブ箱根ビオーレ')
151
+ group.available?
152
+ group.services
153
+ ```
154
+
155
+
80
156
  ## Development
81
157
 
82
158
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
83
159
 
84
160
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
85
161
 
162
+ ### Use Docker env
163
+
164
+ ```sh
165
+ $ docker-compose up -d
166
+ $ docker-compose exec ruby sh
167
+
168
+ # # Start interactive console.
169
+ # pry --gem
170
+ # # Execute tests.
171
+ # rake spec
172
+ ```
173
+
86
174
  ## Contributing
87
175
 
88
176
  Bug reports and pull requests are welcome on GitHub at https://github.com/tearoom6/kenpo_api.
@@ -0,0 +1,10 @@
1
+ version: '3'
2
+ services:
3
+ ruby:
4
+ build:
5
+ context: .
6
+ dockerfile: ./docker/ruby/Dockerfile
7
+ volumes:
8
+ - .:/kenpo_api
9
+ tty: true
10
+ stdin_open: true
@@ -0,0 +1,16 @@
1
+ FROM ruby:2.4.2-alpine3.6
2
+
3
+ ENV LANG=ja_JP.UTF-8\
4
+ APP_ROOT=/kenpo_api
5
+
6
+ RUN apk update && \
7
+ apk upgrade && \
8
+ apk add --update --no-cache --virtual build-dependencies build-base && \
9
+ apk add --update --no-cache tzdata git less && \
10
+ mkdir -p $APP_ROOT
11
+
12
+ WORKDIR $APP_ROOT
13
+ COPY . $APP_ROOT
14
+
15
+ RUN bundle install --jobs=4 && \
16
+ apk del build-dependencies
@@ -32,8 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'bundler', '~> 1'
33
33
  spec.add_development_dependency 'rake', '~> 10'
34
34
  spec.add_development_dependency 'rspec', '~> 3'
35
- spec.add_development_dependency 'faraday', '~> 0.10'
36
- spec.add_development_dependency 'cookiejar', '~> 0.3'
37
- spec.add_development_dependency 'nokogiri', '~> 1'
38
- spec.add_development_dependency 'dry-validation', '~> 0.10'
35
+ spec.add_development_dependency 'pry', '~> 0.11.3'
36
+
37
+ spec.add_dependency 'faraday', '~> 0.10'
38
+ spec.add_dependency 'cookiejar', '~> 0.3'
39
+ spec.add_dependency 'nokogiri', '~> 1'
40
+ spec.add_dependency 'dry-validation', '~> 0.10'
39
41
  end
@@ -22,16 +22,21 @@ module KenpoApi
22
22
  @cookiejar = CookieJar::Jar.new
23
23
  end
24
24
 
25
- def access(path:, method: :get, params: {})
25
+ def access(path:, method: :get, params: {}, headers: {}, redirect_limit: 0)
26
26
  response = @conn.send(method, path, params) do |req|
27
27
  req.options.timeout = @timeout
28
28
  req.options.open_timeout = @open_timeout
29
+ req.headers = headers
29
30
  req.headers['cookie'] = @cookiejar.get_cookie_header(@conn.url_prefix.to_s)
30
31
  end
31
- raise NetworkError.new("Failed to fetch http content. path: #{path} status_code: #{response.status}") unless response.success?
32
+ raise NetworkError.new("Failed to fetch http content. path: #{path} status_code: #{response.status}") unless (200...400).include?(response.status)
32
33
 
33
34
  @cookiejar.set_cookie(@conn.url_prefix.to_s, response.headers['set-cookie']) if response.headers.has_key?('set-cookie')
34
35
 
36
+ if (redirect_limit > 0) && (location = response['location'])
37
+ response = self.access(path: location, method: method, params: params, headers: headers, redirect_limit: redirect_limit - 1)
38
+ end
39
+
35
40
  return (yield response) if block_given?
36
41
  response
37
42
  rescue KenpoApiError => e
@@ -40,16 +45,16 @@ module KenpoApi
40
45
  raise NetworkError.new("Failed to fetch http content. path: #{path} original_error: #{e.message}")
41
46
  end
42
47
 
43
- def fetch_document(path:, method: :get, params: {})
44
- response = access(path: path, method: method, params: params)
48
+ def fetch_document(path:, method: :get, params: {}, headers: {})
49
+ response = access(path: path, method: method, params: params, headers: headers)
45
50
  document = Nokogiri::HTML(response.body)
46
51
 
47
52
  return (yield document) if block_given?
48
53
  document
49
54
  end
50
55
 
51
- def parse_single_form_page(path:, method: :get, params: {})
52
- document = fetch_document(path: path, method: method, params: params)
56
+ def parse_single_form_page(path:, method: :get, params: {}, headers: {})
57
+ document = fetch_document(path: path, method: method, params: params, headers: headers)
53
58
  form_element = document.xpath('//form').first
54
59
 
55
60
  next_page_info = nil
@@ -15,22 +15,85 @@ module KenpoApi
15
15
  request_application_url(service_path: service.path, email: email)
16
16
  end
17
17
 
18
- def self.check_reservation_criteria(application_url)
18
+ def self.check_reservation_criteria(application_url, type: :lottery)
19
19
  html_document = Client.instance.fetch_document(path: application_url)
20
20
  raise NotAvailableError.new("Application URL is invalid: #{html_document.xpath('//p').first.content}") if html_document.xpath('//form').first.nil?
21
- reservation_criteria(html_document)
21
+ reservation_criteria(html_document, type: type)
22
22
  end
23
23
 
24
- def self.apply_reservation(application_url, application_data)
24
+ def self.apply_reservation(application_url, application_data, type: :lottery)
25
25
  apply(application_url: application_url) do |html_document|
26
- reservation_data = self.validate_reservation_data(application_data, html_document)
27
- convert_to_reservation_post_params(reservation_data)
26
+ reservation_data = self.validate_reservation_data(application_data, html_document, type: type)
27
+ convert_to_reservation_post_params(reservation_data, type: type)
28
28
  end
29
29
  end
30
30
 
31
+ def self.check_vacant_search_criteria(resort_name:)
32
+ service = find_service(category_code: :resort_search_vacant, group_name: resort_name)
33
+ html_document = Client.instance.fetch_document(path: service.path)
34
+ raise NotAvailableError.new("Application URL is invalid: #{html_document.xpath('//p').first.content}") if html_document.xpath('//form').first.nil?
35
+ vacant_search_criteria(html_document)
36
+ end
37
+
38
+ def self.search_vacant_rooms(resort_name:, search_condition:)
39
+ vacant_rooms_info = prepare_for_vacant_rooms_reservation(resort_name, search_condition)
40
+ vacant_rooms_info[:vacant_rooms]
41
+ end
42
+
43
+ def self.request_reservation_url_for_vacant_rooms(resort_name:, search_condition:, vacant_room_id:, email:)
44
+ vacant_rooms_info = prepare_for_vacant_rooms_reservation(resort_name, search_condition)
45
+ params = vacant_rooms_info[:params].merge({"apply[coma[#{vacant_room_id}]]" => vacant_room_id})
46
+ response = Client.instance.access(path: vacant_rooms_info[:path], method: vacant_rooms_info[:method], params: params)
47
+ if response.status == 200
48
+ document = Nokogiri::HTML(response.body)
49
+ raise NotAvailableError.new("Application URL is invalid: #{document.xpath('id("errorExplanation")').first.content}")
50
+ end
51
+ request_application_url(service_path: response.headers['location'], email: email)
52
+ end
53
+
31
54
  private
32
55
 
33
- def self.reservation_criteria(html_document)
56
+ def self.prepare_for_vacant_rooms_reservation(resort_name, search_condition)
57
+ service = find_service(category_code: :resort_search_vacant, group_name: resort_name)
58
+ next_page_info, html_document = Client.instance.parse_single_form_page(path: service.path)
59
+ raise NotAvailableError.new("Application URL is invalid: #{html_document.xpath('//p').first.content}") if next_page_info.nil?
60
+
61
+ # Call Ajax API to search vacant rooms.
62
+ search_condition = self.validate_vacant_search_condition(search_condition, html_document)
63
+ params = convert_to_vacant_search_post_params(search_condition)
64
+ params = params.merge(next_page_info[:params])
65
+ query_params = URI::parse(next_page_info[:path]).query
66
+ headers = {'X-Requested-With' => 'XMLHttpRequest'}
67
+ ajax_response = Client.instance.access(path: "/apply/empty_new?#{query_params}", method: :post, params: params, headers: headers)
68
+
69
+ # Parse Ajax response.
70
+ matched = /\<\\\/script\>(.+)\"\)\;/.match(ajax_response.body)
71
+ ajax_document = Nokogiri::HTML(matched[1].gsub(/\\n/, '').gsub(/\s{2,}/, '').gsub(/\\/, ''))
72
+ ids = ajax_document.xpath('id("coma_search_result")/tr/td/input/@value').map {|attr| attr.value }
73
+
74
+ vacant_rooms = ajax_document.xpath('id("coma_search_result")/tr').map.with_index do |elem, index|
75
+ values = elem.xpath('td/text()').map {|text| text.content }
76
+ {
77
+ id: ids[index],
78
+ room_number: values[0],
79
+ join_time: values[1],
80
+ room_type: values[2],
81
+ room_persons: values[3],
82
+ room_status: values[4],
83
+ }
84
+ end
85
+
86
+ additional_params = ajax_document.xpath('//input[@type="hidden"]').select {|input| ! input['name'].nil?}.map {|input| [input['name'], input['value']]}.to_h
87
+ params = params.merge(additional_params)
88
+ {
89
+ path: next_page_info[:path],
90
+ method: next_page_info[:method],
91
+ params: params,
92
+ vacant_rooms: vacant_rooms,
93
+ }
94
+ end
95
+
96
+ def self.reservation_criteria(html_document, type: :lottery)
34
97
  criteria = {}
35
98
  criteria[:note] = html_document.xpath('//div[@class="note mb10"]').first.text
36
99
  criteria[:service_name] = html_document.xpath('//form/div[@class="form_box"]//dd[@class="elements"]').first.text
@@ -40,26 +103,44 @@ module KenpoApi
40
103
  criteria[:gender] = html_document.xpath('id("apply_gender")/*/@value') .map {|attr| attr.value }.map {|val| val.to_sym } # [:man, :woman]
41
104
  criteria[:relationship] = html_document.xpath('id("apply_relationship")/*/@value').map {|attr| attr.value }.map {|val| val.to_sym } # [:myself, :family]
42
105
  criteria[:state] = html_document.xpath('id("apply_state")/*/@value') .map {|attr| attr.value }.select {|val| val != '' } # (1..47)
106
+ if type == :lottery
107
+ criteria[:join_time] = html_document.xpath('id("apply_join_time")/*/@value') .map {|attr| attr.value }.select {|val| val != '' } # ['2017-04-01', .., '2017-04-30']
108
+ criteria[:night_count] = html_document.xpath('id("apply_night_count")/*/@value') .map {|attr| attr.value }.select {|val| val != '' } # (1..2)
109
+ criteria[:room_count] = html_document.xpath('id("house_select")/*/@value') .map {|attr| attr.value.to_i } # (1..10)
110
+ end
111
+ criteria
112
+ end
113
+
114
+ def self.vacant_search_criteria(html_document)
115
+ criteria = {}
43
116
  criteria[:join_time] = html_document.xpath('id("apply_join_time")/*/@value') .map {|attr| attr.value }.select {|val| val != '' } # ['2017-04-01', .., '2017-04-30']
44
117
  criteria[:night_count] = html_document.xpath('id("apply_night_count")/*/@value') .map {|attr| attr.value }.select {|val| val != '' } # (1..2)
45
- criteria[:room_number] = html_document.xpath('id("house_select")/*/@value') .map {|attr| attr.value.to_i } # (1..10)
118
+ criteria[:room_count] = html_document.xpath('id("house_select")/*/@value') .map {|attr| attr.value.to_i } # (1..10)
46
119
  criteria
47
120
  end
48
121
 
49
- def self.preprocess_reservation_data(reservation_data)
122
+ def self.preprocess_reservation_data(reservation_data, type: :lottery)
50
123
  reservation_data[:birth_year] = reservation_data[:birth_year].to_s
51
124
  reservation_data[:birth_month] = reservation_data[:birth_month].to_s
52
125
  reservation_data[:birth_day] = reservation_data[:birth_day].to_s
53
126
  reservation_data[:state] = reservation_data[:state].to_s
54
- reservation_data[:night_count] = reservation_data[:night_count].to_s
55
- reservation_data[:room_persons] = Array(reservation_data[:room_persons])
56
- reservation_data[:meeting_dates] = Array(reservation_data[:meeting_dates])
127
+ if type == :lottery
128
+ reservation_data[:night_count] = reservation_data[:night_count].to_s
129
+ reservation_data[:room_persons] = Array(reservation_data[:room_persons])
130
+ reservation_data[:meeting_dates] = Array(reservation_data[:meeting_dates])
131
+ end
57
132
  reservation_data
58
133
  end
59
134
 
60
- def self.validate_reservation_data(reservation_data, html_document)
61
- reservation_data = preprocess_reservation_data(reservation_data)
62
- criteria = reservation_criteria(html_document)
135
+ def self.preprocess_vacant_search_condition(search_condition)
136
+ search_condition[:night_count] = search_condition[:night_count].to_s
137
+ search_condition[:room_persons] = Array(search_condition[:room_persons])
138
+ search_condition
139
+ end
140
+
141
+ def self.validate_reservation_data(reservation_data, html_document, type: :lottery)
142
+ reservation_data = preprocess_reservation_data(reservation_data, type: type)
143
+ criteria = reservation_criteria(html_document, type: type)
63
144
 
64
145
  schema = Dry::Validation.Schema do
65
146
  required(:sign_no) .filled(:int?)
@@ -75,21 +156,40 @@ module KenpoApi
75
156
  required(:postal_code) .filled(format?: /^[0-9]{3}-[0-9]{4}$/)
76
157
  required(:state) .filled(included_in?: criteria[:state])
77
158
  required(:address) .filled(:str?)
159
+ if type == :lottery
160
+ required(:join_time) .filled(included_in?: criteria[:join_time])
161
+ required(:night_count) .filled(included_in?: criteria[:night_count])
162
+ required(:stay_persons) .filled(:int?)
163
+ required(:room_persons) .filled{ array? & each(:int?) & size?(criteria[:room_count]) }
164
+ required(:meeting_dates).value{ array? & each{ int? & included_in?([1,2,3]) } & size?((0..3)) }
165
+ required(:must_meeting) .maybe(:bool?)
166
+ end
167
+ end
168
+
169
+ result = schema.call(reservation_data)
170
+ raise ValidationError.new("Reservation data is invalid. #{result.messages.to_s}") if result.failure?
171
+ raise ValidationError.new('Stay persons count should match the sum of room persons') unless reservation_data[:stay_persons] == reservation_data[:room_persons].inject(:+)
172
+ result.output
173
+ end
174
+
175
+ def self.validate_vacant_search_condition(search_condition, html_document)
176
+ search_condition = preprocess_vacant_search_condition(search_condition)
177
+ criteria = vacant_search_criteria(html_document)
178
+
179
+ schema = Dry::Validation.Schema do
78
180
  required(:join_time) .filled(included_in?: criteria[:join_time])
79
181
  required(:night_count) .filled(included_in?: criteria[:night_count])
80
182
  required(:stay_persons) .filled(:int?)
81
- required(:room_persons) .filled{ array? & each(:int?) & size?(criteria[:room_number]) }
82
- required(:meeting_dates).value{ array? & each{ int? & included_in?([1,2,3]) } & size?((0..3)) }
83
- required(:must_meeting) .maybe(:bool?)
183
+ required(:room_persons) .filled{ array? & each(:int?) & size?(criteria[:room_count]) }
84
184
  end
85
185
 
86
- result = schema.call(reservation_data)
87
- raise ValidationError.new("Reservation data is invalid. #{result.messages.to_s}") if result.failure?
88
- reise ValidationError.new('Stay persons count should match the sum of room persons') unless reservation_data[:stay_persons] != reservation_data[:room_persons].inject(:+)
186
+ result = schema.call(search_condition)
187
+ raise ValidationError.new("Search condition is invalid. #{result.messages.to_s}") if result.failure?
188
+ raise ValidationError.new('Stay persons count should match the sum of room persons') unless search_condition[:stay_persons] == search_condition[:room_persons].inject(:+)
89
189
  result.output
90
190
  end
91
191
 
92
- def self.convert_to_reservation_post_params(original_data)
192
+ def self.convert_to_reservation_post_params(original_data, type: :lottery)
93
193
  post_params = {}
94
194
  post_params['apply[sign_no]'] = original_data[:sign_no]
95
195
  post_params['apply[insured_no]'] = original_data[:insured_no]
@@ -104,6 +204,32 @@ module KenpoApi
104
204
  post_params['apply[postal]'] = original_data[:postal_code]
105
205
  post_params['apply[state]'] = original_data[:state]
106
206
  post_params['apply[address]'] = original_data[:address]
207
+ if type == :lottery
208
+ post_params['apply[join_time]'] = original_data[:join_time]
209
+ post_params['apply[night_count]'] = original_data[:night_count]
210
+ post_params['apply[stay_persons]'] = original_data[:stay_persons]
211
+ post_params['apply[hope_rooms]'] = original_data[:room_persons].size()
212
+ post_params['apply[hope_room1]'] = original_data[:room_persons][0]
213
+ post_params['apply[hope_room2]'] = original_data[:room_persons][1] || ''
214
+ post_params['apply[hope_room3]'] = original_data[:room_persons][2] || ''
215
+ post_params['apply[hope_room4]'] = original_data[:room_persons][3] || ''
216
+ post_params['apply[hope_room5]'] = original_data[:room_persons][4] || ''
217
+ post_params['apply[hope_room6]'] = original_data[:room_persons][5] || ''
218
+ post_params['apply[hope_room7]'] = original_data[:room_persons][6] || ''
219
+ post_params['apply[hope_room8]'] = original_data[:room_persons][7] || ''
220
+ post_params['apply[hope_room9]'] = original_data[:room_persons][8] || ''
221
+ post_params['apply[hope_room10]'] = original_data[:room_persons][9] || ''
222
+ post_params['apply[use_meeting_flag]'] = original_data[:meeting_dates].any? ? 'use' : 'no_use'
223
+ post_params['apply[use_meeting1]'] = original_data[:meeting_dates].include?(1) ? '1' : '0'
224
+ post_params['apply[use_meeting2]'] = original_data[:meeting_dates].include?(2) ? '1' : '0'
225
+ post_params['apply[use_meeting3]'] = (original_data[:meeting_dates].include?(3) && original_data[:night_count] >= 2) ? '1' : '0'
226
+ post_params['apply[must_meeting]'] = original_data[:must_meeting] ? 'must' : 'not_must'
227
+ end
228
+ post_params
229
+ end
230
+
231
+ def self.convert_to_vacant_search_post_params(original_data)
232
+ post_params = {}
107
233
  post_params['apply[join_time]'] = original_data[:join_time]
108
234
  post_params['apply[night_count]'] = original_data[:night_count]
109
235
  post_params['apply[stay_persons]'] = original_data[:stay_persons]
@@ -118,11 +244,6 @@ module KenpoApi
118
244
  post_params['apply[hope_room8]'] = original_data[:room_persons][7] || ''
119
245
  post_params['apply[hope_room9]'] = original_data[:room_persons][8] || ''
120
246
  post_params['apply[hope_room10]'] = original_data[:room_persons][9] || ''
121
- post_params['apply[use_meeting_flag]'] = original_data[:meeting_dates].any? ? 'use' : 'no_use'
122
- post_params['apply[use_meeting1]'] = original_data[:meeting_dates].include?(1) ? '1' : '0'
123
- post_params['apply[use_meeting2]'] = original_data[:meeting_dates].include?(2) ? '1' : '0'
124
- post_params['apply[use_meeting3]'] = (original_data[:meeting_dates].include?(3) && original_data[:night_count] >= 2) ? '1' : '0'
125
- post_params['apply[must_meeting]'] = original_data[:must_meeting] ? 'must' : 'not_must'
126
247
  post_params
127
248
  end
128
249
 
@@ -12,6 +12,7 @@ module KenpoApi
12
12
  laforet: 'ラフォーレ倶楽部',
13
13
  thalassotherapy: 'タラソテラピー',
14
14
  recreation: '体育奨励イベント',
15
+ room_search_vacant: '健保会館付属会議室(空き照会)',
15
16
  }
16
17
 
17
18
  attr_reader :category_code, :name, :path
@@ -1,3 +1,3 @@
1
1
  module KenpoApi
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kenpo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tearoom6
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-11 00:00:00.000000000 Z
11
+ date: 2017-12-27 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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.11.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.11.3
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: faraday
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +73,7 @@ dependencies:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0.10'
62
- type: :development
76
+ type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
@@ -73,7 +87,7 @@ dependencies:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0.3'
76
- type: :development
90
+ type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
@@ -87,7 +101,7 @@ dependencies:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
103
  version: '1'
90
- type: :development
104
+ type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
@@ -101,7 +115,7 @@ dependencies:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0.10'
104
- type: :development
118
+ type: :runtime
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
@@ -115,8 +129,10 @@ executables: []
115
129
  extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
132
+ - ".dockerignore"
118
133
  - ".gitignore"
119
134
  - ".rspec"
135
+ - ".ruby-version"
120
136
  - ".travis.yml"
121
137
  - Gemfile
122
138
  - LICENSE
@@ -124,6 +140,8 @@ files:
124
140
  - Rakefile
125
141
  - bin/console
126
142
  - bin/setup
143
+ - docker-compose.yml
144
+ - docker/ruby/Dockerfile
127
145
  - kenpo_api.gemspec
128
146
  - lib/kenpo_api.rb
129
147
  - lib/kenpo_api/client.rb
@@ -153,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
171
  version: '0'
154
172
  requirements: []
155
173
  rubyforge_project:
156
- rubygems_version: 2.5.2
174
+ rubygems_version: 2.6.13
157
175
  signing_key:
158
176
  specification_version: 4
159
177
  summary: Unofficial API for ITS kenpo reservation system.