lib/recurly/client.rb in recurly-4.9.0 vs lib/recurly/client.rb in recurly-4.10.0

- old
+ new

@@ -1,19 +1,19 @@ require "logger" require "erb" require "net/https" require "base64" require "securerandom" +require "uri" require_relative "./schema/json_parser" require_relative "./schema/file_parser" module Recurly class Client require_relative "./client/operations" - BASE_HOST = "v3.recurly.com" - BASE_PORT = 443 + BASE_URL = "https://v3.recurly.com" CA_FILE = File.join(File.dirname(__FILE__), "../data/ca-certificates.crt") BINARY_TYPES = [ "application/pdf", ].freeze JSON_CONTENT_TYPE = "application/json" @@ -50,16 +50,19 @@ # # # you should create a new client to connect to another site # client = Recurly::Client.new(api_key: API_KEY2) # sub = client.get_subscription(subscription_id: 'uuid-abcd7890') # + # @param base_url [String] The base URL for the API. Defaults to "https://v3.recurly.com" + # @param ca_file [String] The CA bundle to use when connecting to the API. Defaults to "data/ca-certificates.crt" # @param api_key [String] The private API key # @param logger [Logger] A logger to use. Defaults to creating a new STDOUT logger with level WARN. - def initialize(api_key:, logger: nil) + def initialize(base_url: BASE_URL, ca_file: CA_FILE, api_key:, logger: nil) raise ArgumentError, "'api_key' must be set to a non-nil value" if api_key.nil? set_api_key(api_key) + set_connection_options(base_url, ca_file) if logger.nil? @logger = Logger.new(STDOUT).tap do |l| l.level = Logger::WARN end @@ -156,11 +159,11 @@ # @return [Recurly::ConnectionPool] attr_accessor :connection_pool end def run_request(request, options = {}) - self.class.connection_pool.with_connection do |http| + self.class.connection_pool.with_connection(uri: @base_uri, ca_file: @ca_file) do |http| set_http_options(http, options) retries = 0 begin @@ -334,9 +337,14 @@ path % options end def set_api_key(api_key) @api_key = api_key.to_s + end + + def set_connection_options(base_url, ca_file) + @base_uri = URI.parse(base_url) + @ca_file = ca_file end def build_url(path, options) path = scope_by_site(path, options) query_params = map_array_params(options.fetch(:params, {}))