Module: Betfair::API::REST

Defined in:
lib/betfair/api/rest.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(obj) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/betfair/api/rest.rb', line 7

def self.extended(obj)
  obj.persistent_headers.merge!({
    "Accept" => "application/json",
    "Content-Type" => "application/json"
  })

  apis = {
    betting: "https://#{obj.endpoint}.betfair.com/exchange/betting/rest/v1.0",
    account: "https://#{obj.endpoint}.betfair.com/exchange/account/rest/v1.0",
  }

  obj.class::OPERATIONS.each do |api, operations|
    operations.each do |operation|
      define_method(operation) do |body = nil|
        raise "Not signed in" unless ["X-Authentication", "X-Application"].all? { |k| persistent_headers.key?(k) }

        post(url: "#{apis[api]}/#{operation.to_s.camelize(:lower)}/", body: body.to_json)
      end
    end
  end
end

Instance Method Details

#interactive_login(username, password) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/betfair/api/rest.rb', line 29

def (username, password)
  json = post({
    url: "https://identitysso.betfair.com/api/login",
    body: { username: username, password: password },
    headers: { "Content-Type" => "application/x-www-form-urlencoded" }
  })

  add_session_token_to_persistent_headers(json["token"])
end

#logoutObject



56
57
58
# File 'lib/betfair/api/rest.rb', line 56

def logout
  get(url: "https://identitysso.betfair.com/api/logout")
end

#non_interactive_login(username, password, cert_key_file_path, cert_file_path) ⇒ Object

Performs the login procedure recommended for applications which run autonomously

username: Betfair account username string
password: Betfair account password string
cert_key_file_path: Path to Betfair client certificate private key file
cert_key_path: Path to Betfair client certificate public key file associated with Betfair account


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/betfair/api/rest.rb', line 44

def (username, password, cert_key_file_path, cert_file_path)
  json = post({
    url: "https://identitysso-cert.betfair.com/api/certlogin",
    body: { username: username, password: password },
    headers: { "Content-Type"  => "application/x-www-form-urlencoded" },
    cert_key_file_path: cert_key_file_path,
    cert_file_path: cert_file_path
  })

  add_session_token_to_persistent_headers(json["sessionToken"])
end