Class: KenpoApi::Sport

Inherits:
Object
  • Object
show all
Extended by:
Routines
Defined in:
lib/kenpo_api/sport.rb

Class Method Summary collapse

Methods included from Routines

apply, find_service, request_application_url

Class Method Details

.apply_reservation(application_url, application_data) ⇒ Object



24
25
26
27
28
29
# File 'lib/kenpo_api/sport.rb', line 24

def self.apply_reservation(application_url, application_data)
  apply(application_url: application_url) do |html_document|
    reservation_data = self.validate_reservation_data(application_data, html_document)
    convert_to_reservation_post_params(reservation_data)
  end
end

.check_reservation_criteria(application_url) ⇒ Object

Raises:



18
19
20
21
22
# File 'lib/kenpo_api/sport.rb', line 18

def self.check_reservation_criteria(application_url)
  html_document = Client.instance.fetch_document(path: application_url)
  raise NotAvailableError.new("Application URL is invalid: #{html_document.xpath('//p').first.content}") if html_document.xpath('//form').first.nil?
  reservation_criteria(html_document)
end

.request_reservation_url(sport_name:, email:) ⇒ Object



13
14
15
16
# File 'lib/kenpo_api/sport.rb', line 13

def self.request_reservation_url(sport_name:, email:)
  service = find_service(category_code: :sport_reserve, group_name: sport_name)
  request_application_url(service_path: service.path, email: email)
end

.sport_namesObject

Raises:



7
8
9
10
11
# File 'lib/kenpo_api/sport.rb', line 7

def self.sport_names
  category = ServiceCategory.find(:sport_reserve)
  raise NotFoundError.new("Service category not found. code: #{category_code}") if category.nil?
  category.service_groups.map {|group| group.name}
end