Class: EasyPost::Services::CarrierAccount
- Defined in:
 - lib/easypost/services/carrier_account.rb
 
Constant Summary collapse
- CUSTOM_WORKFLOW_CARRIER_TYPES =
 %w[FedexAccount FedexSmartpostAccount].freeze
- UPS_OAUTH_CARRIER_ACCOUNT_TYPES =
 %w[UpsAccount UpsMailInnovationsAccount UpsSurepostAccount].freeze
- MODEL_CLASS =
 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
      34 35 36  | 
    
      # File 'lib/easypost/services/carrier_account.rb', line 34 def all(params = {}) get_all_helper('carrier_accounts', MODEL_CLASS, params) end  | 
  
#create(params = {}) ⇒ Object
Create a carrier account
      9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  | 
    
      # File 'lib/easypost/services/carrier_account.rb', line 9 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 UPS_OAUTH_CARRIER_ACCOUNT_TYPES.include?(carrier_account_type) 'ups_oauth_registrations' 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
      53 54 55 56 57 58  | 
    
      # File 'lib/easypost/services/carrier_account.rb', line 53 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
      27 28 29 30 31  | 
    
      # File 'lib/easypost/services/carrier_account.rb', line 27 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
      39 40 41 42 43 44 45 46 47 48 49 50  | 
    
      # File 'lib/easypost/services/carrier_account.rb', line 39 def update(id, params = {}) carrier_account = retrieve(id) wrapped_params = { select_top_layer_key(carrier_account[:type]).to_sym => params } update_url = if UPS_OAUTH_CARRIER_ACCOUNT_TYPES.include?(params[:type]) 'ups_oauth_registrations/' else 'carrier_accounts/' end response = @client.make_request(:put, "#{update_url}#{id}", wrapped_params) EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS) end  |