Class: EasyPost::Client
- Inherits:
-
Object
- Object
- EasyPost::Client
- Defined in:
- lib/easypost/client.rb
Constant Summary collapse
- SERVICE_CLASSES =
[ EasyPost::Services::Address, EasyPost::Services::ApiKey, EasyPost::Services::Batch, EasyPost::Services::BetaRate, EasyPost::Services::BetaReferralCustomer, EasyPost::Services::Billing, EasyPost::Services::CarrierAccount, EasyPost::Services::CarrierMetadata, EasyPost::Services::CustomsInfo, EasyPost::Services::CustomsItem, EasyPost::Services::EndShipper, EasyPost::Services::Event, EasyPost::Services::Insurance, EasyPost::Services::Order, EasyPost::Services::Parcel, EasyPost::Services::Pickup, EasyPost::Services::Rate, EasyPost::Services::ReferralCustomer, EasyPost::Services::Refund, EasyPost::Services::Report, EasyPost::Services::ScanForm, EasyPost::Services::Shipment, EasyPost::Services::Tracker, EasyPost::Services::User, EasyPost::Services::Webhook, ].freeze
Instance Attribute Summary collapse
-
#api_base ⇒ Object
readonly
Returns the value of attribute api_base.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
Instance Method Summary collapse
-
#initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://api.easypost.com', custom_client_exec: nil) ⇒ EasyPost::Client
constructor
Initialize a new Client object.
-
#make_request(method, endpoint, cls = EasyPost::Models::EasyPostObject, body = nil, api_version = EasyPost::InternalUtilities::Constants::API_VERSION) ⇒ Hash
Make an HTTP request.
Constructor Details
#initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://api.easypost.com', custom_client_exec: nil) ⇒ EasyPost::Client
Initialize a new Client object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/easypost/client.rb', line 18 def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://api.easypost.com', custom_client_exec: nil) raise EasyPost::Errors::MissingParameterError.new('api_key') if api_key.nil? @api_key = api_key @api_base = api_base @api_version = 'v2' @read_timeout = read_timeout @open_timeout = open_timeout @lib_version = File.open(File.('../../VERSION', __dir__)).read.strip # Make an HTTP client once, reuse it for all requests made by this client # Configuration is immutable, so this is safe @http_client = EasyPost::HttpClient.new(api_base, http_config, custom_client_exec) end |
Instance Attribute Details
#api_base ⇒ Object (readonly)
Returns the value of attribute api_base.
9 10 11 |
# File 'lib/easypost/client.rb', line 9 def api_base @api_base end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
9 10 11 |
# File 'lib/easypost/client.rb', line 9 def open_timeout @open_timeout end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
9 10 11 |
# File 'lib/easypost/client.rb', line 9 def read_timeout @read_timeout end |
Instance Method Details
#make_request(method, endpoint, cls = EasyPost::Models::EasyPostObject, body = nil, api_version = EasyPost::InternalUtilities::Constants::API_VERSION) ⇒ Hash
Make an HTTP request
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/easypost/client.rb', line 78 def make_request( method, endpoint, cls = EasyPost::Models::EasyPostObject, body = nil, api_version = EasyPost::InternalUtilities::Constants::API_VERSION ) response = @http_client.request(method, endpoint, nil, body, api_version) potential_error = EasyPost::Errors::ApiError.handle_api_error(response) raise potential_error unless potential_error.nil? EasyPost::InternalUtilities::Json.convert_json_to_object(response.body, cls) end |