Commit 61589048 authored by sergio1990's avatar sergio1990

Added concern for refreshing ssoid

parent 0a9d7bf1
......@@ -129,10 +129,11 @@ module BetfairApiNgRails
module ConnectionExt
autoload :ErrorHandling, 'betfair_api_ng_rails/api/connection_ext/error_handling'
autoload :Parsing, 'betfair_api_ng_rails/api/connection_ext/parsing'
autoload :Formatting, 'betfair_api_ng_rails/api/connection_ext/formatting'
autoload :Logging, 'betfair_api_ng_rails/api/connection_ext/logging'
autoload :ErrorHandling, 'betfair_api_ng_rails/api/connection_ext/error_handling'
autoload :SsoidRefreshing, 'betfair_api_ng_rails/api/connection_ext/ssoid_refreshing'
autoload :Parsing, 'betfair_api_ng_rails/api/connection_ext/parsing'
autoload :Formatting, 'betfair_api_ng_rails/api/connection_ext/formatting'
autoload :Logging, 'betfair_api_ng_rails/api/connection_ext/logging'
end
......
......@@ -10,9 +10,15 @@ module BetfairApiNgRails
include Api::ConnectionExt::Logging
include Api::ConnectionExt::ErrorHandling
include Api::ConnectionExt::SsoidRefreshing
include Api::ConnectionExt::Parsing
include Api::ConnectionExt::Formatting
def expire_ssoid
@_provider = nil
BetfairApiNgRails::Api::SessionManager.expire_ssoid
end
protected
def provider
......
require 'active_support/inflector'
require "betfair_api_ng_rails/errors"
module BetfairApiNgRails
module Api
module ConnectionExt
module SsoidRefreshing
include BetfairApiNgRails::Api::Constants
def self.included(base)
base.send :class_eval, <<-CODE
def request_with_ssoid_refreshing(method, params = {})
res = nil
begin
res = request_without_ssoid_refreshing(method, params)
rescue BetfairApiNgRails::APINGException => e
raise e unless is_ssoid_problem?(e)
try_request method, params
end
res
end
alias_method :request_without_ssoid_refreshing, :request
alias_method :request, :request_with_ssoid_refreshing
CODE
end
private
def is_ssoid_problem?(e)
e.info[:info]["code"] == -32099
end
def try_request(method, params)
expire_ssoid
request_without_ssoid_refreshing(method, params)
end
end
end
end
end
\ No newline at end of file
......@@ -2,7 +2,7 @@ require 'spec_helper'
describe BetfairApiNgRails::Api::Connection do
subject { described_class.new }
subject(:connection) { described_class.new }
describe "#request" do
......@@ -27,6 +27,16 @@ describe BetfairApiNgRails::Api::Connection do
end
describe "#expire_ssoid" do
it "resets provider and ssoid" do
expect(BetfairApiNgRails::Api::SessionManager).to receive(:expire_ssoid)
connection.expire_ssoid
expect(connection.instance_variable_get(:@_provider)).to be_nil
end
end
describe "private method" do
describe "#provider" do
......
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