Class: Postmen::ShipperAccount

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/postmen/shipper_account.rb

Overview

Shipper account object (brief information for rate and manifest responses)

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all(options = {}) ⇒ ShipperAccountCollection

Returns all ShipperAccounts

Returns:

See Also:



20
21
22
# File 'lib/postmen/shipper_account.rb', line 20

def self.all(options = {})
  ShipperAccountCollection.all(options)
end

.create(params) ⇒ ShipperAccount

Creates an instance of ShipperAccount



36
37
38
# File 'lib/postmen/shipper_account.rb', line 36

def self.create(params)
  ShipperAccountCollection.create(params)
end

.find(id) ⇒ ShipperAccount

Fetches single ShipperAccount



28
29
30
# File 'lib/postmen/shipper_account.rb', line 28

def self.find(id)
  ShipperAccountCollection.find(id)
end

Instance Method Details

#destroyObject

Deletes given ShipperAccount

See Also:



43
44
45
# File 'lib/postmen/shipper_account.rb', line 43

def destroy
  Connection.new.delete("/shipper-accounts/#{@id}")
end

#update(params = {}) ⇒ ShipperAccount, Hash

Update a shipper account information

Examples:

.update(description: "Your new description")
.update(address: {})

Returns:

  • (ShipperAccount)

    Updated ShipperAccount resource

  • (Hash)

    a Hash with detailed information about what went wrong

See Also:



101
102
103
104
105
# File 'lib/postmen/shipper_account.rb', line 101

def update(params = {})
  update!(params)
rescue RequestError => error
  error.meta
end

#update!(params = {}) ⇒ ShipperAccount

Update a shipper account information

Examples:

.update(description: "Your new description")
.update(address: {})

Returns:

Raises:

See Also:



82
83
84
85
86
87
88
89
90
91
# File 'lib/postmen/shipper_account.rb', line 82

def update!(params = {})
  response = Connection.new.put(
    "/shipper-accounts/#{@id}/info",
    ShipperAccountUpdateQuery.new(params.merge(subject: self)).to_query
  )

  raise RequestError, response unless response.success?

  ShipperAccount.new(response.data)
end

#update_credentials(params = {}) ⇒ ShipperAccount, Hash

Update a ShipperAccount credentials

Returns:

  • (ShipperAccount)

    Updated ShipperAccount resource

  • (Hash)

    a Hash with detailed information about what went wrong

See Also:



68
69
70
71
72
# File 'lib/postmen/shipper_account.rb', line 68

def update_credentials(params = {})
  update_credentials!(params)
rescue RequestError => error
  error.meta
end

#update_credentials!(params = {}) ⇒ ShipperAccount

Update a ShipperAccount credentials



52
53
54
55
56
57
58
59
60
61
# File 'lib/postmen/shipper_account.rb', line 52

def update_credentials!(params = {})
  response = Connection.new.put(
    "/shipper-accounts/#{@id}/credentials",
    ShipperAccountUpdateCredentialsQuery.new(params).to_query
  )

  raise RequestError, response unless response.success?

  ShipperAccount.new(response.data)
end