betfair 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README +6 -2
- data/lib/betfair/api.rb +21 -4
- data/lib/betfair/version.rb +1 -1
- data/spec/betfair/api_spec.rb +31 -12
- data/spec/fixtures/login/bad_password.xml +22 -0
- metadata +14 -13
data/.gitignore
CHANGED
data/README
CHANGED
@@ -44,9 +44,13 @@ as the UK.
|
|
44
44
|
At the heart of the Betfair API is the `session_token`. In order to
|
45
45
|
get one of these simply call:
|
46
46
|
|
47
|
-
session_token = bf.login('username', 'password',
|
47
|
+
session_token = bf.login('username', 'password',
|
48
|
+
::Betfair::API;;PRODUCT_ID_FREE, 0, 0, nil)
|
48
49
|
|
49
|
-
Username and Password are fairly obvious.
|
50
|
+
Username and Password are fairly obvious. The `session_token` value
|
51
|
+
you get back responds to #success? which will tell you whether login
|
52
|
+
was successful or not. If `session_token.success?` returns false,
|
53
|
+
`session_token.to_s` will give you the error message.
|
50
54
|
|
51
55
|
82 is the standard Product Id, you may have a different one depending
|
52
56
|
on the level of Betfair API access that you have.
|
data/lib/betfair/api.rb
CHANGED
@@ -15,6 +15,19 @@ module Betfair
|
|
15
15
|
BET_TYPE_BACK = 'B'
|
16
16
|
|
17
17
|
|
18
|
+
## Success and Failure get mixed in to API result values
|
19
|
+
# so that you can tell the difference easily - just call
|
20
|
+
# #success? on the result to find out if it worked
|
21
|
+
module Success
|
22
|
+
def success?; true; end
|
23
|
+
end # module Success
|
24
|
+
|
25
|
+
|
26
|
+
module Failure
|
27
|
+
def success?; false; end
|
28
|
+
end # module Failure
|
29
|
+
|
30
|
+
|
18
31
|
## API METHODS
|
19
32
|
#
|
20
33
|
|
@@ -183,8 +196,8 @@ module Betfair
|
|
183
196
|
:vendorSoftwareId => vendor_software_id,
|
184
197
|
:locationId => location_id,
|
185
198
|
:ipAddress => ip_address )
|
186
|
-
|
187
|
-
|
199
|
+
|
200
|
+
return response.maybe_result( :header, :session_token )
|
188
201
|
end
|
189
202
|
|
190
203
|
#
|
@@ -299,7 +312,11 @@ module Betfair
|
|
299
312
|
|
300
313
|
|
301
314
|
def maybe_result( *path )
|
302
|
-
success?
|
315
|
+
if success?
|
316
|
+
path.inject(self){|m,r| m[r]}.extend( Success )
|
317
|
+
else
|
318
|
+
format_error().extend( Failure )
|
319
|
+
end
|
303
320
|
end
|
304
321
|
|
305
322
|
|
@@ -483,4 +500,4 @@ module Betfair
|
|
483
500
|
|
484
501
|
end
|
485
502
|
|
486
|
-
end
|
503
|
+
end
|
data/lib/betfair/version.rb
CHANGED
data/spec/betfair/api_spec.rb
CHANGED
@@ -239,22 +239,41 @@ module Betfair
|
|
239
239
|
@bf = Betfair::API.new
|
240
240
|
end
|
241
241
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
242
|
+
|
243
|
+
describe "login" do
|
244
|
+
let( :response ) { @bf.login('username', 'password', 82, 0, 0, nil) }
|
245
|
+
subject { response }
|
246
|
+
|
247
|
+
before do savon.expects( api_call ).returns( api_response ) end
|
248
|
+
|
249
|
+
let( :api_call ) { :login }
|
250
|
+
|
251
|
+
describe "success" do
|
252
|
+
let( :api_response ) { :success }
|
253
|
+
|
254
|
+
it { should be_a_kind_of(String) }
|
255
|
+
it { should be_success }
|
247
256
|
end
|
248
|
-
end
|
249
257
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
258
|
+
describe "failure" do
|
259
|
+
describe "with a bad product code" do
|
260
|
+
let( :api_response ) { :fail }
|
261
|
+
|
262
|
+
it { should match('PRODUCT_REQUIRES_FUNDED_ACCOUNT') }
|
263
|
+
it { should_not be_success }
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "with a bad password" do
|
267
|
+
let( :api_response ) { :bad_password }
|
268
|
+
|
269
|
+
it { should match("INVALID_USERNAME_OR_PASSWORD") }
|
270
|
+
it { should_not be_success }
|
271
|
+
end
|
272
|
+
|
255
273
|
end
|
256
274
|
end
|
257
275
|
|
276
|
+
|
258
277
|
describe "proxy success" do
|
259
278
|
it "should return a session token" do
|
260
279
|
savon.expects(:login).returns(:success)
|
@@ -269,7 +288,7 @@ module Betfair
|
|
269
288
|
savon.expects(:login).returns(:fail)
|
270
289
|
proxy = 'http://localhost:8888'
|
271
290
|
error_code = Betfair::API.new(proxy).login('username', 'password', 82, 0, 0, nil)
|
272
|
-
error_code.should
|
291
|
+
error_code.should match('PRODUCT_REQUIRES_FUNDED_ACCOUNT')
|
273
292
|
end
|
274
293
|
end
|
275
294
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xmlns:n2="http://www.betfair.com/publicapi/types/global/v3/"
|
5
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
6
|
+
<soap:Body>
|
7
|
+
<n:loginResponse xmlns:n="http://www.betfair.com/publicapi/v3/BFGlobalService/">
|
8
|
+
<n:Result xsi:type="n2:LoginResp">
|
9
|
+
<header xsi:type="n2:APIResponseHeader">
|
10
|
+
<errorCode xsi:type="n2:APIErrorEnum">OK</errorCode>
|
11
|
+
<minorErrorCode xsi:nil="1"></minorErrorCode>
|
12
|
+
<sessionToken xsi:nil="1"></sessionToken>
|
13
|
+
<timestamp xsi:type="xsd:dateTime">2012-03-13T07:44:21.422Z</timestamp>
|
14
|
+
</header>
|
15
|
+
<currency xsi:nil="1"></currency>
|
16
|
+
<errorCode xsi:type="n2:LoginErrorEnum">INVALID_USERNAME_OR_PASSWORD</errorCode>
|
17
|
+
<minorErrorCode xsi:nil="1"></minorErrorCode>
|
18
|
+
<validUntil xsi:type="xsd:dateTime">0001-01-01T00:00:00.000Z</validUntil>
|
19
|
+
</n:Result>
|
20
|
+
</n:loginResponse>
|
21
|
+
</soap:Body>
|
22
|
+
</soap:Envelope>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: betfair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
16
|
-
requirement: &
|
16
|
+
requirement: &70181452429080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70181452429080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70181452427520 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70181452427520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70181452426460 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70181452426460
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: savon_spec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70181452425740 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70181452425740
|
58
58
|
description: Gem for accessing the Betfair API.
|
59
59
|
email:
|
60
60
|
- lukeb@lukebyrne.com
|
@@ -68,7 +68,6 @@ files:
|
|
68
68
|
- README
|
69
69
|
- Rakefile
|
70
70
|
- betfair.gemspec
|
71
|
-
- examples/doh.log
|
72
71
|
- examples/foo.rb
|
73
72
|
- lib/betfair.rb
|
74
73
|
- lib/betfair/api.rb
|
@@ -86,6 +85,7 @@ files:
|
|
86
85
|
- spec/fixtures/get_market_prices_compressed/success.xml
|
87
86
|
- spec/fixtures/get_mu_bets/fail.xml
|
88
87
|
- spec/fixtures/get_mu_bets/success.xml
|
88
|
+
- spec/fixtures/login/bad_password.xml
|
89
89
|
- spec/fixtures/login/fail.xml
|
90
90
|
- spec/fixtures/login/success.xml
|
91
91
|
- spec/fixtures/place_bets/fail.xml
|
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
version: '0'
|
106
106
|
segments:
|
107
107
|
- 0
|
108
|
-
hash:
|
108
|
+
hash: -4185997546867498005
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
none: false
|
111
111
|
requirements:
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash:
|
117
|
+
hash: -4185997546867498005
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project: betfair
|
120
120
|
rubygems_version: 1.8.10
|
@@ -135,6 +135,7 @@ test_files:
|
|
135
135
|
- spec/fixtures/get_market_prices_compressed/success.xml
|
136
136
|
- spec/fixtures/get_mu_bets/fail.xml
|
137
137
|
- spec/fixtures/get_mu_bets/success.xml
|
138
|
+
- spec/fixtures/login/bad_password.xml
|
138
139
|
- spec/fixtures/login/fail.xml
|
139
140
|
- spec/fixtures/login/success.xml
|
140
141
|
- spec/fixtures/place_bets/fail.xml
|