Class: GolfSwitch::CourseAvailRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/golf_switch/course_avail_request.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

#initializeCourseAvailRequest

Returns a new instance of CourseAvailRequest.



10
11
12
# File 'lib/golf_switch/course_avail_request.rb', line 10

def initialize
  @course_avails = []
end

Instance Attribute Details

#api_responseObject

Returns the value of attribute api_response.



8
9
10
# File 'lib/golf_switch/course_avail_request.rb', line 8

def api_response
  @api_response
end

#course_availsObject

Returns the value of attribute course_avails.



8
9
10
# File 'lib/golf_switch/course_avail_request.rb', line 8

def course_avails
  @course_avails
end

Instance Method Details

#commitObject



14
15
16
# File 'lib/golf_switch/course_avail_request.rb', line 14

def commit
  super("course_avail")
end

#course_avail_attributesObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/golf_switch/course_avail_request.rb', line 18

def course_avail_attributes
  option_attributes = []
  Array(@course_avails).flatten.compact.each do |avail|
    if avail.is_a?(GolfSwitch::CourseAvail)
      option_attributes << avail.option_attributes
    else
      # Raise an error it should be an object of course Avail
    end
  end
  option_attributes
end

#get_optionsObject



30
31
32
33
34
35
36
37
# File 'lib/golf_switch/course_avail_request.rb', line 30

def get_options
  {
    "Req"=>{
      "CourseAvailRequest"=>course_avail_attributes
    }

  }
end

#parse_errorObject



39
40
41
# File 'lib/golf_switch/course_avail_request.rb', line 39

def parse_error
  @response[:course_avail_response][:course_avail_result]
end

#parse_responseObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/golf_switch/course_avail_request.rb', line 43

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

  end
end