Class: EasyPost::Services::CarrierAccount
- Defined in:
- lib/easypost/services/carrier_account.rb
Constant Summary collapse
- CUSTOM_WORKFLOW_CARRIER_TYPES =
%w[FedexAccount FedexSmartpostAccount].freeze
- CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH =
%w[ AmazonShippingAccount UpsAccount UpsMailInnovationsAccount UpsSurepostAccount UspsShipAccount ].freeze
- MODEL_CLASS =
:nodoc:
EasyPost::Models::CarrierAccount
Instance Method Summary collapse
-
#all(params = {}) ⇒ Object
Retrieve all carrier accounts.
-
#create(params = {}) ⇒ Object
Create a carrier account.
-
#delete(id) ⇒ Object
Delete a carrier account.
-
#retrieve(id) ⇒ Object
Retrieve a carrier account.
-
#update(id, params = {}) ⇒ Object
Update a carrier account.
Methods inherited from Service
Constructor Details
This class inherits a constructor from EasyPost::Services::Service
Instance Method Details
#all(params = {}) ⇒ Object
Retrieve all carrier accounts
37 38 39 |
# File 'lib/easypost/services/carrier_account.rb', line 37 def all(params = {}) get_all_helper('carrier_accounts', MODEL_CLASS, params) end |
#create(params = {}) ⇒ Object
Create a carrier account
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/easypost/services/carrier_account.rb', line 12 def create(params = {}) carrier_account_type = params[:type] wrapped_params = { select_top_layer_key(carrier_account_type).to_sym => params } # For UPS and FedEx the endpoint is different create_url = if CUSTOM_WORKFLOW_CARRIER_TYPES.include?(carrier_account_type) 'carrier_accounts/register' elsif CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH.include?(carrier_account_type) 'carrier_accounts/register_oauth' else 'carrier_accounts' end response = @client.make_request(:post, create_url, wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#delete(id) ⇒ Object
Delete a carrier account
51 52 53 54 55 56 |
# File 'lib/easypost/services/carrier_account.rb', line 51 def delete(id) @client.make_request(:delete, "carrier_accounts/#{id}") # Return true if succeeds, an error will be thrown if it fails true end |
#retrieve(id) ⇒ Object
Retrieve a carrier account
30 31 32 33 34 |
# File 'lib/easypost/services/carrier_account.rb', line 30 def retrieve(id) response = @client.make_request(:get, "carrier_accounts/#{id}") EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |
#update(id, params = {}) ⇒ Object
Update a carrier account
42 43 44 45 46 47 48 |
# File 'lib/easypost/services/carrier_account.rb', line 42 def update(id, params = {}) carrier_account = retrieve(id) wrapped_params = { select_top_layer_key(carrier_account[:type]).to_sym => params } response = @client.make_request(:put, "carrier_accounts/#{id}", wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end |