Class: EasyPost::Beta::EndShipper

Inherits:
Resource show all
Defined in:
lib/easypost/beta/end_shipper.rb

Overview

EndShipper objects are fully-qualified Address objects that require all parameters and get verified upon creation.

Instance Attribute Summary

Attributes inherited from EasyPostObject

#api_key, #name, #parent, #unsaved_values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

class_name, #delete, each, #refresh, url, #url

Methods inherited from EasyPostObject

#[], #[]=, #as_json, construct_from, #deconstruct_keys, #each, #id, #id=, #initialize, #inspect, #keys, #refresh_from, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from EasyPost::EasyPostObject

Class Method Details

.all(params = {}, api_key = nil) ⇒ Object

Retrieves a list of EndShipper objects.



18
19
20
21
# File 'lib/easypost/beta/end_shipper.rb', line 18

def self.all(params = {}, api_key = nil)
  response = EasyPost.make_request(:get, '/beta/end_shippers', api_key, params)
  EasyPost::Util.convert_to_easypost_object(response, api_key)
end

.create(params = {}, api_key = nil) ⇒ Object

Create an EndShipper object.



6
7
8
9
# File 'lib/easypost/beta/end_shipper.rb', line 6

def self.create(params = {}, api_key = nil)
  response = EasyPost.make_request(:post, '/beta/end_shippers', api_key, { address: params })
  EasyPost::Util.convert_to_easypost_object(response, api_key)
end

.retrieve(id, params = {}, api_key = nil) ⇒ Object

Retrieves an EndShipper object.



12
13
14
15
# File 'lib/easypost/beta/end_shipper.rb', line 12

def self.retrieve(id, params = {}, api_key = nil)
  response = EasyPost.make_request(:get, "/beta/end_shippers/#{id}", api_key, params)
  EasyPost::Util.convert_to_easypost_object(response, api_key)
end

Instance Method Details

#saveObject

Updates (saves) an EndShipper object. This requires all parameters to be set.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/easypost/beta/end_shipper.rb', line 24

def save
  if @unsaved_values.length.positive?
    values = {}
    @unsaved_values.each { |k| values[k] = @values[k] }

    wrapped_params = { address: values }

    response = EasyPost.make_request(:put, "/beta/end_shippers/#{id}", @api_key, wrapped_params)
    refresh_from(response, api_key)
  end
  self
end