class Sendcloud::ParcelResource
Public Instance Methods
adjust_parcel(parcel_id)
click to toggle source
# File lib/sendcloud/parcel_resource.rb, line 25 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 = {})
click to toggle source
# 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) }.to_json, basic_auth: auth, headers: {'Content-Type' => 'application/json'} ) handle_response_error(response) response['parcel'] end
get_label_parcel(parcel_id)
click to toggle source
# File lib/sendcloud/parcel_resource.rb, line 46 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)
click to toggle source
# File lib/sendcloud/parcel_resource.rb, line 40 def show_parcel(parcel_id) response = self.class.get("/parcels/#{parcel_id}", basic_auth: auth) handle_response_error(response) response['parcel'] end
Private Instance Methods
handle_response_error(response)
click to toggle source
# File lib/sendcloud/parcel_resource.rb, line 54 def handle_response_error(response) if response['error'] raise ParcelResourceException.new(response['error']['message']) end end