Commit ec426803 authored by Sergey Gernyak's avatar Sergey Gernyak

Extract RequestMethod

parent b1e135f9
......@@ -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'
......
......@@ -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
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment