Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Joshua Lind
BetfairNGAPI
Commits
ec426803
Commit
ec426803
authored
Nov 24, 2014
by
Sergey Gernyak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract RequestMethod
parent
b1e135f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
2 deletions
+77
-2
lib/betfair_api_ng_rails.rb
lib/betfair_api_ng_rails.rb
+4
-2
lib/betfair_api_ng_rails/api/constants.rb
lib/betfair_api_ng_rails/api/constants.rb
+5
-0
lib/betfair_api_ng_rails/api/request_method.rb
lib/betfair_api_ng_rails/api/request_method.rb
+35
-0
spec/betfair_api_ng_rails/api/request_method_spec.rb
spec/betfair_api_ng_rails/api/request_method_spec.rb
+33
-0
No files found.
lib/betfair_api_ng_rails.rb
View file @
ec426803
...
...
@@ -15,8 +15,10 @@ module BetfairApiNgRails
autoload
:Provider
,
'betfair_api_ng_rails/api/provider'
autoload
:SessionManager
,
'betfair_api_ng_rails/api/session_manager'
autoload
:Connection
,
'betfair_api_ng_rails/api/connection'
autoload
:Hashalator
,
'betfair_api_ng_rails/api/hashalator'
autoload
:Connection
,
'betfair_api_ng_rails/api/connection'
autoload
:Hashalator
,
'betfair_api_ng_rails/api/hashalator'
autoload
:RequestMethod
,
'betfair_api_ng_rails/api/request_method'
module
Caching
autoload
:Helper
,
'betfair_api_ng_rails/api/caching/helper'
...
...
lib/betfair_api_ng_rails/api/constants.rb
View file @
ec426803
...
...
@@ -58,6 +58,11 @@ module BetfairApiNgRails
LOGIN_URL
=
"https://identitysso.betfair.com/api/certlogin"
KEEP_ALIVE_URL
=
"https://identitysso.betfair.com/api/keepAlive"
API_URL
=
{
betting:
'https://api-ng.betstores.com/betting/betfair/services/api.betfair.com/exchange/betting/json-rpc/v1'
,
account:
'https://developer.betfair.com/api.betfair.com/exchange/account/json-rpc/v1'
}
end
end
end
lib/betfair_api_ng_rails/api/request_method.rb
0 → 100644
View file @
ec426803
module
BetfairApiNgRails
module
Api
class
RequestMethod
include
Api
::
Constants
attr_reader
:name
def
initialize
(
name
)
@name
=
name
end
def
allowed?
allow_data
.
any?
end
def
type
return
:no_type
unless
allowed?
allow_data
.
keys
.
first
end
def
api_url
return
:no_api_url
unless
allowed?
API_URL
[
type
]
end
private
def
allow_data
@_allow_data
||=
ALLOWED_RESOURCES
.
keep_if
do
|
k
,
v
|
v
.
include?
name
end
end
end
end
end
spec/betfair_api_ng_rails/api/request_method_spec.rb
0 → 100644
View file @
ec426803
require
'spec_helper'
describe
BetfairApiNgRails
::
Api
::
RequestMethod
do
let
(
:method_name
)
{
'someMethod'
}
subject
(
:method
)
{
described_class
.
new
(
method_name
)
}
context
'has attributes'
do
its
(
:name
)
{
is_expected
.
to
eq
(
method_name
)
}
end
context
'when method is exists in allowed'
do
before
do
stub_const
(
'BetfairApiNgRails::Api::Constants::ALLOWED_RESOURCES'
,
{
betting:
[
method_name
]})
stub_const
(
'BetfairApiNgRails::Api::Constants::API_URL'
,
{
betting:
'api_url'
})
end
its
(
:type
)
{
is_expected
.
to
eq
(
:betting
)
}
its
(
:allowed?
)
{
is_expected
.
to
be_truthy
}
its
(
:api_url
)
{
is_expected
.
to
eq
(
'api_url'
)
}
end
context
'when method is not exists in allowed'
do
before
do
stub_const
(
'BetfairApiNgRails::Api::Constants::ALLOWED_RESOURCES'
,
{
betting:
[
'someMethod1'
]})
stub_const
(
'BetfairApiNgRails::Api::Constants::API_URL'
,
{
betting:
'api_url'
})
end
its
(
:type
)
{
is_expected
.
to
eq
(
:no_type
)
}
its
(
:allowed?
)
{
is_expected
.
to
be_falsey
}
its
(
:api_url
)
{
is_expected
.
to
eq
(
:no_api_url
)
}
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