Commit cf0a2629 authored by sergio1990's avatar sergio1990

Merge branch 'ssoid-refreshing'

parents 0a9d7bf1 202b4753
......@@ -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,14 @@ module BetfairApiNgRails
include Api::ConnectionExt::Logging
include Api::ConnectionExt::ErrorHandling
include Api::ConnectionExt::SsoidRefreshing
include Api::ConnectionExt::Parsing
include Api::ConnectionExt::Formatting
def expire_provider
@_provider = nil
end
protected
def provider
......@@ -20,7 +25,7 @@ module BetfairApiNgRails
end
def request_ssoid
@_ssoid ||= BetfairApiNgRails::Api::SessionManager.new_ssoid
BetfairApiNgRails::Api::SessionManager.new_ssoid
end
def hashing(params)
......
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"].to_i == -32099
end
def try_request(method, params)
expire_provider
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,15 @@ describe BetfairApiNgRails::Api::Connection do
end
describe "#expire_provider" do
it "resets provider and ssoid" do
connection.expire_provider
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