golf_switch 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +127 -0
- data/Rakefile +1 -0
- data/examples/area_test.rb +15 -0
- data/examples/book_golf.rb +74 -0
- data/examples/cancel_booking.rb +78 -0
- data/examples/course_avail.rb +26 -0
- data/examples/course_avail_list.rb +33 -0
- data/examples/course_info.rb +15 -0
- data/examples/course_list.rb +15 -0
- data/examples/course_policy_test.rb +15 -0
- data/golf_switch.gemspec +20 -0
- data/lib/golf_switch.rb +42 -0
- data/lib/golf_switch/alt_rate_type.rb +28 -0
- data/lib/golf_switch/area.rb +52 -0
- data/lib/golf_switch/area_response.rb +27 -0
- data/lib/golf_switch/available_course.rb +53 -0
- data/lib/golf_switch/book_golf.rb +41 -0
- data/lib/golf_switch/book_golf_item.rb +50 -0
- data/lib/golf_switch/cancel_golf.rb +49 -0
- data/lib/golf_switch/cancel_golf_response.rb +16 -0
- data/lib/golf_switch/configuration.rb +28 -0
- data/lib/golf_switch/country.rb +30 -0
- data/lib/golf_switch/country_region.rb +29 -0
- data/lib/golf_switch/course.rb +28 -0
- data/lib/golf_switch/course_avail.rb +73 -0
- data/lib/golf_switch/course_avail_date.rb +25 -0
- data/lib/golf_switch/course_avail_list.rb +85 -0
- data/lib/golf_switch/course_avail_request.rb +56 -0
- data/lib/golf_switch/course_avail_time.rb +31 -0
- data/lib/golf_switch/course_info.rb +38 -0
- data/lib/golf_switch/course_info_course.rb +90 -0
- data/lib/golf_switch/course_list.rb +62 -0
- data/lib/golf_switch/course_list_course.rb +27 -0
- data/lib/golf_switch/course_policy.rb +14 -0
- data/lib/golf_switch/course_policy_response.rb +18 -0
- data/lib/golf_switch/get_alt_rate_type.rb +42 -0
- data/lib/golf_switch/get_course_policy.rb +50 -0
- data/lib/golf_switch/get_golf_booking.rb +49 -0
- data/lib/golf_switch/golf_book.rb +42 -0
- data/lib/golf_switch/golf_book_info.rb +17 -0
- data/lib/golf_switch/payment.rb +39 -0
- data/lib/golf_switch/player.rb +35 -0
- data/lib/golf_switch/region_area.rb +13 -0
- data/lib/golf_switch/request.rb +62 -0
- data/lib/golf_switch/score_card.rb +5 -0
- data/lib/golf_switch/version.rb +3 -0
- metadata +110 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CountryRegion < AreaResponse
|
3
|
+
attr_accessor :region_areas
|
4
|
+
def initialize(area_id=nil,name=nil)
|
5
|
+
super(area_id,name)
|
6
|
+
@region_areas = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse_region(region)
|
10
|
+
golfswitch_region = CountryRegion.new(region[:id],region[:nm])
|
11
|
+
golfswitch_region.parse_region_areas(region[:areas])
|
12
|
+
golfswitch_region
|
13
|
+
end
|
14
|
+
|
15
|
+
def areas
|
16
|
+
@region_areas
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse_region_areas(areas)
|
20
|
+
if areas[:area] && areas[:area].is_a?(Array)
|
21
|
+
areas[:area].each do |area|
|
22
|
+
@region_areas << RegionArea.parse_region_area(area)
|
23
|
+
end
|
24
|
+
elsif areas[:area] && areas[:area].is_a?(Hash)
|
25
|
+
@region_areas << RegionArea.parse_region_area(areas[:area])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module GolfSwitch
|
3
|
+
class Course
|
4
|
+
attr_accessor :id,:xid,:on_req,:nm,:cty,:st,:cou,:s_cou,:s_reg,:s_ar,:lat,:lon,:adv_days,:inside_days,:dist,:promo,:rating,:img,:img_base
|
5
|
+
# insideDays Max days within tee time bookings are allowed.
|
6
|
+
# Eg 0 = bookings for today are allowed
|
7
|
+
# 1 = bookings allowed for tomorrow, but not today
|
8
|
+
alias :name :nm
|
9
|
+
alias :country :cou
|
10
|
+
alias :state :st
|
11
|
+
alias :city :cty
|
12
|
+
alias :country_id :s_cou
|
13
|
+
alias :regon_id :s_reg
|
14
|
+
alias :area_id :s_ar
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
def img_url(protocol="https")
|
19
|
+
if @img
|
20
|
+
"#{protocol}://#{img_base.to_s}/#{self.id}/#{img.to_s}".gsub("\/\/",'/')
|
21
|
+
else
|
22
|
+
""
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseAvail < GolfSwitch::Request
|
3
|
+
attr_accessor :course_id,:play_beg_date,:play_end_date,:time,:players,:alt_rate_type,:promo_code
|
4
|
+
attr_accessor :member_no,:member_no2,:member_no3,:member_no4
|
5
|
+
attr_accessor :show_all_times,:barter_only,:charging_only,:specials_only,:regular_rate_only,:profile_id,:api_response
|
6
|
+
|
7
|
+
def initialize(attributes = {})
|
8
|
+
attributes.each do |name, value|
|
9
|
+
begin
|
10
|
+
send("#{name}=", value)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
@play_end_date||= @play_beg_date
|
14
|
+
end
|
15
|
+
|
16
|
+
def option_attributes
|
17
|
+
options = {}
|
18
|
+
options.merge!("CourseId"=>@course_id) unless @course_id.blank?
|
19
|
+
options.merge!("PlayBegDate"=>(DateTime.parse(@play_beg_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_beg_date.blank?
|
20
|
+
options.merge!("PlayEndDate"=>(DateTime.parse(@play_end_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_end_date.blank?
|
21
|
+
|
22
|
+
options.merge!("MemberNo"=>@member_no) unless @member_no.blank?
|
23
|
+
options.merge!("MemberNo2"=>@member_no2) unless @member_no2.blank?
|
24
|
+
options.merge!("MemberNo3"=>@member_no3) unless @member_no3.blank?
|
25
|
+
options.merge!("MemberNo4"=>@member_no4) unless @member_no4.blank?
|
26
|
+
|
27
|
+
options.merge!("Time"=>@time) unless @time.blank?
|
28
|
+
options.merge!("Players"=>@players) unless @players.blank?
|
29
|
+
options.merge!("AltRateType"=>@alt_rate_type) unless @alt_rate_type.blank?
|
30
|
+
options.merge!("PromoCode"=>@promo_code) unless @promo_code.blank?
|
31
|
+
options.merge!("ShowAllTimes"=>@show_all_times) unless @show_all_times.blank?
|
32
|
+
options.merge!("BarterOnly"=>@barter_only) unless @barter_only.blank?
|
33
|
+
options.merge!("ChargingOnly"=>@charging_only) unless @charging_only.blank?
|
34
|
+
options.merge!("SpecialsOnly"=>@specials_only) unless @specials_only.blank?
|
35
|
+
options.merge!("RegularRateOnly"=>@regular_rate_only) unless @regular_rate_only.blank?
|
36
|
+
options.merge!("ProfileId"=>@profile_id) unless @profile_id.blank?
|
37
|
+
options
|
38
|
+
end
|
39
|
+
|
40
|
+
def commit
|
41
|
+
super("course_avail")
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_options
|
45
|
+
{
|
46
|
+
"Req"=>{
|
47
|
+
"CourseAvailRequest"=>option_attributes
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_error
|
54
|
+
begin
|
55
|
+
@response[:course_avail_response][:course_avail_result]
|
56
|
+
rescue
|
57
|
+
"Error on Parsing error messsage"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_response
|
62
|
+
begin
|
63
|
+
unless error?
|
64
|
+
@api_response = AvailableCourse.parse_courses(@response[:course_avail_response][:course_avail_result])
|
65
|
+
else
|
66
|
+
puts "Error #{error_message}"
|
67
|
+
end
|
68
|
+
rescue
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseAvailDate
|
3
|
+
attr_accessor :dt,:al_times
|
4
|
+
alias :date :dt
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@al_times = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse_date_info(al_date)
|
11
|
+
|
12
|
+
avail_date = CourseAvailDate.new
|
13
|
+
avail_date.dt= al_date[:dt]
|
14
|
+
if al_date[:times] && al_date[:times][:al_time].is_a?(Array)
|
15
|
+
al_date[:times][:al_time].each do |al_time|
|
16
|
+
avail_date.al_times << CourseAvailTime.new(al_time)
|
17
|
+
end
|
18
|
+
elsif al_date[:times] && al_date[:times][:al_time].is_a?(Hash)
|
19
|
+
avail_date.al_times << CourseAvailTime.new(al_date[:times][:al_time])
|
20
|
+
end
|
21
|
+
avail_date
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseAvailList < GolfSwitch::Request
|
3
|
+
attr_accessor :country_id,:region_id,:area
|
4
|
+
attr_accessor :play_beg_date,:play_end_date,:time,:players,:alt_rate_type,:promo_code
|
5
|
+
attr_accessor :latitude,:longitude,:postal_code,:max_distance,:max_distance_type,:featured_only
|
6
|
+
attr_accessor :show_all_times,:show_if_no_times,:barter_only,:charging_only,:specials_only,:regular_rate_only
|
7
|
+
attr_accessor :profile_id,:api_response
|
8
|
+
# play_beg_date,play_end_date is "yyyy-mm-dd" format
|
9
|
+
# Time HHMM format
|
10
|
+
def initialize(attributes = {})
|
11
|
+
|
12
|
+
attributes.each do |name, value|
|
13
|
+
begin
|
14
|
+
send("#{name}=", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@max_distance_type = "M" unless ["M","K"].include?(@max_distance_type)
|
18
|
+
@country_id ||= "USA"
|
19
|
+
@play_end_date||= @play_beg_date
|
20
|
+
end
|
21
|
+
|
22
|
+
def option_attributes
|
23
|
+
options = {}
|
24
|
+
options.merge!("CountryId"=>@country_id) unless @country_id.blank?
|
25
|
+
options.merge!("RegionId"=>@region_id) unless @region_id.blank?
|
26
|
+
options.merge!("Area"=>@area) unless @area.blank?
|
27
|
+
|
28
|
+
options.merge!("PlayBegDate"=>(DateTime.parse(@play_beg_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_beg_date.blank?
|
29
|
+
|
30
|
+
options.merge!("PlayEndDate"=>(DateTime.parse(@play_end_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_end_date.blank?
|
31
|
+
|
32
|
+
options.merge!("Time"=>@time) unless @time.blank?
|
33
|
+
options.merge!("Players"=>@players) unless @players.blank?
|
34
|
+
options.merge!("AltRateType"=>@alt_rate_type) unless @alt_rate_type.blank?
|
35
|
+
options.merge!("PromoCode"=>@promo_code) unless @promo_code.blank?
|
36
|
+
|
37
|
+
options.merge!("Latitude"=>@latitude) unless @latitude.blank?
|
38
|
+
options.merge!("Longitude"=>@longitude) unless @longitude.blank?
|
39
|
+
options.merge!("PostalCode"=>@postal_code) unless @postal_code.blank?
|
40
|
+
options.merge!("MaxDistance"=>@max_distance) unless @max_distance.blank?
|
41
|
+
options.merge!("MaxDistanceType"=>@max_distance_type) if !@max_distance.blank? && !@max_distance_type.blank?
|
42
|
+
options.merge!("FeaturedOnly"=>@featured_only) unless @featured_only.blank?
|
43
|
+
|
44
|
+
options.merge!("ShowAllTimes"=>@show_all_times) unless @show_all_times.blank?
|
45
|
+
options.merge!("ShowIfNoTimes"=>@show_if_no_times) unless @show_if_no_times.blank?
|
46
|
+
options.merge!("BarterOnly"=>@barter_only) unless @barter_only.blank?
|
47
|
+
options.merge!("ChargingOnly"=>@charging_only) unless @charging_only.blank?
|
48
|
+
options.merge!("SpecialsOnly"=>@specials_only) unless @specials_only.blank?
|
49
|
+
options.merge!("RegularRateOnly"=>@regular_rate_only) unless @regular_rate_only.blank?
|
50
|
+
options.merge!("ProfileId"=>@profile_id) unless @profile_id.blank?
|
51
|
+
|
52
|
+
|
53
|
+
options
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_options
|
57
|
+
{
|
58
|
+
"Req"=>
|
59
|
+
option_attributes
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def commit
|
64
|
+
super("course_avail_list")
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_error
|
68
|
+
@response[:course_avail_list_response][:course_avail_list_result]
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_response
|
72
|
+
begin
|
73
|
+
unless error?
|
74
|
+
@api_response = AvailableCourse.parse_courses(@response[:course_avail_list_response][:course_avail_list_result])
|
75
|
+
else
|
76
|
+
puts "Error #{error_message}"
|
77
|
+
end
|
78
|
+
rescue
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# avail_course = GolfSwitch::CourseAvailRequest.new
|
2
|
+
# avail_course.course_avails << GolfSwitch::CourseAvail.new(options)
|
3
|
+
# avail_course.course_avails << GolfSwitch::CourseAvail.new(options)
|
4
|
+
# avail_course.commit
|
5
|
+
|
6
|
+
module GolfSwitch
|
7
|
+
class CourseAvailRequest < GolfSwitch::Request
|
8
|
+
attr_accessor :course_avails,:api_response
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@course_avails = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def commit
|
15
|
+
super("course_avail")
|
16
|
+
end
|
17
|
+
|
18
|
+
def course_avail_attributes
|
19
|
+
option_attributes = []
|
20
|
+
Array(@course_avails).flatten.compact.each do |avail|
|
21
|
+
if avail.is_a?(GolfSwitch::CourseAvail)
|
22
|
+
option_attributes << avail.option_attributes
|
23
|
+
else
|
24
|
+
# Raise an error it should be an object of course Avail
|
25
|
+
end
|
26
|
+
end
|
27
|
+
option_attributes
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_options
|
31
|
+
{
|
32
|
+
"Req"=>{
|
33
|
+
"CourseAvailRequest"=>course_avail_attributes
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_error
|
40
|
+
@response[:course_avail_response][:course_avail_result]
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_response
|
44
|
+
begin
|
45
|
+
unless error?
|
46
|
+
@api_response = AvailableCourse.parse_courses(@response[:course_avail_response][:course_avail_result])
|
47
|
+
else
|
48
|
+
puts "Error #{error_message}"
|
49
|
+
end
|
50
|
+
rescue
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseAvailTime
|
3
|
+
attr_accessor :tm,:allow,:pp_price,:pp_reg_price,:pp_txn_fee,:curr,:pp_txn_free,:pp_charge,:chrg_curr,:pp_non_ref,:pp_net_rt,:pp_rew_pts,:inc,:info,:flags
|
4
|
+
alias :per_person_price :pp_price
|
5
|
+
alias :per_person_charge :pp_charge
|
6
|
+
def initialize(attributes={})
|
7
|
+
attributes.each do |name, value|
|
8
|
+
begin
|
9
|
+
send("#{name}=", value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def no_of_allowed_player
|
14
|
+
@allow.split("").count{|p| p=='Y'}
|
15
|
+
end
|
16
|
+
|
17
|
+
def min_player
|
18
|
+
min_index = @allow.split("").index("N")
|
19
|
+
min_index.blank? ? 1 : min_index+2
|
20
|
+
end
|
21
|
+
|
22
|
+
def max_player
|
23
|
+
begin
|
24
|
+
@allow.split("").rindex("Y")+1
|
25
|
+
rescue
|
26
|
+
no_of_allowed_player
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseInfo < GolfSwitch::Request
|
3
|
+
attr_accessor :course_id,:api_response
|
4
|
+
|
5
|
+
def initialize(course_id)
|
6
|
+
@course_id = course_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_options
|
10
|
+
{
|
11
|
+
"Req"=>{
|
12
|
+
"CourseId"=>@course_id
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def commit
|
18
|
+
super("course_info")
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_error
|
22
|
+
@response[:course_info_response][:course_info_result]
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_response
|
26
|
+
begin
|
27
|
+
unless error?
|
28
|
+
@api_response = CourseInfoCourse.parse_course(@response[:course_info_response][:course_info_result])
|
29
|
+
else
|
30
|
+
puts "Error #{error_message}"
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
puts "Error On Parsing Response"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module GolfSwitch
|
2
|
+
class CourseInfoCourse < GolfSwitch::Course
|
3
|
+
attr_accessor :from_price,:to_price,:curr,:note,:short_promo,:rating_cnt,:max_reward_points,:addr1,:zip
|
4
|
+
attr_accessor :cc_allow,:allow_players,:year_built,:holes,:designer,:greens,:imgs,:services
|
5
|
+
attr_accessor :has_net_rates,:has_trade,:cxl_policy,:payment_terms,:score_card,:dress_code
|
6
|
+
attr_accessor :yard_ages,:pars,:handicaps
|
7
|
+
|
8
|
+
def initialize(attributes={})
|
9
|
+
@yard_ages= []
|
10
|
+
@pars = []
|
11
|
+
@handicaps = []
|
12
|
+
@imgs = []
|
13
|
+
attributes.each do |name, value|
|
14
|
+
begin
|
15
|
+
if name.to_s=="imgs"
|
16
|
+
parse_images(value)
|
17
|
+
elsif name.to_s =="cxl_policy"
|
18
|
+
@cxl_policy = GolfSwitch::CoursePolicy.new(value)
|
19
|
+
elsif name.to_s == "score_card"
|
20
|
+
@yard_ages = parse_score_card((value[:yardages][:yardage] rescue nil))
|
21
|
+
@pars = parse_score_card((value[:pars][:par] rescue nil))
|
22
|
+
@handicaps =parse_score_card((value[:handicaps][:handicap] rescue nil))
|
23
|
+
else
|
24
|
+
send("#{name}=", value)
|
25
|
+
end
|
26
|
+
rescue
|
27
|
+
puts "Add #{name} as accessor in Corse Info Course"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
set_course_image
|
31
|
+
|
32
|
+
end
|
33
|
+
def set_course_image
|
34
|
+
unless @imgs.grep(/overview/).blank?
|
35
|
+
@img = @imgs.grep(/overview/).first
|
36
|
+
else
|
37
|
+
@img = @imgs[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_score_card(scores)
|
43
|
+
score_card =[]
|
44
|
+
if scores.is_a?(Array)
|
45
|
+
scores.each do |score|
|
46
|
+
score_card << GolfSwitch::ScoreCard.new(score)
|
47
|
+
end
|
48
|
+
elsif scores.is_a?(Hash)
|
49
|
+
score_card << GolfSwitch::ScoreCard.new(scores)
|
50
|
+
end
|
51
|
+
score_card
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_images(imgs)
|
55
|
+
if imgs[:img].is_a?(Array)
|
56
|
+
imgs[:img].each do |img|
|
57
|
+
@imgs << img
|
58
|
+
end
|
59
|
+
elsif imgs[:img].is_a?(String)
|
60
|
+
@imgs << imgs[:img]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def no_of_allowed_player
|
65
|
+
@allow_players.split("").count{|p| p=='Y'}
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.parse_course(response_hash)
|
69
|
+
CourseInfoCourse.new(response_hash[:course].merge(:img_base=>response_hash[:img_base]))
|
70
|
+
end
|
71
|
+
|
72
|
+
def images(protocol="https")
|
73
|
+
images = []
|
74
|
+
self.imgs.each do |img|
|
75
|
+
images << build_url(img,protocol)
|
76
|
+
end
|
77
|
+
images
|
78
|
+
end
|
79
|
+
|
80
|
+
protected
|
81
|
+
def build_url(img,protocol="https")
|
82
|
+
if img
|
83
|
+
"#{protocol}://#{self.img_base.to_s}/#{self.id}/#{img.to_s}".gsub("\/\/",'/')
|
84
|
+
else
|
85
|
+
""
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|