Class: Sendcloud::ParcelResource

Inherits:
Base
  • Object
show all
Defined in:
lib/sendcloud/parcel_resource.rb

Instance Attribute Summary

Attributes inherited from Base

#api_key, #api_secret

Instance Method Summary collapse

Methods inherited from Base

#auth, #initialize

Constructor Details

This class inherits a constructor from Sendcloud::Base

Instance Method Details

#adjust_parcel(parcel_id) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sendcloud/parcel_resource.rb', line 26

def adjust_parcel(parcel_id)
  response = self.class.put('/parcels',
                            body: {
                                parcel: {
                                    id: parcel_id,
                                    requestShipment: true
                                }
                            }.to_json,
                            basic_auth: auth,
                            headers: {'Content-Type' => 'application/json'}
  )
  handle_response_error(response)
  response['parcel']
end

#create_parcel(name, shipment_address, shipment = {id: 1, options: []}, method_params = {}) ⇒ Object


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

def create_parcel(name, shipment_address, shipment = {id: 1, options: []}, method_params = {})
  response = self.class.post('/parcels',
                             body: {
                                 parcel: {
                                     name: name,
                                     address: shipment_address.address,
                                     city: shipment_address.city,
                                     postal_code: shipment_address.postal_code,
                                     country: shipment_address.country,
                                     shipment: shipment,
                                     requestShipment: false
                                 }.merge(method_params).
                                   merge(telephone: '', email: '', data: [])
                             }.to_json,
                              basic_auth: auth,
                              headers: {'Content-Type' => 'application/json'}
  )
  handle_response_error(response)
  response['parcel']
end

#get_label_parcel(parcel_id) ⇒ Object


47
48
49
50
51
52
# File 'lib/sendcloud/parcel_resource.rb', line 47

def get_label_parcel(parcel_id)
  response = self.class.get("/labels/#{parcel_id}", basic_auth: auth,
                            headers: {'Content-Type' => 'application/json'})
  handle_response_error(response)
  response['label']
end

#show_parcel(parcel_id) ⇒ Object


41
42
43
44
45
# File 'lib/sendcloud/parcel_resource.rb', line 41

def show_parcel(parcel_id)
  response = self.class.get("/parcels/#{parcel_id}", basic_auth: auth)
  handle_response_error(response)
  response['parcel']
end