Class: Belpost::Models::ParcelBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/belpost/models/parcel_builder.rb

Instance Method Summary collapse

Constructor Details

#initializeParcelBuilder

Returns a new instance of ParcelBuilder.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/belpost/models/parcel_builder.rb', line 6

def initialize
  @data = {
    parcel: {
      type: "package",
      attachment_type: "products",
      measures: {},
      departure: {
        country: "BY",
        place: "post_office"
      },
      arrival: {
        place: "post_office"
      }
    },
    addons: {},
    sender: {
      info: {},
      location: {}
    },
    recipient: {
      info: {},
      location: {}
    }
  }
end

Instance Method Details

#add_service(service_name, value = true) ⇒ Object



77
78
79
80
# File 'lib/belpost/models/parcel_builder.rb', line 77

def add_service(service_name, value = true)
  @data[:addons][service_name.to_sym] = value
  self
end

#buildObject



189
190
191
192
# File 'lib/belpost/models/parcel_builder.rb', line 189

def build
  validate!
  @data
end

Отправитель



83
84
85
86
87
# File 'lib/belpost/models/parcel_builder.rb', line 83

def from_legal_person(organization_name)
  @data[:sender][:type] = "legal_person"
  @data[:sender][:info][:organization_name] = organization_name
  self
end

#from_sole_proprietor(organization_name) ⇒ Object



89
90
91
92
93
# File 'lib/belpost/models/parcel_builder.rb', line 89

def from_sole_proprietor(organization_name)
  @data[:sender][:type] = "sole_proprietor"
  @data[:sender][:info][:organization_name] = organization_name
  self
end

#to_country(country_code) ⇒ Object



55
56
57
58
# File 'lib/belpost/models/parcel_builder.rb', line 55

def to_country(country_code)
  @data[:parcel][:arrival][:country] = country_code
  self
end


140
141
142
143
144
145
146
# File 'lib/belpost/models/parcel_builder.rb', line 140

def to_legal_person(organization_name)
  @data[:recipient][:type] = "legal_person"
  @data[:recipient][:info] = {
    organization_name: organization_name
  }
  self
end

#to_natural_person(first_name:, last_name:, second_name: nil) ⇒ Object

Получатель



130
131
132
133
134
135
136
137
138
# File 'lib/belpost/models/parcel_builder.rb', line 130

def to_natural_person(first_name:, last_name:, second_name: nil)
  @data[:recipient][:type] = "natural_person"
  @data[:recipient][:info] = {
    first_name: first_name,
    last_name: last_name,
    second_name: second_name
  }.compact
  self
end

#with_attachment_type(attachment_type) ⇒ Object



38
39
40
41
# File 'lib/belpost/models/parcel_builder.rb', line 38

def with_attachment_type(attachment_type)
  @data[:parcel][:attachment_type] = attachment_type
  self
end

#with_cash_on_delivery(value, currency = "BYN") ⇒ Object



69
70
71
72
73
74
75
# File 'lib/belpost/models/parcel_builder.rb', line 69

def with_cash_on_delivery(value, currency = "BYN")
  @data[:addons][:cash_on_delivery] = {
    currency: currency,
    value: value.to_f
  }
  self
end

#with_customs_declaration(customs_declaration) ⇒ Object

Таможенная декларация



184
185
186
187
# File 'lib/belpost/models/parcel_builder.rb', line 184

def with_customs_declaration(customs_declaration)
  @data[:cp72] = customs_declaration.to_h
  self
end

#with_declared_value(value, currency = "BYN") ⇒ Object

Дополнительные сервисы



61
62
63
64
65
66
67
# File 'lib/belpost/models/parcel_builder.rb', line 61

def with_declared_value(value, currency = "BYN")
  @data[:addons][:declared_value] = {
    currency: currency,
    value: value.to_f
  }
  self
end

#with_dimensions(length, width, height) ⇒ Object



48
49
50
51
52
53
# File 'lib/belpost/models/parcel_builder.rb', line 48

def with_dimensions(length, width, height)
  @data[:parcel][:measures][:long] = length
  @data[:parcel][:measures][:width] = width
  @data[:parcel][:measures][:height] = height
  self
end

#with_foreign_recipient_location(postal_code:, locality:, address:) ⇒ Object



168
169
170
171
172
173
174
175
# File 'lib/belpost/models/parcel_builder.rb', line 168

def with_foreign_recipient_location(postal_code:, locality:, address:)
  @data[:recipient][:location] = {
    code: postal_code,
    locality: locality,
    address: address
  }
  self
end

#with_recipient_contact(email: nil, phone:) ⇒ Object



177
178
179
180
181
# File 'lib/belpost/models/parcel_builder.rb', line 177

def with_recipient_contact(email: nil, phone:)
  @data[:recipient][:email] = email
  @data[:recipient][:phone] = phone
  self
end

#with_recipient_location(postal_code:, region:, district:, locality_type:, locality_name:, road_type:, road_name:, building:, housing: nil, apartment: nil) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/belpost/models/parcel_builder.rb', line 148

def with_recipient_location(postal_code:, region:, district:, locality_type:, locality_name:, road_type:, road_name:, building:, housing: nil, apartment: nil)
  @data[:recipient][:location] = {
    code: postal_code,
    region: region,
    district: district,
    locality: {
      type: locality_type,
      name: locality_name
    },
    road: {
      type: road_type,
      name: road_name
    },
    building: building,
    housing: housing,
    apartment: apartment
  }.compact
  self
end

#with_sender_contact(email:, phone:) ⇒ Object



123
124
125
126
127
# File 'lib/belpost/models/parcel_builder.rb', line 123

def with_sender_contact(email:, phone:)
  @data[:sender][:email] = email
  @data[:sender][:phone] = phone
  self
end

#with_sender_details(taxpayer_number: nil, bank: nil, iban: nil, bic: nil) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/belpost/models/parcel_builder.rb', line 95

def with_sender_details(taxpayer_number: nil, bank: nil, iban: nil, bic: nil)
  @data[:sender][:info][:taxpayer_number] = taxpayer_number if taxpayer_number
  @data[:sender][:info][:bank] = bank if bank
  @data[:sender][:info][:IBAN] = iban if iban
  @data[:sender][:info][:BIC] = bic if bic
  self
end

#with_sender_location(postal_code:, region:, district:, locality_type:, locality_name:, road_type:, road_name:, building:, housing: nil, apartment: nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/belpost/models/parcel_builder.rb', line 103

def with_sender_location(postal_code:, region:, district:, locality_type:, locality_name:, road_type:, road_name:, building:, housing: nil, apartment: nil)
  @data[:sender][:location] = {
    code: postal_code,
    region: region,
    district: district,
    locality: {
      type: locality_type,
      name: locality_name
    },
    road: {
      type: road_type,
      name: road_name
    },
    building: building,
    housing: housing,
    apartment: apartment
  }.compact
  self
end

#with_type(type) ⇒ Object

Основные параметры посылки



33
34
35
36
# File 'lib/belpost/models/parcel_builder.rb', line 33

def with_type(type)
  @data[:parcel][:type] = type
  self
end

#with_weight(weight_in_grams) ⇒ Object



43
44
45
46
# File 'lib/belpost/models/parcel_builder.rb', line 43

def with_weight(weight_in_grams)
  @data[:parcel][:measures][:weight] = weight_in_grams
  self
end