postmen 0.1.0 → 1.0.0.pre.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -1
  3. data/lib/postmen/collection_proxy.rb +22 -0
  4. data/lib/postmen/connection.rb +44 -0
  5. data/lib/postmen/label.rb +15 -0
  6. data/lib/postmen/label_collection.rb +19 -0
  7. data/lib/postmen/manifest.rb +38 -0
  8. data/lib/postmen/manifest_collection.rb +39 -0
  9. data/lib/postmen/parcel.rb +12 -0
  10. data/lib/postmen/query/create_label_query.rb +6 -1
  11. data/lib/postmen/query/create_manifest_query.rb +23 -0
  12. data/lib/postmen/query/create_rate_query.rb +27 -0
  13. data/lib/postmen/query/create_shipper_account_query.rb +22 -0
  14. data/lib/postmen/query/label_query.rb +7 -1
  15. data/lib/postmen/query/manifest_query.rb +50 -0
  16. data/lib/postmen/query/rate_query.rb +41 -0
  17. data/lib/postmen/query/shipper_account_query.rb +29 -0
  18. data/lib/postmen/query/shipper_account_update_credentials_query.rb +20 -0
  19. data/lib/postmen/query/shipper_account_update_query.rb +30 -0
  20. data/lib/postmen/rate.rb +35 -0
  21. data/lib/postmen/rate_collection.rb +39 -0
  22. data/lib/postmen/rate_object.rb +19 -0
  23. data/lib/postmen/response.rb +20 -0
  24. data/lib/postmen/shipment.rb +18 -0
  25. data/lib/postmen/shipper_account.rb +68 -0
  26. data/lib/postmen/shipper_account_collection.rb +39 -0
  27. data/lib/postmen/types/address.rb +31 -0
  28. data/lib/postmen/types/aes.rb +11 -0
  29. data/lib/postmen/types/billing.rb +9 -0
  30. data/lib/postmen/types/brief_shipper_account.rb +12 -0
  31. data/lib/postmen/types/customs.rb +16 -0
  32. data/lib/postmen/types/customs_billing.rb +13 -0
  33. data/lib/postmen/types/detailed_charges.rb +10 -0
  34. data/lib/postmen/types/dimension.rb +12 -0
  35. data/lib/postmen/types/invoice.rb +9 -0
  36. data/lib/postmen/types/item.rb +24 -0
  37. data/lib/postmen/types/money.rb +10 -0
  38. data/lib/postmen/types/no_eei.rb +11 -0
  39. data/lib/postmen/types/passport.rb +21 -0
  40. data/lib/postmen/types/payment_method.rb +13 -0
  41. data/lib/postmen/types/reference.rb +9 -0
  42. data/lib/postmen/types/uuid.rb +10 -0
  43. data/lib/postmen/types/weight.rb +10 -0
  44. data/lib/postmen/types.rb +113 -8
  45. data/lib/postmen/version.rb +2 -1
  46. data/lib/postmen.rb +36 -1
  47. metadata +71 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0c166c6e9e1ba64fa64b643d122c137684d1405
4
- data.tar.gz: e0df26f3ce8ee0d14c662cdcc776d143c59abc7e
3
+ metadata.gz: ef3279747f60ddf021d56412eed1d833adb77f1c
4
+ data.tar.gz: e93b892733da84d2b7d3ae556c004baef30bc9f6
5
5
  SHA512:
