Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Joshua Lind
BetfairNGAPI
Commits
582a28cc
Commit
582a28cc
authored
Dec 11, 2014
by
Sergey Gernyak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AccountManager implementation
parent
2489c32b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
0 deletions
+113
-0
lib/betfair_api_ng_rails.rb
lib/betfair_api_ng_rails.rb
+1
-0
lib/betfair_api_ng_rails/account_manager.rb
lib/betfair_api_ng_rails/account_manager.rb
+36
-0
spec/lib/betfair_api_ng_rails/account_manager_spec.rb
spec/lib/betfair_api_ng_rails/account_manager_spec.rb
+76
-0
No files found.
lib/betfair_api_ng_rails.rb
View file @
582a28cc
...
...
@@ -10,6 +10,7 @@ module BetfairApiNgRails
autoload
:Account
autoload
:AccountSession
autoload
:AccountManager
module
Api
extend
ActiveSupport
::
Autoload
...
...
lib/betfair_api_ng_rails/account_manager.rb
0 → 100644
View file @
582a28cc
require
'singleton'
module
BetfairApiNgRails
class
AccountManager
include
Singleton
attr_reader
:accounts
attr_reader
:default_account
def
initialize
clear
end
def
store
(
account
)
accounts
[
account
.
username
]
=
account
end
def
get
(
username
)
accounts
.
fetch
username
,
fetch_default_account
end
def
default
(
username
)
@default_account
=
username
end
def
clear
@accounts
=
{}
end
private
def
fetch_default_account
accounts
.
fetch
default_account
,
nil
end
end
end
spec/lib/betfair_api_ng_rails/account_manager_spec.rb
0 → 100644
View file @
582a28cc
require
'spec_helper'
describe
BetfairApiNgRails
::
AccountManager
do
let
(
:account
)
{
BetfairApiNgRails
::
Account
.
new
(
'user001'
,
'password'
,
'cf23f23'
)
}
subject
(
:manager
)
{
described_class
.
instance
}
it
{
is_expected
.
to
respond_to
:accounts
}
describe
'#store'
do
before
do
manager
.
clear
end
it
'stores account in global hash'
do
expect
{
manager
.
store
account
}.
to
change
(
manager
.
accounts
,
:count
).
by
1
end
end
describe
'#get'
do
context
'gets account by username'
do
context
'when it exists'
do
before
do
manager
.
store
account
end
it
'returns this one'
do
expect
(
manager
.
get
(
'user001'
)).
to
eq
account
end
end
context
'when it not exists'
do
context
'and default exists'
do
before
do
manager
.
store
account
manager
.
default
'user001'
end
it
'returns it'
do
expect
(
manager
.
get
(
'user002'
)).
to
eq
account
end
end
context
'and no defaults'
do
before
do
manager
.
clear
end
it
'returns nil'
do
expect
(
manager
.
get
(
'user002'
)).
to
be_nil
end
end
end
end
end
describe
'#clear'
do
before
do
manager
.
store
account
end
it
'cleares account register'
do
manager
.
clear
expect
(
manager
.
accounts
.
count
).
to
eq
0
end
end
describe
'#default'
do
it
'sets default account'
do
expect
{
manager
.
default
'user001'
}.
to_not
raise_error
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment