provider.rb 841 Bytes
Newer Older
sergio1990's avatar
sergio1990 committed
1
require 'active_support/inflector'
sergio1990's avatar
sergio1990 committed
2 3 4 5
require 'betfair_api_ng_rails/api/concerns/errorable'

module BetfairApiNgRails
  module Api
sergio1990's avatar
sergio1990 committed
6
    class Provider
sergio1990's avatar
sergio1990 committed
7 8 9
      include Api::Concerns::Errorable
      include Api::Constants

sergio1990's avatar
sergio1990 committed
10
      attr_reader :ssoid
sergio1990's avatar
sergio1990 committed
11

sergio1990's avatar
sergio1990 committed
12 13
      def initialize(ssoid)
        @ssoid = ssoid
sergio1990's avatar
sergio1990 committed
14 15
      end

sergio1990's avatar
sergio1990 committed
16
      def fetch(method: "", params: {})
17
        raise "Not allowed method #{method.name}" unless method.allowed?
sergio1990's avatar
sergio1990 committed
18
        run_request for_method: method, params: params
sergio1990's avatar
sergio1990 committed
19 20
      end

21
      private
sergio1990's avatar
sergio1990 committed
22

sergio1990's avatar
sergio1990 committed
23
      def run_request(for_method: "", params: {})
24 25 26
        requester = http_requester(for_method.api_url)
        requester.set_api_req_body for_method, params
        requester.do_request
sergio1990's avatar
sergio1990 committed
27 28
      end

29 30
      def http_requester(api_url)
        @_http_requester ||= Api::Http::Factory.provider_requester api_url, ssoid
sergio1990's avatar
sergio1990 committed
31 32 33
      end
    end
  end
34
end