6
- metadata.gz: bbe91de55327692811997e3402792f4a3e45520dccd0a91feb81f7d42ffc55a6e01e312570f251965b96194b6ec3297ac9feb55305af629fedfbba346de99c08
7
- data.tar.gz: de33322a0d03cfe24e5c96405503eb165c82273912b21032de64348601b4bd0bdd1f267d0cee7e245056e856f913caac61fee4e853d8c21bec6d7c7344780cb5
6
+ metadata.gz: 721df92fa7baf87693a78098a04cf5f1986f8829ff2f83a752899767fd2aa147ab252f16065b807408108e3872ae6e81c972c024c7231c06ea6c09ec4a02a625
7
+ data.tar.gz: 9436a466ca9044c098e05e3df986861bbe5f64dd257f944f486341cddc5dfbd791437bc0dee7ffea3df7e234f352fd96f38893dd0380dbd7ced2ab4f7f5867db
data/README.md CHANGED
@@ -4,6 +4,9 @@
4
4
  [![Code Climate](https://codeclimate.com/github/postmen/postmen-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/postmen/postmen-sdk-ruby)
5
5
  [![Gem Version](https://badge.fury.io/rb/postmen.svg)](https://badge.fury.io/rb/postmen)
6
6
  [![Dependency Status](https://gemnasium.com/badges/github.com/postmen/postmen-sdk-ruby.svg)](https://gemnasium.com/github.com/postmen/postmen-sdk-ruby)
7
+ [![Coverage Status](https://coveralls.io/repos/github/postmen/postmen-sdk-ruby/badge.svg?branch=master)](https://coveralls.io/github/postmen/postmen-sdk-ruby?branch=master)
8
+ [![Documentation status](https://inch-ci.org/github/postmen/postmen-sdk-ruby.svg?branch=master)](https://inch-ci.org/github/postmen/postmen-sdk-ruby)
9
+
7
10
 
8
11
  Ruby Gem for Postmen API.
9
12
 
@@ -20,7 +23,7 @@ This gem is on early stage of development - There are a lot of features that are
20
23
  1. Add the following line to your application's Gemfile
21
24
 
22
25
  ```
23
- gem "postmen", "~> 0.0.1"
26
+ gem "postmen", "~> 0.1.0"
24
27
  ```
25
28
 
26
29
  2. Run bundler
@@ -1,26 +1,46 @@
1
1
  class Postmen
2
+ # This is a mixin used by all collections.
3
+ # For an user perspective, every collection should
4
+ # behave like a simple array of models.
2
5
  module CollectionProxy
3
6
  include Enumerable
4
7
  extend Forwardable
5
8
 
9
+ # This module holds all class-level methods
6
10
  module ClassMethods
11
+ # Settings hash. Used in model/key methods.
7
12
  attr_reader :settings
8
13
 
14
+ # Sets (if argument is provided) or gets the model class name
15
+ #
16
+ # @return [Class] Model name, eg. `Label`
9
17
  def model(model = nil)
10
18
  return settings[:model] unless model
11
19
  settings[:model] = model
12
20
  end
13
21
 
22
+ # Sets (if argument is provides) or gets the key where the data is being
23
+ # searched in the API response.
24
+ #
25
+ # @see https://docs.postmen.com/#data API documentation
26
+ # @return [Symbol] key name
14
27
  def key(key = nil)
15
28
  return settings[:key] unless key
16
29
  settings[:key] = key
17
30
  end
18
31
 
32
+ # Wraps raw JSON response into an model
33
+ #
34
+ # @param response [Hash] parsed JSON response
35
+ # @return model an instance of
19
36
  def get(response)
20
37
  model.new(response[:data])
21
38
  end
22
39
  end
23
40
 
41
+ # Method called on base object when mixin gets included
42
+ #
43
+ # @private
24
44
  def self.included(base)
25
45
  base.extend ClassMethods
26
46
  base.instance_variable_set('@settings', {})
@@ -28,6 +48,8 @@ class Postmen
28
48
 
29
49
  def_delegators :@data, :[], :each
30
50
 
51
+ # Constructor
52
+ # @param response [Hash] HTTP response, parsed by the Response class
31
53
  def initialize(response)
32
54
  @data = response[:data][self.class.key].map { |element| self.class.model.new(element) }
33
55
  end
@@ -1,11 +1,21 @@
1
1
  class Postmen
2
+ # Connection class is used to perform any HTTP connections,
3
+ # it also does error handling.
2
4
  class Connection
5
+ # Maximum number of retries
3
6
  MAX_REQUESTS = 5
4
7
 
5
8
  def initialize
6
9
  @requests = 0
7
10
  end
8
11
 
12
+ # Performs a HTTP GET request.
13
+ #
14
+ # @param path [String]
15
+ # @param options [Hash]
16
+ # @example
17
+ # .get('/labels')
18
+ # .get('/labels', { params: { limit: 5 } })
9
19
  def get(path, options = {})
10
20
  Response.new(raw_get(path, options)).tap(&:parse_response!)
11
21
  rescue RateLimitExceeded
@@ -15,10 +25,38 @@ class Postmen
15
25
  retry
16
26
  end
17
27
 
28
+ # Performs a HTTP POST request.
29
+ #
30
+ # @param path [String]
31
+ # @param options [Hash]
32
+ # @example
33
+ # .post('/labels')
34
+ # .post('/labels', { json: { my: { sample: :data } } })
18
35
  def post(path, options = {})
19
36
  Response.new(raw_post(path, options))
20
37
  end
21
38
 
39
+ # Performs a HTTP PUT request.
40
+ #
41
+ # @param path [String]
42
+ # @param options [Hash]
43
+ # @example
44
+ # .put('/shipper-accounts/123/info')
45
+ # ..put('/shipper-accounts/123/info', { json: { my: { sample: :data } } })
46
+ def put(path, options = {})
47
+ Response.new(raw_put(path, options))
48
+ end
49
+ # Performs a HTTP DELETE request
50
+ #
51
+ # @param path [String]
52
+ # @example
53
+ # .delete('/shipper-accounts/11111')
54
+ def delete(path)
55
+ HTTP
56
+ .headers(headers)
57
+ .delete(get_full_url(path))
58
+ end
59
+
22
60
  private
23
61
 
24
62
  def raw_get(path, options)
@@ -33,6 +71,12 @@ class Postmen
33
71
  .post(get_full_url(path), options)
34
72
  end
35
73
 
74
+ def raw_put(path, options)
75
+ HTTP
76
+ .headers(headers)
77
+ .put(get_full_url(path), options)
78
+ end
79
+
36
80
  def get_full_url(path)
37
81
  [Postmen.endpoint, path].join
38
82
  end
data/lib/postmen/label.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Postmen
2
+ # Label object
3
+ #
4
+ # @see https://docs.postmen.com/api.html#labels API documentation
2
5
  class Label < Dry::Struct
3
6
  attribute :id, Types::UUID
4
7
  attribute :status, Types::String
@@ -6,14 +9,26 @@ class Postmen
6
9
  attribute :files, Types::Strict::Nil | Types::Array.member(Types::Hash)
7
10
  attribute :rate, Types::Strict::Nil | Types::Hash
8
11
 
12
+ # Returns all labels
13
+ #
14
+ # @see LabelCollection#all
15
+ # @return [LabelCollection] Collection of Labels
9
16
  def self.all(options = {})
10
17
  LabelCollection.all(options)
11
18
  end
12
19
 
20
+ # Fetches single label
21
+ #
22
+ # @see LabelCollection#find
23
+ # @return [Label]
13
24
  def self.find(id)
14
25
  LabelCollection.find(id)
15
26
  end
16
27
 
28
+ # Creates an instance of Label
29
+ #
30
+ # @see LabelCollection#create
31
+ # @return [Label]
17
32
  def self.create(params)
18
33
  LabelCollection.create(params)
19
34
  end
@@ -1,18 +1,37 @@
1
1
  class Postmen
2
+ # This class wraps the array of Label models
2
3
  class LabelCollection
3
4
  include CollectionProxy
4
5
 
5
6
  model Label
6
7
  key :labels
7
8
 
9
+ # Fetch all labels.
10
+ #
11
+ # @param options [Hash] Options for the query.
12
+ # @see https://docs.postmen.com/api.html#labels-list-all-labels API documentation
13
+ # @example
14
+ # .all # Returns all labels, default query.
15
+ # .all(status: :cancelled) # Returns only cancelled labels
8
16
  def self.all(options = {})
9
17
  new(Connection.new.get('/labels', LabelQuery.new(options).to_query).parsed_response)
10
18
  end
11
19
 
20
+ # Fetch single label
21
+ #
22
+ # @param id [UUID] Label UUID
23
+ # @see https://docs.postmen.com/api.html#labels-retrieve-a-label API documentation
24
+ # @return [Label]
25
+ # @raise ResourceNotFound if label with given id was not fount
12
26
  def self.find(id)
13
27
  get(Connection.new.get("/labels/#{id}").parsed_response)
14
28
  end
15
29
 
30
+ # Creates a label
31
+ #
32
+ # @param params [Hash] Label params
33
+ # @see https://docs.postmen.com/api.html#labels-create-a-label API documentation
34
+ # @return [Label]
16
35
  def self.create(params)
17
36
  Label.new(Connection.new.post('/labels', CreateLabelQuery.new(params).to_query).parsed_response[:data])
18
37
  end
@@ -0,0 +1,38 @@
1
+ class Postmen
2
+ # A manifest object object
3
+ #
4
+ # @see https://docs.postmen.com/api.html#a-manifest-object API Documentation
5
+ class Manifest < Dry::Struct
6
+ attribute :id, Types::UUID
7
+ attribute :status, Types::ManifestStatuses
8
+ attribute :shipper_account, Types::Reference
9
+ attribute :labels, Types::Array # TODO: implement manifesting label type
10
+ attribute :files, Types::Hash # TODO: Implement Files Type
11
+ attribute :created_at, Types::DateTime
12
+ attribute :updated_at, Types::DateTime
13
+
14
+ # Returns all manifests
15
+ #
16
+ # @see ManifestCollection#all
17
+ # @return [ManifestCollection] Collection of Manifests
18
+ def self.all(options = {})
19
+ ManifestCollection.all(options)
20
+ end
21
+
22
+ # Fetches single manifest
23
+ #
24
+ # @see ManifestCollection#find
25
+ # @return [Manifest]
26
+ def self.find(id)
27
+ ManifestCollection.find(id)
28
+ end
29
+
30
+ # Creates an instance of manifest
31
+ #
32
+ # @see ManifestCollection#create
33
+ # @return [Manifest]
34
+ def self.create(params)
35
+ ManifestCollection.create(params)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ class Postmen
2
+ # This class wraps the array of Manifest models
3
+ class ManifestCollection
4
+ include CollectionProxy
5
+
6
+ model Manifest
7
+ key :manifests
8
+
9
+ # Fetch all manifests.
10
+ #
11
+ # @param options [Hash] Options for the query.
12
+ # @see https://docs.postmen.com/api.html#manifests-list-all-manifests API Documentation
13
+ # @example
14
+ # .all # Returns all manisfests, default query.
15
+ # .all(status: :failed) # Returns only failed manifests
16
+ def self.all(options = {})
17
+ new(Connection.new.get('/manifests', ManifestQuery.new(options).to_query).parsed_response)
18
+ end
19
+
20
+ # Fetch single manifest
21
+ #
22
+ # @param id [UUID] Manifest UUID
23
+ # @see https://docs.postmen.com/api.html#manifests-retrieve-a-manifest API documentation
24
+ # @return [Manifest]
25
+ # @raise ResourceNotFound if Manifest with given id was not found
26
+ def self.find(id)
27
+ get(Connection.new.get("/manifests/#{id}").parsed_response)
28
+ end
29
+
30
+ # Creates a Manifest
31
+ #
32
+ # @param params [Hash] Manifest params
33
+ # @see https://docs.postmen.com/api.html#manifests-create-a-manifest API documentation
34
+ # @return [Rate]
35
+ def self.create(params)
36
+ Manifest.new(Connection.new.post('/manifests', CreateManifestQuery.new(params).to_query).parsed_response[:data])
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ class Postmen
2
+ # Parcel object
3
+ #
4
+ # @see https://docs.postmen.com/api.html#parcel API Documentation
5
+ class Parcel < Dry::Struct
6
+ attribute :description, Types::String
7
+ attribute :box_type, Types::String
8
+ attribute :weight, Types::Weight
9
+ attribute :dimension, Types::Dimension
10
+ attribute :items, Types::Array.member(Types::Item)
11
+ end
12
+ end
@@ -1,10 +1,13 @@
1
1
  class Postmen
2
+ # This class holds all the logic behind preparing query for
3
+ # creating a Label. It does type convertion, removes empty values and so on.
4
+ # @see LabelCollection#create Usage
2
5
  class CreateLabelQuery < Dry::Struct
3
6
  constructor_type :strict_with_defaults
4
7
 
5
8
  attribute :service_type, Types::String
6
9
  attribute :shipper_account, Types::Reference
7
- attribute :shipment, Types::Shipment
10
+ attribute :shipment, Shipment
8
11
  attribute :async, Types::Bool.optional.default(nil)
9
12
  attribute :return_shipment, Types::Bool.optional.default(nil)
10
13
  attribute :paper_size, Types::PaperSize.optional.default(nil)
@@ -15,6 +18,8 @@ class Postmen
15
18
  attribute :billing, Types::Billing.optional.default(nil)
16
19
  attribute :customs, Types::Customs.optional.default(nil)
17
20
 
21
+ # Converts query object to hash
22
+ # @return [Hash]
18
23
  def to_query
19
24
  {
20
25
  json: query
@@ -0,0 +1,23 @@
1
+ class Postmen
2
+ # This class holds all the logic behind preparing query for
3
+ # creating a Manifest. It does type convertion, removes empty values and so on.
4
+ class CreateManifestQuery < Dry::Struct
5
+ constructor_type :strict_with_defaults
6
+
7
+ attribute :shipper_account, Types::Reference
8
+
9
+ # Converts query object to hash
10
+ # @return [Hash]
11
+ def to_query
12
+ {
13
+ json: query
14
+ }
15
+ end
16
+
17
+ private
18
+
19
+ def query
20
+ to_hash.reject { |_k, v| v.nil? }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ class Postmen
2
+ # This class holds all the logic behind preparing query for
3
+ # creating a Rate. It does type convertion, removes empty values and so on.
4
+ class CreateRateQuery < Dry::Struct
5
+ constructor_type :strict_with_defaults
6
+
7
+ # async boolean enable async mode or not (set to false if not provided)
8
+ # is_document boolean If the shipment is document type. (set to false if not provided)
9
+
10
+ attribute :shipment, Shipment
11
+ attribute :shipper_accounts, Types::Array.member(Types::Reference)
12
+
13
+ # Converts query object to hash
14
+ # @return [Hash]
15
+ def to_query
16
+ {
17
+ json: query
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def query
24
+ to_hash.reject { |_k, v| v.nil? }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ class Postmen
2
+ # This class holds all the logic behind preparing query for
3
+ # creating a ShipperAccount. It does type convertion, removes empty values and so on.
4
+ # @see ShipperAccountCollection#create Usage
5
+ class CreateShipperAccountQuery < Dry::Struct
6
+ constructor_type :schema
7
+
8
+ attribute :slug, Types::String
9
+ attribute :description, Types::String
10
+ attribute :address, Types::Address
11
+ attribute :timezone, Types::Timezone
12
+ attribute :credentials, Types::Hash
13
+
14
+ # Converts query object to hash
15
+ # @return [Hash]
16
+ def to_query
17
+ {
18
+ params: query
19
+ }
20
+ end
21
+ end
22
+ end
@@ -1,17 +1,23 @@
1
1
  class Postmen
2
+ # This class holds all the logic behind querying for a single Label.
3
+ # @see LabelCollection.find Usage
2
4
  class LabelQuery < Dry::Struct
5
+ # Expected format for dates
6
+ # example value: 2017-02-08T10:17:04+01:00
3
7
  DATE_FORMAT = '%FT%T%:z'.freeze
4
8
 
5
9
  constructor_type :schema
6
10
 
7
11
  attribute :shipper_account_id, Types::String.optional
8
- attribute :status, Types::Strict::Nil | Types::Statuses
12
+ attribute :status, Types::Strict::Nil | Types::LabelStatuses
9
13
  attribute :limit, Types::String.optional
10
14
  attribute :created_at_min, Types::DateTime.maybe
11
15
  attribute :created_at_max, Types::DateTime.maybe
12
16
  attribute :tracking_numbers, Types::String.maybe
13
17
  attribute :next_token, Types::String.optional
14
18
 
19
+ # Converts query object to hash
20
+ # @return [Hash]
15
21
  def to_query
16
22
  {
17
23
  params: query
@@ -0,0 +1,50 @@
1
+ # shipper_account_id string Shipper account ID
2
+ # status string Manifest status Accepts: manifesting,manifested,failed.
3
+ # limit string Number of records per page
4
+ # created_at_min string Start date and time of the record created (default: 24hrs ago)
5
+ # created_at_max string End date and time of the record created (default: NOW())
6
+ # next_token string Next token
7
+
8
+ class Postmen
9
+ # This class holds all the logic behind querying for a single Manifest.
10
+ # @see ManifestCollection.find Usage
11
+ class ManifestQuery < Dry::Struct
12
+ # Expected format for dates
13
+ # example value: 2017-02-08T10:17:04+01:00
14
+ DATE_FORMAT = '%FT%T%:z'.freeze
15
+
16
+ constructor_type :schema
17
+
18
+ attribute :shipper_account_id, Types::String.optional
19
+ attribute :status, Types::Strict::Nil | Types::ManifestStatuses
20
+ attribute :limit, Types::String.optional
21
+ attribute :created_at_min, Types::DateTime.maybe
22
+ attribute :created_at_max, Types::DateTime.maybe
23
+ attribute :next_token, Types::String.optional
24
+
25
+ # Converts query object to hash
26
+ # @return [Hash]
27
+ def to_query
28
+ {
29
+ params: query
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def format_date(date)
36
+ date.fmap { |d| d.strftime(DATE_FORMAT) }.value
37
+ end
38
+
39
+ def query
40
+ {
41
+ shipper_account_id: shipper_account_id,
42
+ status: status,
43
+ limit: limit,
44
+ created_at_min: format_date(created_at_min),
45
+ created_at_max: format_date(created_at_max),
46
+ next_token: next_token
47
+ }.reject { |_k, v| v.nil? }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ class Postmen
2
+ # This class holds all the logic behind querying for a single Rate.
3
+ # @see RateCollection.find Usage
4
+ class RateQuery < Dry::Struct
5
+ # Expected format for dates
6
+ # example value: 2017-02-08T10:17:04+01:00
7
+ DATE_FORMAT = '%FT%T%:z'.freeze
8
+
9
+ constructor_type :schema
10
+
11
+ attribute :status, Types::Strict::Nil | Types::RateStatuses
12
+ attribute :limit, Types::String.optional
13
+ attribute :created_at_min, Types::DateTime.maybe
14
+ attribute :created_at_max, Types::DateTime.maybe
15
+ attribute :next_token, Types::String.optional
16
+
17
+ # Converts query object to hash
18
+ # @return [Hash]
19
+ def to_query
20
+ {
21
+ params: query
22
+ }
23
+ end
24
+
25
+ private
26
+
27
+ def format_date(date)
28
+ date.fmap { |d| d.strftime(DATE_FORMAT) }.value
29
+ end
30
+
31
+ def query
32
+ {
33
+ status: status,
34
+ limit: limit,
35
+ created_at_min: format_date(created_at_min),
36
+ created_at_max: format_date(created_at_max),
37
+ next_token: next_token
38
+ }.reject { |_k, v| v.nil? }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ class Postmen
2
+ # This class holds all the logic behind querying for a single ShipperAccount.
3
+ # @see ShipperAccountCollection.find Usage
4
+ class ShipperAccountQuery < Dry::Struct
5
+ constructor_type :schema
6
+
7
+ attribute :slug, Types::String
8
+ attribute :limit, Types::Int
9
+ attribute :next_token, Types::String
10
+
11
+ # Converts query object to hash
12
+ # @return [Hash]
13
+ def to_query
14
+ {
15
+ params: query
16
+ }
17
+ end
18
+
19
+ private
20
+
21
+ def query
22
+ {
23
+ slug: slug,
24
+ limit: limit,
25
+ next_token: next_token
26
+ }.reject { |_k, v| v.nil? }
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ class Postmen
2
+ # This class holds all the logic behind
3
+ # updating credentials for a ShipperAccount details
4
+ # @see ShipperAccount.update_credentials Usage
5
+ class ShipperAccountUpdateCredentialsQuery < Dry::Types::Hash
6
+ # Converts query object to hash
7
+ # @return [Hash]
8
+ def to_query
9
+ {
10
+ json: query
11
+ }
12
+ end
13
+
14
+ private
15
+
16
+ def query
17
+ primitive.reject { |_k, v| v.nil? }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ class Postmen
2
+ # This class holds all the logic behind updating a ShipperAccount details
3
+ # @see ShipperAccount.update Usage
4
+ class ShipperAccountUpdateQuery < Dry::Struct
5
+ constructor_type :schema
6
+
7
+ attribute :subject, ShipperAccount
8
+ attribute :description, Types::String
9
+ attribute :timezone, Types::Timezone
10
+ attribute :address, Types::Address
11
+
12
+ # Converts query object to hash
13
+ # @return [Hash]
14
+ def to_query
15
+ {
16
+ json: query
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def query
23
+ {
24
+ description: description || subject.description,
25
+ timezone: timezone || subject.timezone,
26
+ address: (address || subject.address).to_h
27
+ }.reject { |_k, v| v.nil? }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ class Postmen
2
+ # Rate object
3
+ # It encapsulates Rate record objects
4
+ # @see RateObject
5
+ # @see https://docs.postmen.com/api.html#rates API documentation
6
+ class Rate < Dry::Struct
7
+ attribute :id, Types::UUID
8
+ attribute :status, Types::RateStatuses
9
+ attribute :rates, Types::Array.member(RateObject)
10
+
11
+ # Returns all rates
12
+ #
13
+ # @see RateCollection#all
14
+ # @return [RateCollection] Collection of Rates
15
+ def self.all(options = {})
16
+ RateCollection.all(options)
17
+ end
18
+
19
+ # Fetches single rate
20
+ #
21
+ # @see RateCollection#find
22
+ # @return [Rate]
23
+ def self.find(id)
24
+ RateCollection.find(id)
25
+ end
26
+
27
+ # Creates an instance of Rate
28
+ #
29
+ # @see RateCollection#create
30
+ # @return [Rate]
31
+ def self.create(params)
32
+ RateCollection.create(params)
33
+ end
34
+ end
35
+ end