Class: GolfSwitch::CourseAvailList

Inherits:
Request
  • Object
show all
Defined in:
lib/golf_switch/course_avail_list.rb

Instance Attribute Summary collapse

Attributes inherited from Request

#client, #config, #request, #response, #soap_error

Instance Method Summary collapse

Methods inherited from Request

#error?, #error_message, #get_authentication_header

Constructor Details

#initialize(attributes = {}) ⇒ CourseAvailList

play_beg_date,play_end_date is “yyyy-mm-dd” format Time HHMM format



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/golf_switch/course_avail_list.rb', line 10

def initialize(attributes = {})

  attributes.each do |name, value|
    begin
      send("#{name}=", value)
    end
  end
  @max_distance_type = "M" unless ["M","K"].include?(@max_distance_type)
  @country_id ||= "USA"
  @play_end_date||= @play_beg_date
end

Instance Attribute Details

#alt_rate_typeObject

Returns the value of attribute alt_rate_type.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def alt_rate_type
  @alt_rate_type
end

#api_responseObject

Returns the value of attribute api_response.



7
8
9
# File 'lib/golf_switch/course_avail_list.rb', line 7

def api_response
  @api_response
end

#areaObject

Returns the value of attribute area.



3
4
5
# File 'lib/golf_switch/course_avail_list.rb', line 3

def area
  @area
end

#barter_onlyObject

Returns the value of attribute barter_only.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def barter_only
  @barter_only
end

#charging_onlyObject

Returns the value of attribute charging_only.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def charging_only
  @charging_only
end

#country_idObject

Returns the value of attribute country_id.



3
4
5
# File 'lib/golf_switch/course_avail_list.rb', line 3

def country_id
  @country_id
end

Returns the value of attribute featured_only.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def featured_only
  @featured_only
end

#latitudeObject

Returns the value of attribute latitude.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def longitude
  @longitude
end

#max_distanceObject

Returns the value of attribute max_distance.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def max_distance
  @max_distance
end

#max_distance_typeObject

Returns the value of attribute max_distance_type.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def max_distance_type
  @max_distance_type
end

#play_beg_dateObject

Returns the value of attribute play_beg_date.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def play_beg_date
  @play_beg_date
end

#play_end_dateObject

Returns the value of attribute play_end_date.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def play_end_date
  @play_end_date
end

#playersObject

Returns the value of attribute players.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def players
  @players
end

#postal_codeObject

Returns the value of attribute postal_code.



5
6
7
# File 'lib/golf_switch/course_avail_list.rb', line 5

def postal_code
  @postal_code
end

#profile_idObject

Returns the value of attribute profile_id.



7
8
9
# File 'lib/golf_switch/course_avail_list.rb', line 7

def profile_id
  @profile_id
end

#promo_codeObject

Returns the value of attribute promo_code.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def promo_code
  @promo_code
end

#region_idObject

Returns the value of attribute region_id.



3
4
5
# File 'lib/golf_switch/course_avail_list.rb', line 3

def region_id
  @region_id
end

#regular_rate_onlyObject

Returns the value of attribute regular_rate_only.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def regular_rate_only
  @regular_rate_only
end

#show_all_timesObject

Returns the value of attribute show_all_times.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def show_all_times
  @show_all_times
end

#show_if_no_timesObject

Returns the value of attribute show_if_no_times.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def show_if_no_times
  @show_if_no_times
end

#specials_onlyObject

Returns the value of attribute specials_only.



6
7
8
# File 'lib/golf_switch/course_avail_list.rb', line 6

def specials_only
  @specials_only
end

#timeObject

Returns the value of attribute time.



4
5
6
# File 'lib/golf_switch/course_avail_list.rb', line 4

def time
  @time
end

Instance Method Details

#commitObject



63
64
65
# File 'lib/golf_switch/course_avail_list.rb', line 63

def commit
  super("course_avail_list")
end

#get_optionsObject



56
57
58
59
60
61
# File 'lib/golf_switch/course_avail_list.rb', line 56

def get_options
  {
    "Req"=>
      option_attributes
  }
end

#option_attributesObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/golf_switch/course_avail_list.rb', line 22

def option_attributes
  options = {}
  options.merge!("CountryId"=>@country_id) unless @country_id.blank?
  options.merge!("RegionId"=>@region_id) unless @region_id.blank?
  options.merge!("Area"=>@area) unless @area.blank?

  options.merge!("PlayBegDate"=>(DateTime.parse(@play_beg_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_beg_date.blank?

  options.merge!("PlayEndDate"=>(DateTime.parse(@play_end_date).strftime("%Y-%m-%dT00:00:00"))) unless @play_end_date.blank?

  options.merge!("Time"=>@time) unless @time.blank?
  options.merge!("Players"=>@players) unless @players.blank?
  options.merge!("AltRateType"=>@alt_rate_type) unless @alt_rate_type.blank?
  options.merge!("PromoCode"=>@promo_code) unless @promo_code.blank?

  options.merge!("Latitude"=>@latitude) unless @latitude.blank?
  options.merge!("Longitude"=>@longitude) unless @longitude.blank?
  options.merge!("PostalCode"=>@postal_code) unless @postal_code.blank?
  options.merge!("MaxDistance"=>@max_distance) unless @max_distance.blank?
  options.merge!("MaxDistanceType"=>@max_distance_type) if !@max_distance.blank? && !@max_distance_type.blank?
  options.merge!("FeaturedOnly"=>@featured_only) unless @featured_only.blank?

  options.merge!("ShowAllTimes"=>@show_all_times) unless @show_all_times.blank?
  options.merge!("ShowIfNoTimes"=>@show_if_no_times) unless @show_if_no_times.blank?
  options.merge!("BarterOnly"=>@barter_only) unless @barter_only.blank?
  options.merge!("ChargingOnly"=>@charging_only) unless @charging_only.blank?
  options.merge!("SpecialsOnly"=>@specials_only) unless @specials_only.blank?
  options.merge!("RegularRateOnly"=>@regular_rate_only) unless @regular_rate_only.blank?
  options.merge!("ProfileId"=>@profile_id) unless @profile_id.blank?


  options
end

#parse_errorObject



67
68
69
# File 'lib/golf_switch/course_avail_list.rb', line 67

def parse_error
  @response[:course_avail_list_response][:course_avail_list_result]
end

#parse_responseObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/golf_switch/course_avail_list.rb', line 71

def parse_response
  begin
    unless error?
      @api_response = AvailableCourse.parse_courses(@response[:course_avail_list_response][:course_avail_list_result])
    else
      puts "Error #{error_message}"
    end
  rescue

  end
end