Class: Betfair::Response
- Inherits:
-
Object
- Object
- Betfair::Response
- Includes:
- ResponseParser
- Defined in:
- lib/em-betfair/response.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
String error message.
-
#parsed_response ⇒ Object
response xml (Nokogiri::XML object).
-
#raw_response ⇒ Object
raw response body (String).
-
#successfull ⇒ Object
boolean.
Instance Method Summary collapse
-
#get_response_type ⇒ Object
Gets the response method based on the parsed response object.
-
#hash_response ⇒ Object
Hash of response parsed using the Betfair::ResponseParser.
-
#initialize(raw, parsed, successfull, error = "") ⇒ Response
constructor
A new instance of Response.
-
#underscore(camel_cased_word) ⇒ String
Stolen from active support.
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.
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
#error ⇒ Object
String error message
11 12 13 |
# File 'lib/em-betfair/response.rb', line 11 def error @error end |
#parsed_response ⇒ Object
response xml (Nokogiri::XML object)
9 10 11 |
# File 'lib/em-betfair/response.rb', line 9 def parsed_response @parsed_response end |
#raw_response ⇒ Object
raw response body (String)
8 9 10 |
# File 'lib/em-betfair/response.rb', line 8 def raw_response @raw_response end |
#successfull ⇒ Object
boolean
10 11 12 |
# File 'lib/em-betfair/response.rb', line 10 def successfull @successfull end |
Instance Method Details
#get_response_type ⇒ Object
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_response ⇒ Object
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
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 |