Class: Betfair::API::SOAPClient
- Inherits:
-
Object
- Object
- Betfair::API::SOAPClient
- Defined in:
- lib/betfair/api.rb
Overview
A wrapper around the raw Savon::Client to hide the details of the Savon API and those parts of the Betfair API which are constant across the different API method calls
Constant Summary collapse
- NAMESPACES =
Handy constants
{ :aus => 'http://www.betfair.com/exchange/v3/BFExchangeService/AUS', :global => 'https://www.betfair.com/global/v3/BFGlobalService', :uk => 'http://www.betfair.com/exchange/v3/BFExchangeService/UK' }
- ENDPOINTS =
{ :aus => 'https://api-au.betfair.com/exchange/v5/BFExchangeService', :global => 'https://api.betfair.com/global/v3/BFGlobalService', :uk => 'https://api.betfair.com/exchange/v5/BFExchangeService' }
Class Method Summary collapse
- .aus(proxy) ⇒ Object
-
.global(proxy) ⇒ Object
Factory methods for building clients to the different endpoints.
-
.log=(logging) ⇒ Object
Wrapper to avoid leaking Savon’s logging API.
- .uk(proxy) ⇒ Object
Instance Method Summary collapse
-
#initialize(region, proxy) ⇒ SOAPClient
constructor
Pass the ‘region` (see ENDPOINTS for valid values) to pick the WSDL endpoint and namespace.
-
#request(method, result_field, body) ⇒ Object
Delegate the SOAP call to bf:‘method` with `body` as the `bf:request` field.
-
#session_request(session_token, method, result_field, body = {}) ⇒ Object
For those requests which take place in the context of a session, this method constructs the correct header and delegates to #request.
Constructor Details
#initialize(region, proxy) ⇒ SOAPClient
Pass the ‘region` (see ENDPOINTS for valid values) to pick the WSDL endpoint and namespace. `proxy` should be a string URL for HTTPI to use as a proxy setting.
329 330 331 332 333 334 335 |
# File 'lib/betfair/api.rb', line 329 def initialize( region, proxy ) @client = Savon::Client.new do |wsdl, http| wsdl.endpoint = ENDPOINTS[region] wsdl.namespace = NAMESPACES[region] http.proxy = proxy if proxy end end |
Class Method Details
.aus(proxy) ⇒ Object
319 |
# File 'lib/betfair/api.rb', line 319 def self.aus( proxy ); new( :aus, proxy ); end |
.global(proxy) ⇒ Object
Factory methods for building clients to the different endpoints
317 |
# File 'lib/betfair/api.rb', line 317 def self.global( proxy ); new( :global, proxy ); end |
.log=(logging) ⇒ Object
Wrapper to avoid leaking Savon’s logging API
323 |
# File 'lib/betfair/api.rb', line 323 def self.log=(logging); Savon.log = !!logging; end |
.uk(proxy) ⇒ Object
318 |
# File 'lib/betfair/api.rb', line 318 def self.uk( proxy ); new( :uk, proxy ); end |
Instance Method Details
#request(method, result_field, body) ⇒ Object
Delegate the SOAP call to bf:‘method` with `body` as the `bf:request` field. Getting a Hash back, this method returns response[:result] as its result.
341 342 343 344 345 346 347 348 349 |
# File 'lib/betfair/api.rb', line 341 def request( method, result_field, body ) response = @client.request( :bf, method ) { soap.body = { 'bf:request' => body } }.to_hash[result_field][:result] response.extend( ErrorPresenter ) response end |
#session_request(session_token, method, result_field, body = {}) ⇒ Object
For those requests which take place in the context of a session, this method constructs the correct header and delegates to #request.
354 355 356 357 358 359 |
# File 'lib/betfair/api.rb', line 354 def session_request( session_token, method, result_field, body = {}) header_body = { :header => api_request_header(session_token) } full_body = header_body.merge( body ) request method, result_field, full_body end |