Class: GolfSwitch::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#requestObject

Returns the value of attribute request.



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

def request
  @request
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

#soap_errorObject

Returns the value of attribute soap_error.



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

def soap_error
  @soap_error
end

Instance Method Details

#commit(method_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/golf_switch/request.rb', line 5

def commit(method_name)
  @soap_error = false
  @config =GolfSwitch.configuration
  @client = Savon.client({:wsdl=>@config.get_golf_switch_wsdl})
  # Available Operations
#     [:areas,:course_list,:course_info,:course_avail_list,:course_avail,:book_golf,
#      :get_golf_booking,:cancel_golf, :get_alt_rate_types,:get_course_policies]
  begin
    @request = @client.call(method_name.to_sym) do
      message  get_authentication_header.merge(get_options)
    end

  rescue Savon::SOAPFault => error

    @request = error.to_hash
    @soap_error= true
  rescue Savon::Error => error
    @request = error.to_hash
    @soap_error= true
  rescue Savon::InvalidResponseError
    Logger.log "Invalid server response"
  end
  @response = @request.body

end

#error?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/golf_switch/request.rb', line 49

def error?
  parse_error[:ret_cd].to_i != 0  || @soap_error
end

#error_messageObject



53
54
55
56
57
58
59
# File 'lib/golf_switch/request.rb', line 53

def error_message
  if @soap_error
    @request
  else
    parse_error[:ret_msg]
  end
end

#get_authentication_headerObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/golf_switch/request.rb', line 30

def get_authentication_header

  {
     "Hdr"=>{
      "ResellerId"=>@config.reseller_id,
      "PartnerId"=>@config.partner_id,
      "SourceCd"=>@config.source_cd || "A",
      "Lang"=>@config.lang,
      "UserIp"=>@config.user_ip,
      "UserSessionId"=>@config.user_session_id,
      "AccessKey"=>@config.access_key,
      "Agent"=>@config.agent,
      "gsSource"=>@config.gs_source,
      "gsDebug"=>@config.gs_debug || false

    }
  }
end