Class: SolidusEasypost::AddressBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_easypost/address_builder.rb

Class Method Summary collapse

Class Method Details

.from_address(address) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/solidus_easypost/address_builder.rb', line 6

def from_address(address)
  attributes = {
    street1: address.address1,
    street2: address.address2,
    city: address.city,
    zip: address.zipcode,
    phone: address.phone
  }

  attributes[:company] = address.company if address.respond_to?(:company)
  attributes[:name] = if address.respond_to?(:name)
                        address.name
                      elsif respond_to?(:full_name)
                        address.full_name
                      end
  attributes[:state] = address.state ? address.state.abbr : address.state_name
  attributes[:country] = address.country&.iso

  ::EasyPost::Address.create attributes
end

.from_stock_location(stock_location) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/solidus_easypost/address_builder.rb', line 27

def from_stock_location(stock_location)
  attributes = {
    street1: stock_location.address1,
    street2: stock_location.address2,
    city: stock_location.city,
    zip: stock_location.zipcode,
    phone: stock_location.phone,
    name: stock_location.name,
    company: stock_location.name
  }

  attributes[:state] = stock_location.state ? stock_location.state.abbr : stock_location.state_name
  attributes[:country] = stock_location.country&.iso

  ::EasyPost::Address.create attributes
end