Class: Betfair::Response

Inherits:
Object
  • Object
show all
Includes:
ResponseParser
Defined in:
lib/em-betfair/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ResponseParser

#get_all_markets, #get_market, #get_market_prices_compressed, #get_market_traded_volume_compressed, #get_silks_v2, #login

Constructor Details

#initialize(raw, parsed, successfull, error = "") ⇒ Response

Returns a new instance of Response.

Parameters:

  • raw (String)

    raw request body from EM::Http request

  • parsed (String)

    Nokogiri XML object

  • successfull (Boolean)

    boolean for status of request

  • error (String) (defaults to: "")

    error message



17
18
19
20
21
22
# File 'lib/em-betfair/response.rb', line 17

def initialize raw, parsed, successfull, error=""
  @raw_response = raw
  @parsed_response = parsed
  @successfull = successfull
  @error = error
end

Instance Attribute Details

#errorObject

String error message



11
12
13
# File 'lib/em-betfair/response.rb', line 11

def error
  @error
end

#parsed_responseObject

response xml (Nokogiri::XML object)



9
10
11
# File 'lib/em-betfair/response.rb', line 9

def parsed_response
  @parsed_response
end

#raw_responseObject

raw response body (String)



8
9
10
# File 'lib/em-betfair/response.rb', line 8

def raw_response
  @raw_response
end

#successfullObject

boolean



10
11
12
# File 'lib/em-betfair/response.rb', line 10

def successfull
  @successfull
end

Instance Method Details

#get_response_typeObject

Gets the response method based on the parsed response object



31
32
33
34
35
# File 'lib/em-betfair/response.rb', line 31

def get_response_type
  return nil unless self.parsed_response.respond_to?(:xpath)
  response_type = self.parsed_response.xpath("//ns:Envelope/ns:Body", "ns" => "http://schemas.xmlsoap.org/soap/envelope/").first.elements.first.name
  underscore(response_type.gsub("Response",""))
end

#hash_responseObject

Returns Hash of response parsed using the Betfair::ResponseParser.

Returns:

  • Hash of response parsed using the Betfair::ResponseParser



25
26
27
28
# File 'lib/em-betfair/response.rb', line 25

def hash_response
  method = get_response_type
  self.send method.to_sym, self.parsed_response if method && self.respond_to?(method)
end

#underscore(camel_cased_word) ⇒ String

Stolen from active support

Parameters:

  • camel_cased_word (String)

    Camel cased method name

Returns:

  • (String)

    underscored method name



40
41
42
43
44
45
46
# File 'lib/em-betfair/response.rb', line 40

def underscore(camel_cased_word)
  camel_cased_word.to_s.gsub(/::/, '/').
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
  tr("-", "_").
  downcase
end