Module: KenpoApi::Routines

Included in:
Resort, Sport
Defined in:
lib/kenpo_api/routines.rb

Instance Method Summary collapse

Instance Method Details

#apply(application_url:) ⇒ Object

Block param receives one argument (html_document), and should return additional POST params.

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kenpo_api/routines.rb', line 31

def apply(application_url:)
  # Input application form.
  next_page_info, html_document = Client.instance.parse_single_form_page(path: application_url)
  raise NotAvailableError.new("Application URL is invalid: #{html_document.xpath('//p').first.content}") if next_page_info.nil?

  next_page_info[:params].merge!(yield html_document) if block_given?

  # Confirm.
  next_page_info, = Client.instance.parse_single_form_page(next_page_info)

  Client.instance.access(next_page_info)
end

#find_service(category_code:, group_name:, service_name: nil) ⇒ Object

Returns first service if you specify nil to service_name.

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kenpo_api/routines.rb', line 5

def find_service(category_code:, group_name:, service_name: nil)
  category = ServiceCategory.find(category_code.to_sym)
  raise NotFoundError.new("Service category not found. code: #{category_code}") if category.nil?

  group = category.find_service_group(group_name)
  raise NotFoundError.new("Service group not found. name: #{group_name}") if group.nil?
  raise NotAvailableError.new("No available services. name: #{group_name}") unless group.available?

  return group.services.first if service_name.nil?
  service = group.find_service(service_name)
  raise NotFoundError.new("Service not found. name: #{service_name}") if service.nil?
  service
end

#request_application_url(service_path:, email:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/kenpo_api/routines.rb', line 19

def request_application_url(service_path:, email:)
  # Accept agreement.
  next_page_info, = Client.instance.parse_single_form_page(path: service_path)

  # Input email.
  next_page_info, = Client.instance.parse_single_form_page(next_page_info)
  next_page_info[:params]['email'] = email

  Client.instance.access(next_page_info)
end