smartsend-ruby 0.1.1 → 0.2.0
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.
- checksums.yaml +5 -5
 - data/Gemfile.lock +8 -2
 - data/README.md +53 -86
 - data/lib/smartsend/account.rb +4 -10
 - data/lib/smartsend/address.rb +15 -11
 - data/lib/smartsend/agent.rb +23 -7
 - data/lib/smartsend/client.rb +33 -26
 - data/lib/smartsend/parcel.rb +18 -17
 - data/lib/smartsend/parcel_item.rb +20 -7
 - data/lib/smartsend/receiver.rb +0 -3
 - data/lib/smartsend/request_error.rb +13 -0
 - data/lib/smartsend/sender.rb +0 -3
 - data/lib/smartsend/services.rb +18 -0
 - data/lib/smartsend/shipment.rb +56 -0
 - data/lib/smartsend/version.rb +1 -1
 - data/lib/smartsend.rb +11 -42
 - data/test/test_shipment.rb +199 -0
 - data/test/test_smartsend.rb +2 -6
 - metadata +7 -17
 - data/lib/smartsend/order.rb +0 -62
 - data/lib/smartsend/orders.rb +0 -43
 - data/lib/smartsend/service.rb +0 -17
 - data/test/test_addresses.rb +0 -80
 - data/test/test_client.rb +0 -9
 - data/test/test_orders.rb +0 -64
 - data/test/test_parcel_items.rb +0 -26
 - data/test/test_parcels.rb +0 -42
 - data/test/test_service.rb +0 -15
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5e338e7c9a7df4d21d802d3add16f25ff4f9215b01e251cac1f0cf0f6895325c
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 694b44590d3806a8b4be161adbfcfd40bf32489325cb09d913a7b1974fa4bec7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 0ae5e3227403d982d6a9f590af15cd654d93d0b10627ff301d3315ce13d666b19b8fd7123a6e4fd9751c3fe06df7d1ea95d9eb7a1d98617df8b078c025dd94c7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b4aa12989d2d520920a39e3b0c6d8b1a0485991f8e621dcfadf3cc06b0901cf057aa8d3c94b172733cfa4dbb4f2545cceb849ed6911e4b0d61126624d1401b02
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            PATH
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: .
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                smartsend-ruby (0. 
     | 
| 
      
 4 
     | 
    
         
            +
                smartsend-ruby (0.1.1)
         
     | 
| 
       5 
5 
     | 
    
         
             
                  http (~> 2.2)
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            GEM
         
     | 
| 
         @@ -9,6 +9,7 @@ GEM 
     | 
|
| 
       9 
9 
     | 
    
         
             
              specs:
         
     | 
| 
       10 
10 
     | 
    
         
             
                addressable (2.5.2)
         
     | 
| 
       11 
11 
     | 
    
         
             
                  public_suffix (>= 2.0.2, < 4.0)
         
     | 
| 
      
 12 
     | 
    
         
            +
                coderay (1.1.2)
         
     | 
| 
       12 
13 
     | 
    
         
             
                domain_name (0.5.20170404)
         
     | 
| 
       13 
14 
     | 
    
         
             
                  unf (>= 0.0.5, < 1.0.0)
         
     | 
| 
       14 
15 
     | 
    
         
             
                http (2.2.2)
         
     | 
| 
         @@ -20,6 +21,10 @@ GEM 
     | 
|
| 
       20 
21 
     | 
    
         
             
                  domain_name (~> 0.5)
         
     | 
| 
       21 
22 
     | 
    
         
             
                http-form_data (1.0.3)
         
     | 
| 
       22 
23 
     | 
    
         
             
                http_parser.rb (0.6.0)
         
     | 
| 
      
 24 
     | 
    
         
            +
                method_source (0.9.0)
         
     | 
| 
      
 25 
     | 
    
         
            +
                pry (0.11.3)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  coderay (~> 1.1.0)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  method_source (~> 0.9.0)
         
     | 
| 
       23 
28 
     | 
    
         
             
                public_suffix (3.0.1)
         
     | 
| 
       24 
29 
     | 
    
         
             
                unf (0.1.4)
         
     | 
| 
       25 
30 
     | 
    
         
             
                  unf_ext
         
     | 
| 
         @@ -29,7 +34,8 @@ PLATFORMS 
     | 
|
| 
       29 
34 
     | 
    
         
             
              ruby
         
     | 
| 
       30 
35 
     | 
    
         | 
| 
       31 
36 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
      
 37 
     | 
    
         
            +
              pry
         
     | 
| 
       32 
38 
     | 
    
         
             
              smartsend-ruby!
         
     | 
| 
       33 
39 
     | 
    
         | 
| 
       34 
40 
     | 
    
         
             
            BUNDLED WITH
         
     | 
| 
       35 
     | 
    
         
            -
               1. 
     | 
| 
      
 41 
     | 
    
         
            +
               1.16.1
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -15,67 +15,60 @@ gem install 'smartsend-ruby' 
     | 
|
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            ```ruby
         
     | 
| 
       17 
17 
     | 
    
         
             
            Smartsend.configure(
         
     | 
| 
       18 
     | 
    
         
            -
               
     | 
| 
       19 
     | 
    
         
            -
              email: 'smartsend-username',
         
     | 
| 
       20 
     | 
    
         
            -
              license: 'smartsend-license-key',
         
     | 
| 
       21 
     | 
    
         
            -
              cms_system: 'Ruby on Rails',
         
     | 
| 
       22 
     | 
    
         
            -
              cms_version: '5.0.0'
         
     | 
| 
      
 18 
     | 
    
         
            +
              api_token: 'smart-send-api-token'
         
     | 
| 
       23 
19 
     | 
    
         
             
            )
         
     | 
| 
       24 
20 
     | 
    
         
             
            ```
         
     | 
| 
       25 
21 
     | 
    
         | 
| 
       26 
22 
     | 
    
         
             
            ## Usage
         
     | 
| 
       27 
23 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
            ### Creating  
     | 
| 
      
 24 
     | 
    
         
            +
            ### Creating a shipment
         
     | 
| 
       29 
25 
     | 
    
         | 
| 
       30 
26 
     | 
    
         
             
            This creates a label.
         
     | 
| 
       31 
27 
     | 
    
         | 
| 
       32 
28 
     | 
    
         
             
            ```ruby
         
     | 
| 
       33 
     | 
    
         
            -
            # initalize a new  
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
               
     | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
       39 
     | 
    
         
            -
               
     | 
| 
       40 
     | 
    
         
            -
              total_price: 199.75,
         
     | 
| 
       41 
     | 
    
         
            -
              shipping_price: 49,
         
     | 
| 
       42 
     | 
    
         
            -
              currency: "DKK",
         
     | 
| 
       43 
     | 
    
         
            -
              sms_notification: "12345678",
         
     | 
| 
       44 
     | 
    
         
            -
              email_notification: "contact@smartsend.io"
         
     | 
| 
      
 29 
     | 
    
         
            +
            # initalize a new shipment
         
     | 
| 
      
 30 
     | 
    
         
            +
            shipment = Smartsend::Shipment.new(
         
     | 
| 
      
 31 
     | 
    
         
            +
              internal_id: "123123123", # your internal order id
         
     | 
| 
      
 32 
     | 
    
         
            +
              internal_reference: "AC12345789", # your order number
         
     | 
| 
      
 33 
     | 
    
         
            +
              shipping_carrier: "postnord", # postnord/gls/bring/dao
         
     | 
| 
      
 34 
     | 
    
         
            +
              shipping_method: "agent",
         
     | 
| 
      
 35 
     | 
    
         
            +
              shipping_date: "2018-02-28"
         
     | 
| 
       45 
36 
     | 
    
         
             
            )
         
     | 
| 
       46 
37 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
            # set the receiver of the  
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
               
     | 
| 
      
 38 
     | 
    
         
            +
            # set the receiver of the shipment
         
     | 
| 
      
 39 
     | 
    
         
            +
            shipment.receiver = Smartsend::Receiver.new(
         
     | 
| 
      
 40 
     | 
    
         
            +
              internal_id: "123456", # your internal customer id
         
     | 
| 
      
 41 
     | 
    
         
            +
              internal_reference: "123456",
         
     | 
| 
       50 
42 
     | 
    
         
             
              company: "Smart Send",
         
     | 
| 
       51 
     | 
    
         
            -
               
     | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
       53 
     | 
    
         
            -
               
     | 
| 
       54 
     | 
    
         
            -
               
     | 
| 
       55 
     | 
    
         
            -
               
     | 
| 
      
 43 
     | 
    
         
            +
              name_line1: "Henrik Hansen",
         
     | 
| 
      
 44 
     | 
    
         
            +
              name_line2: "C/O Vivian Hansen",
         
     | 
| 
      
 45 
     | 
    
         
            +
              address_line1: "Willemoesgade 42",
         
     | 
| 
      
 46 
     | 
    
         
            +
              address_line2: "3.th.",
         
     | 
| 
      
 47 
     | 
    
         
            +
              postal_code: "2100",
         
     | 
| 
       56 
48 
     | 
    
         
             
              city: "Copenhagen",
         
     | 
| 
       57 
49 
     | 
    
         
             
              country: "DK",
         
     | 
| 
       58 
     | 
    
         
            -
               
     | 
| 
       59 
     | 
    
         
            -
               
     | 
| 
      
 50 
     | 
    
         
            +
              sms: "12345678",
         
     | 
| 
      
 51 
     | 
    
         
            +
              email: "contact@smartsend.io"
         
     | 
| 
       60 
52 
     | 
    
         
             
            )
         
     | 
| 
       61 
53 
     | 
    
         | 
| 
       62 
     | 
    
         
            -
            # optionally set the sender of the  
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
               
     | 
| 
      
 54 
     | 
    
         
            +
            # optionally set the sender of the shipment
         
     | 
| 
      
 55 
     | 
    
         
            +
            shipment.sender = Smartsend::Sender.new(
         
     | 
| 
      
 56 
     | 
    
         
            +
              internal_id: "123456",
         
     | 
| 
      
 57 
     | 
    
         
            +
              internal_reference: "123456",
         
     | 
| 
       65 
58 
     | 
    
         
             
              company: "Smart Send",
         
     | 
| 
       66 
     | 
    
         
            -
               
     | 
| 
       67 
     | 
    
         
            -
               
     | 
| 
       68 
     | 
    
         
            -
               
     | 
| 
       69 
     | 
    
         
            -
               
     | 
| 
       70 
     | 
    
         
            -
               
     | 
| 
      
 59 
     | 
    
         
            +
              name_line1: "Henrik Hansen",
         
     | 
| 
      
 60 
     | 
    
         
            +
              name_line2: "C/O Vivian Hansen",
         
     | 
| 
      
 61 
     | 
    
         
            +
              address_line1: "Willemoesgade 42",
         
     | 
| 
      
 62 
     | 
    
         
            +
              address_line2: "3.th.",
         
     | 
| 
      
 63 
     | 
    
         
            +
              postal_code: "2100",
         
     | 
| 
       71 
64 
     | 
    
         
             
              city: "Copenhagen",
         
     | 
| 
       72 
65 
     | 
    
         
             
              country: "DK",
         
     | 
| 
       73 
     | 
    
         
            -
               
     | 
| 
       74 
     | 
    
         
            -
               
     | 
| 
      
 66 
     | 
    
         
            +
              sms: "12345678",
         
     | 
| 
      
 67 
     | 
    
         
            +
              email: "contact@smartsend.io"
         
     | 
| 
       75 
68 
     | 
    
         
             
            )
         
     | 
| 
       76 
69 
     | 
    
         | 
| 
       77 
70 
     | 
    
         
             
            # optionally ship to a droppoint by setting an agent
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
      
 71 
     | 
    
         
            +
            shipment.agent = Smartsend::Agent.new(
         
     | 
| 
       79 
72 
     | 
    
         
             
              id: "2103", # droppoint id
         
     | 
| 
       80 
73 
     | 
    
         
             
              type: "PDK", # droppoint provider
         
     | 
| 
       81 
74 
     | 
    
         
             
              company: "Smart Send",
         
     | 
| 
         @@ -90,94 +83,68 @@ order.agent = Smartsend::Agent.new( 
     | 
|
| 
       90 
83 
     | 
    
         
             
              mail: "contact@smartsend.io"
         
     | 
| 
       91 
84 
     | 
    
         
             
            )
         
     | 
| 
       92 
85 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
            # add one or more parcels/fulfillments to the  
     | 
| 
      
 86 
     | 
    
         
            +
            # add one or more parcels/fulfillments to the shipment
         
     | 
| 
       94 
87 
     | 
    
         
             
            parcel = Smartsend::Parcel.new(
         
     | 
| 
       95 
88 
     | 
    
         
             
              shipped_at: DateTime.now,
         
     | 
| 
       96 
     | 
    
         
            -
               
     | 
| 
      
 89 
     | 
    
         
            +
              internal_id: "123456789", # your internal parcel id
         
     | 
| 
      
 90 
     | 
    
         
            +
              internal_reference: "123456789",
         
     | 
| 
       97 
91 
     | 
    
         
             
              weight: 1.25,
         
     | 
| 
       98 
92 
     | 
    
         
             
              height: 21,
         
     | 
| 
       99 
93 
     | 
    
         
             
              width: 27,
         
     | 
| 
       100 
94 
     | 
    
         
             
              length: 35,
         
     | 
| 
       101 
     | 
    
         
            -
               
     | 
| 
       102 
     | 
    
         
            -
               
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                "Don't open this before your birthsday Brian",
         
     | 
| 
       105 
     | 
    
         
            -
                "We look forward to seeing you soon Brian"
         
     | 
| 
       106 
     | 
    
         
            -
              ]
         
     | 
| 
      
 95 
     | 
    
         
            +
              freetext1: "Brians birthday gift",
         
     | 
| 
      
 96 
     | 
    
         
            +
              freetext2: "Don't open this before your birthday Brian",
         
     | 
| 
      
 97 
     | 
    
         
            +
              freetext3: "We look forward to seeing you soon Brian",
         
     | 
| 
       107 
98 
     | 
    
         
             
            )
         
     | 
| 
       108 
99 
     | 
    
         | 
| 
       109 
100 
     | 
    
         
             
            # add items to the parcel
         
     | 
| 
       110 
101 
     | 
    
         
             
            parcel_item = Smartsend::ParcelItem.new(
         
     | 
| 
      
 102 
     | 
    
         
            +
              internal_id: "ABC123",
         
     | 
| 
      
 103 
     | 
    
         
            +
              internal_reference: "ABC123",
         
     | 
| 
       111 
104 
     | 
    
         
             
              sku: "ABC123",
         
     | 
| 
       112 
     | 
    
         
            -
               
     | 
| 
      
 105 
     | 
    
         
            +
              name: "Product name",
         
     | 
| 
       113 
106 
     | 
    
         
             
              quantity: 2,
         
     | 
| 
       114 
     | 
    
         
            -
              unit_weight: 1.25 
     | 
| 
       115 
     | 
    
         
            -
              unit_price: 144.5,
         
     | 
| 
       116 
     | 
    
         
            -
              currency: "DKK"
         
     | 
| 
      
 107 
     | 
    
         
            +
              unit_weight: 1.25
         
     | 
| 
       117 
108 
     | 
    
         
             
            )
         
     | 
| 
       118 
109 
     | 
    
         | 
| 
       119 
110 
     | 
    
         
             
            parcel.items << parcel_item
         
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
      
 111 
     | 
    
         
            +
            shipment.parcels << parcel
         
     | 
| 
       121 
112 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
            # send the  
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
      
 113 
     | 
    
         
            +
            # send the shipment to Smartsend.io
         
     | 
| 
      
 114 
     | 
    
         
            +
            shipment.save!
         
     | 
| 
       124 
115 
     | 
    
         
             
            ```
         
     | 
| 
       125 
116 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
            After saving, the  
     | 
| 
      
 117 
     | 
    
         
            +
            After saving, the shipment it is updated with a url for the label pdf and tracking codes for each parcel.
         
     | 
| 
       127 
118 
     | 
    
         | 
| 
       128 
119 
     | 
    
         
             
            ```ruby
         
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
            shipment.label_url
         
     | 
| 
       130 
121 
     | 
    
         
             
              => 'http://v70.api.smartsend.dk/...'
         
     | 
| 
       131 
122 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
      
 123 
     | 
    
         
            +
            shipment.parcels.first.tracking_code
         
     | 
| 
       133 
124 
     | 
    
         
             
              => '1234...'
         
     | 
| 
       134 
125 
     | 
    
         | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
      
 126 
     | 
    
         
            +
            shipment.parcels.first.tracking_url
         
     | 
| 
       136 
127 
     | 
    
         
             
              => 'https://tracking.postnord.com/...'
         
     | 
| 
       137 
128 
     | 
    
         
             
            ```
         
     | 
| 
       138 
129 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
            ### Creating orders in batch
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
            You can create up to 10 orders in batch.
         
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
            This updates all orders with a label_url and also gives you a labels_url with the combined labels
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
            ```ruby
         
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
            orders = Smartsend::Orders.new
         
     | 
| 
       148 
     | 
    
         
            -
            orders << Smartsend::Order.new(...)
         
     | 
| 
       149 
     | 
    
         
            -
            orders << Smartsend::Order.new(...)
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
            # send the orders to Smartsend.io
         
     | 
| 
       152 
     | 
    
         
            -
            orders.save_all!
         
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
            orders.labels_url
         
     | 
| 
       155 
     | 
    
         
            -
              => 'http://v70.api.smartsend.dk/...'
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
            orders.first.label_url
         
     | 
| 
       158 
     | 
    
         
            -
              => 'http://v70.api.smartsend.dk/...'
         
     | 
| 
       159 
     | 
    
         
            -
            ```
         
     | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
       161 
130 
     | 
    
         
             
            ### Using multiple accounts
         
     | 
| 
       162 
131 
     | 
    
         | 
| 
       163 
132 
     | 
    
         
             
            If your system requires multiple accounts you can pass an account instance when saving orders.
         
     | 
| 
       164 
133 
     | 
    
         | 
| 
       165 
134 
     | 
    
         
             
            ```ruby
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
      
 135 
     | 
    
         
            +
            shipment = Smartsend::Order.new(...)
         
     | 
| 
       167 
136 
     | 
    
         | 
| 
       168 
137 
     | 
    
         
             
            account = Smartsend::Account.new(
         
     | 
| 
       169 
     | 
    
         
            -
               
     | 
| 
       170 
     | 
    
         
            -
              license: 'smartsend-license-key'
         
     | 
| 
      
 138 
     | 
    
         
            +
              api_token: 'smartsend-api-token'
         
     | 
| 
       171 
139 
     | 
    
         
             
            )
         
     | 
| 
       172 
140 
     | 
    
         | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
      
 141 
     | 
    
         
            +
            shipment.save!(account: account)
         
     | 
| 
       174 
142 
     | 
    
         
             
            ```
         
     | 
| 
       175 
143 
     | 
    
         | 
| 
       176 
144 
     | 
    
         
             
            ### Validating account
         
     | 
| 
       177 
145 
     | 
    
         
             
            ```ruby
         
     | 
| 
       178 
146 
     | 
    
         
             
            account = Smartsend::Account.new(
         
     | 
| 
       179 
     | 
    
         
            -
               
     | 
| 
       180 
     | 
    
         
            -
              license: 'wrong-license-key'
         
     | 
| 
      
 147 
     | 
    
         
            +
              api_token: 'wrong-smartsend-api-token'
         
     | 
| 
       181 
148 
     | 
    
         
             
            )
         
     | 
| 
       182 
149 
     | 
    
         | 
| 
       183 
150 
     | 
    
         
             
            account.valid?
         
     | 
    
        data/lib/smartsend/account.rb
    CHANGED
    
    | 
         @@ -1,18 +1,12 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Smartsend::Account
         
     | 
| 
       2 
     | 
    
         
            -
              attr_accessor : 
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :api_token
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
              def initialize( 
     | 
| 
       5 
     | 
    
         
            -
                @ 
     | 
| 
       6 
     | 
    
         
            -
                @license = license
         
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize(api_token:)
         
     | 
| 
      
 5 
     | 
    
         
            +
                @api_token = api_token
         
     | 
| 
       7 
6 
     | 
    
         
             
              end
         
     | 
| 
       8 
7 
     | 
    
         | 
| 
       9 
8 
     | 
    
         
             
              def valid?
         
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                  response = Smartsend::Client.new(self).get_plain('verify_user')
         
     | 
| 
       12 
     | 
    
         
            -
                  response.code.to_s == '200'
         
     | 
| 
       13 
     | 
    
         
            -
                rescue Smartsend::AuthorizationError => e
         
     | 
| 
       14 
     | 
    
         
            -
                  false
         
     | 
| 
       15 
     | 
    
         
            -
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
                raise NotImplementedError
         
     | 
| 
       16 
10 
     | 
    
         
             
              end
         
     | 
| 
       17 
11 
     | 
    
         | 
| 
       18 
12 
     | 
    
         
             
            end
         
     | 
    
        data/lib/smartsend/address.rb
    CHANGED
    
    | 
         @@ -1,5 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Smartsend::Address
         
     | 
| 
       2 
     | 
    
         
            -
              attr_accessor : 
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :internal_id, :internal_reference, :company, :name_line1,
         
     | 
| 
      
 3 
     | 
    
         
            +
                            :name_line2, :address_line1, :address_line2, :postal_code,
         
     | 
| 
      
 4 
     | 
    
         
            +
                            :city, :country, :sms, :email
         
     | 
| 
       3 
5 
     | 
    
         | 
| 
       4 
6 
     | 
    
         
             
              def initialize(args={})
         
     | 
| 
       5 
7 
     | 
    
         
             
                args.each do |k, v|
         
     | 
| 
         @@ -9,16 +11,18 @@ class Smartsend::Address 
     | 
|
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
              def serialize
         
     | 
| 
       11 
13 
     | 
    
         
             
                {
         
     | 
| 
       12 
     | 
    
         
            -
                  : 
     | 
| 
       13 
     | 
    
         
            -
                  : 
     | 
| 
       14 
     | 
    
         
            -
                  : 
     | 
| 
       15 
     | 
    
         
            -
                  : 
     | 
| 
       16 
     | 
    
         
            -
                  : 
     | 
| 
       17 
     | 
    
         
            -
                  : 
     | 
| 
       18 
     | 
    
         
            -
                  : 
     | 
| 
       19 
     | 
    
         
            -
                  : 
     | 
| 
       20 
     | 
    
         
            -
                  : 
     | 
| 
       21 
     | 
    
         
            -
                  : 
     | 
| 
      
 14 
     | 
    
         
            +
                  :internal_id        => internal_id,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :internal_reference => internal_reference,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  :company            => company,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :name_line1         => name_line1,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :name_line2         => name_line2,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :address_line1      => address_line1,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :address_line2      => address_line2,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  :postal_code        => postal_code,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :city               => city,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :country            => country,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :sms                => sms,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  :email              => email
         
     | 
| 
       22 
26 
     | 
    
         
             
                }
         
     | 
| 
       23 
27 
     | 
    
         
             
              end
         
     | 
| 
       24 
28 
     | 
    
         | 
    
        data/lib/smartsend/agent.rb
    CHANGED
    
    | 
         @@ -1,12 +1,28 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class Smartsend::Agent 
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            class Smartsend::Agent
         
     | 
| 
      
 2 
     | 
    
         
            +
             attr_accessor :internal_id, :internal_reference, :agent_no, :company,
         
     | 
| 
      
 3 
     | 
    
         
            +
                           :name_line1, :name_line2, :address_line1, :address_line2,
         
     | 
| 
      
 4 
     | 
    
         
            +
                           :postal_code, :city, :country
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def initialize(args={})
         
     | 
| 
      
 7 
     | 
    
         
            +
               args.each do |k, v|
         
     | 
| 
      
 8 
     | 
    
         
            +
                 instance_variable_set "@#{k}", v
         
     | 
| 
      
 9 
     | 
    
         
            +
               end
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
       3 
11 
     | 
    
         | 
| 
       4 
12 
     | 
    
         
             
              def serialize
         
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
       6 
     | 
    
         
            -
                   
     | 
| 
       7 
     | 
    
         
            -
                   
     | 
| 
       8 
     | 
    
         
            -
                   
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                {
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :internal_id        => internal_id,
         
     | 
| 
      
 15 
     | 
    
         
            +
                  :internal_reference => internal_reference,
         
     | 
| 
      
 16 
     | 
    
         
            +
                  :agent_no           => agent_no,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :company            => company,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :name_line1         => name_line1,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :name_line2         => name_line2,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :address_line1      => address_line1,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  :address_line2      => address_line2,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :postal_code        => postal_code,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :city               => city,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :country            => country,
         
     | 
| 
      
 25 
     | 
    
         
            +
                }
         
     | 
| 
       10 
26 
     | 
    
         
             
              end
         
     | 
| 
       11 
27 
     | 
    
         | 
| 
       12 
28 
     | 
    
         
             
            end
         
     | 
    
        data/lib/smartsend/client.rb
    CHANGED
    
    | 
         @@ -2,51 +2,55 @@ require 'http' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class Smartsend::Client
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
              BASE_URL = 'http://smartsend-prod.apigee.net/v7'.freeze
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
5 
     | 
    
         
             
              def initialize(account=nil)
         
     | 
| 
       8 
6 
     | 
    
         
             
                @account = account || Smartsend.account
         
     | 
| 
       9 
7 
     | 
    
         
             
              end
         
     | 
| 
       10 
8 
     | 
    
         | 
| 
       11 
9 
     | 
    
         
             
              def post(path, params)
         
     | 
| 
       12 
10 
     | 
    
         
             
                request do
         
     | 
| 
       13 
     | 
    
         
            -
                  http.post( 
     | 
| 
      
 11 
     | 
    
         
            +
                  http.post(url(path), json: params)
         
     | 
| 
       14 
12 
     | 
    
         
             
                end
         
     | 
| 
       15 
13 
     | 
    
         
             
              end
         
     | 
| 
       16 
14 
     | 
    
         | 
| 
       17 
15 
     | 
    
         
             
              def get(path)
         
     | 
| 
       18 
16 
     | 
    
         
             
                request do
         
     | 
| 
       19 
     | 
    
         
            -
                  http.get( 
     | 
| 
      
 17 
     | 
    
         
            +
                  http.get(url(path))
         
     | 
| 
       20 
18 
     | 
    
         
             
                end
         
     | 
| 
       21 
19 
     | 
    
         
             
              end
         
     | 
| 
       22 
20 
     | 
    
         | 
| 
       23 
21 
     | 
    
         
             
              def get_plain(path)
         
     | 
| 
       24 
     | 
    
         
            -
                http.get( 
     | 
| 
      
 22 
     | 
    
         
            +
                http.get(url(path))
         
     | 
| 
       25 
23 
     | 
    
         
             
              end
         
     | 
| 
       26 
24 
     | 
    
         | 
| 
       27 
25 
     | 
    
         
             
              def request
         
     | 
| 
       28 
26 
     | 
    
         
             
                response = yield
         
     | 
| 
       29 
27 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                 
     | 
| 
      
 28 
     | 
    
         
            +
                logger.debug(response)
         
     | 
| 
      
 29 
     | 
    
         
            +
                logger.debug(response.body.to_s)
         
     | 
| 
       31 
30 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
                case response.code 
     | 
| 
       33 
     | 
    
         
            -
                when  
     | 
| 
       34 
     | 
    
         
            -
                  Response.new(JSON.parse(response)).successful!
         
     | 
| 
       35 
     | 
    
         
            -
                when  
     | 
| 
      
 31 
     | 
    
         
            +
                case response.code
         
     | 
| 
      
 32 
     | 
    
         
            +
                when (200..299)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Response.new(JSON.parse(response)).successful!(response.code)
         
     | 
| 
      
 34 
     | 
    
         
            +
                when 401
         
     | 
| 
       36 
35 
     | 
    
         
             
                  raise Smartsend::AuthorizationError, 'Unable to authorize'
         
     | 
| 
      
 36 
     | 
    
         
            +
                when 404
         
     | 
| 
      
 37 
     | 
    
         
            +
                  raise Smartsend::NotFoundError, 'Resource not found'
         
     | 
| 
       37 
38 
     | 
    
         
             
                else
         
     | 
| 
       38 
     | 
    
         
            -
                  Response.new(response).failed!
         
     | 
| 
      
 39 
     | 
    
         
            +
                  Response.new(JSON.parse(response)).failed!(response.code)
         
     | 
| 
       39 
40 
     | 
    
         
             
                end
         
     | 
| 
       40 
41 
     | 
    
         
             
              end
         
     | 
| 
       41 
42 
     | 
    
         | 
| 
       42 
43 
     | 
    
         
             
              class Response < SimpleDelegator
         
     | 
| 
      
 44 
     | 
    
         
            +
                attr_reader :http_code
         
     | 
| 
       43 
45 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                def successful!
         
     | 
| 
      
 46 
     | 
    
         
            +
                def successful!(http_code)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @http_code = http_code
         
     | 
| 
       45 
48 
     | 
    
         
             
                  @success = true
         
     | 
| 
       46 
49 
     | 
    
         
             
                  self
         
     | 
| 
       47 
50 
     | 
    
         
             
                end
         
     | 
| 
       48 
51 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                def failed!
         
     | 
| 
      
 52 
     | 
    
         
            +
                def failed!(http_code)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @http_code = http_code
         
     | 
| 
       50 
54 
     | 
    
         
             
                  @success = false
         
     | 
| 
       51 
55 
     | 
    
         
             
                  self
         
     | 
| 
       52 
56 
     | 
    
         
             
                end
         
     | 
| 
         @@ -63,20 +67,23 @@ class Smartsend::Client 
     | 
|
| 
       63 
67 
     | 
    
         | 
| 
       64 
68 
     | 
    
         
             
              private
         
     | 
| 
       65 
69 
     | 
    
         | 
| 
      
 70 
     | 
    
         
            +
              BASE_URL = 'http://smartsend-test.apigee.net/api/v1'.freeze
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
              def url(path)
         
     | 
| 
      
 73 
     | 
    
         
            +
                "#{BASE_URL}/#{path}"
         
     | 
| 
      
 74 
     | 
    
         
            +
              end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
              def logger
         
     | 
| 
      
 77 
     | 
    
         
            +
                Logger.new($stdout)
         
     | 
| 
      
 78 
     | 
    
         
            +
              end
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
       66 
80 
     | 
    
         
             
              def http
         
     | 
| 
       67 
     | 
    
         
            -
                raise Smartsend::MissingConfigError, 'Missing  
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                 
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                  smartsendmail: @account.email,
         
     | 
| 
       74 
     | 
    
         
            -
                  smartsendlicence: @account.license,
         
     | 
| 
       75 
     | 
    
         
            -
                  cmssystem: Smartsend.cms_system,
         
     | 
| 
       76 
     | 
    
         
            -
                  cmsversion: Smartsend.cms_version,
         
     | 
| 
       77 
     | 
    
         
            -
                  appversion: Smartsend.app_version,
         
     | 
| 
       78 
     | 
    
         
            -
                  test: Smartsend.test?
         
     | 
| 
       79 
     | 
    
         
            -
                )
         
     | 
| 
      
 81 
     | 
    
         
            +
                raise Smartsend::MissingConfigError, 'Missing api_token' if @account.api_token.nil?
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
                HTTP.headers({
         
     | 
| 
      
 84 
     | 
    
         
            +
                  accept: 'application/json',
         
     | 
| 
      
 85 
     | 
    
         
            +
                  api_token: @account.api_token
         
     | 
| 
      
 86 
     | 
    
         
            +
                })
         
     | 
| 
       80 
87 
     | 
    
         
             
              end
         
     | 
| 
       81 
88 
     | 
    
         | 
| 
       82 
89 
     | 
    
         
             
            end
         
     | 
    
        data/lib/smartsend/parcel.rb
    CHANGED
    
    | 
         @@ -1,5 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Smartsend::Parcel
         
     | 
| 
       2 
     | 
    
         
            -
              attr_accessor : 
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :internal_id, :internal_reference, :weight, :height, :width,
         
     | 
| 
      
 3 
     | 
    
         
            +
                            :length, :freetext1, :freetext2, :freetext3,
         
     | 
| 
      
 4 
     | 
    
         
            +
                            :total_price_excluding_tax, :total_price_including_tax,
         
     | 
| 
      
 5 
     | 
    
         
            +
                            :total_tax_amount, :items
         
     | 
| 
       3 
6 
     | 
    
         | 
| 
       4 
7 
     | 
    
         
             
              def initialize(args={})
         
     | 
| 
       5 
8 
     | 
    
         
             
                args.each do |k, v|
         
     | 
| 
         @@ -10,23 +13,21 @@ class Smartsend::Parcel 
     | 
|
| 
       10 
13 
     | 
    
         
             
              end
         
     | 
| 
       11 
14 
     | 
    
         | 
| 
       12 
15 
     | 
    
         
             
              def serialize
         
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                  : 
     | 
| 
       15 
     | 
    
         
            -
                  : 
     | 
| 
       16 
     | 
    
         
            -
                  :weight 
     | 
| 
       17 
     | 
    
         
            -
                  :height 
     | 
| 
       18 
     | 
    
         
            -
                  :width 
     | 
| 
       19 
     | 
    
         
            -
                  :length 
     | 
| 
       20 
     | 
    
         
            -
                  : 
     | 
| 
       21 
     | 
    
         
            -
                  : 
     | 
| 
      
 16 
     | 
    
         
            +
                {
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :internal_id               => internal_id,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :internal_reference        => internal_reference,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :weight                    => weight,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :height                    => height,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  :width                     => width,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :length                    => length,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :freetext1                 => freetext1,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :freetext2                 => freetext2,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  :freetext3                 => freetext3,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  :total_price_excluding_tax => total_price_excluding_tax,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  :total_price_including_tax => total_price_including_tax,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  :total_tax_amount          => total_tax_amount,
         
     | 
| 
      
 29 
     | 
    
         
            +
                  :items                     => items.map(&:serialize)
         
     | 
| 
       22 
30 
     | 
    
         
             
                }
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                freetext_lines.to_a.each_with_index do |line, i|
         
     | 
| 
       25 
     | 
    
         
            -
                  params["freetext#{i.next}".to_sym] = line
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                params
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
31 
     | 
    
         
             
              end
         
     | 
| 
       31 
32 
     | 
    
         | 
| 
       32 
33 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,5 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Smartsend::ParcelItem
         
     | 
| 
       2 
     | 
    
         
            -
              attr_accessor : 
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :internal_id, :internal_reference, :sku, :name, :description,
         
     | 
| 
      
 3 
     | 
    
         
            +
                            :hs_code, :country_of_origin, :image_url, :unit_weight,
         
     | 
| 
      
 4 
     | 
    
         
            +
                            :unit_price_excluding_tax, :unit_price_including_tax, :quantity,
         
     | 
| 
      
 5 
     | 
    
         
            +
                            :total_price_excluding_tax, :total_price_including_tax,
         
     | 
| 
      
 6 
     | 
    
         
            +
                            :total_tax_amount
         
     | 
| 
       3 
7 
     | 
    
         | 
| 
       4 
8 
     | 
    
         
             
              def initialize(args={})
         
     | 
| 
       5 
9 
     | 
    
         
             
                args.each do |k, v|
         
     | 
| 
         @@ -9,12 +13,21 @@ class Smartsend::ParcelItem 
     | 
|
| 
       9 
13 
     | 
    
         | 
| 
       10 
14 
     | 
    
         
             
              def serialize
         
     | 
| 
       11 
15 
     | 
    
         
             
                {
         
     | 
| 
       12 
     | 
    
         
            -
                  : 
     | 
| 
       13 
     | 
    
         
            -
                  : 
     | 
| 
       14 
     | 
    
         
            -
                  : 
     | 
| 
       15 
     | 
    
         
            -
                  : 
     | 
| 
       16 
     | 
    
         
            -
                  : 
     | 
| 
       17 
     | 
    
         
            -
                  : 
     | 
| 
      
 16 
     | 
    
         
            +
                  :internal_id               => internal_id,
         
     | 
| 
      
 17 
     | 
    
         
            +
                  :internal_reference        => internal_reference,
         
     | 
| 
      
 18 
     | 
    
         
            +
                  :sku                       => sku,
         
     | 
| 
      
 19 
     | 
    
         
            +
                  :name                      => name,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  :description               => description,
         
     | 
| 
      
 21 
     | 
    
         
            +
                  :hs_code                   => hs_code,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :country_of_origin         => country_of_origin,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :image_url                 => image_url,
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :unit_weight               => unit_weight,
         
     | 
| 
      
 25 
     | 
    
         
            +
                  :unit_price_excluding_tax  => unit_price_excluding_tax,
         
     | 
| 
      
 26 
     | 
    
         
            +
                  :unit_price_including_tax  => unit_price_including_tax,
         
     | 
| 
      
 27 
     | 
    
         
            +
                  :quantity                  => quantity,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  :total_price_excluding_tax => total_price_excluding_tax,
         
     | 
| 
      
 29 
     | 
    
         
            +
                  :total_price_including_tax => total_price_including_tax,
         
     | 
| 
      
 30 
     | 
    
         
            +
                  :total_tax_amount          => total_tax_amount,
         
     | 
| 
       18 
31 
     | 
    
         
             
                }
         
     | 
| 
       19 
32 
     | 
    
         
             
              end
         
     | 
| 
       20 
33 
     | 
    
         | 
    
        data/lib/smartsend/receiver.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Smartsend::RequestError
         
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :links, :errors, :message, :code, :id
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              def self.build(response)
         
     | 
| 
      
 5 
     | 
    
         
            +
                self.new.tap do |error|
         
     | 
| 
      
 6 
     | 
    
         
            +
                  error.id = response['id']
         
     | 
| 
      
 7 
     | 
    
         
            +
                  error.code = response['code']
         
     | 
| 
      
 8 
     | 
    
         
            +
                  error.message = response['message']
         
     | 
| 
      
 9 
     | 
    
         
            +
                  error.links = response['links']
         
     | 
| 
      
 10 
     | 
    
         
            +
                  error.errors = response['errors']
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/smartsend/sender.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Smartsend::Services
         
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :email_notification, :sms_notification, :flex_delivery
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
              def initialize(args={})
         
     | 
| 
      
 5 
     | 
    
         
            +
                args.each do |k, v|
         
     | 
| 
      
 6 
     | 
    
         
            +
                  instance_variable_set "@#{k}", v
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def serialize
         
     | 
| 
      
 11 
     | 
    
         
            +
                {
         
     | 
| 
      
 12 
     | 
    
         
            +
                  :email_notification => email_notification,
         
     | 
| 
      
 13 
     | 
    
         
            +
                  :sms_notification   => sms_notification,
         
     | 
| 
      
 14 
     | 
    
         
            +
                  :flex_delivery      => flex_delivery
         
     | 
| 
      
 15 
     | 
    
         
            +
                }
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,56 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Smartsend::Shipment
         
     | 
| 
      
 2 
     | 
    
         
            +
              attr_accessor :internal_id, :internal_reference, :shipping_carrier,
         
     | 
| 
      
 3 
     | 
    
         
            +
                            :shipping_method, :shipping_date, :sender, :receiver, :agent,
         
     | 
| 
      
 4 
     | 
    
         
            +
                            :parcels, :services, :sub_total_price_excluding_tax,
         
     | 
| 
      
 5 
     | 
    
         
            +
                            :sub_total_price_including_tax, :shipping_price_excluding_tax,
         
     | 
| 
      
 6 
     | 
    
         
            +
                            :shipping_price_including_tax, :total_price_excluding_tax,
         
     | 
| 
      
 7 
     | 
    
         
            +
                            :total_price_including_tax, :total_tax_amount, :currency,
         
     | 
| 
      
 8 
     | 
    
         
            +
                            :success, :label_url, :error
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def initialize(args={})
         
     | 
| 
      
 11 
     | 
    
         
            +
                args.each do |k, v|
         
     | 
| 
      
 12 
     | 
    
         
            +
                  instance_variable_set "@#{k}", v
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                @parcels ||= []
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              def success?
         
     | 
| 
      
 19 
     | 
    
         
            +
                success
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              def save!(account: nil)
         
     | 
| 
      
 23 
     | 
    
         
            +
                response = Smartsend::Client.new(account).post('shipments/labels', self.serialize)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                if response.success?
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @success = true
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @label_url = response.dig('data', 'pdf', 'link')
         
     | 
| 
      
 28 
     | 
    
         
            +
                else
         
     | 
| 
      
 29 
     | 
    
         
            +
                  self.error = Smartsend::RequestError.build(response)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def serialize
         
     | 
| 
      
 34 
     | 
    
         
            +
                {
         
     | 
| 
      
 35 
     | 
    
         
            +
                  :internal_id                   => internal_id,
         
     | 
| 
      
 36 
     | 
    
         
            +
                  :internal_reference            => internal_reference,
         
     | 
| 
      
 37 
     | 
    
         
            +
                  :shipping_carrier              => shipping_carrier,
         
     | 
| 
      
 38 
     | 
    
         
            +
                  :shipping_method               => shipping_method,
         
     | 
| 
      
 39 
     | 
    
         
            +
                  :shipping_date                 => shipping_date,
         
     | 
| 
      
 40 
     | 
    
         
            +
                  :sender                        => sender&.serialize,
         
     | 
| 
      
 41 
     | 
    
         
            +
                  :receiver                      => receiver&.serialize,
         
     | 
| 
      
 42 
     | 
    
         
            +
                  :agent                         => agent&.serialize,
         
     | 
| 
      
 43 
     | 
    
         
            +
                  :parcels                       => parcels.map(&:serialize),
         
     | 
| 
      
 44 
     | 
    
         
            +
                  :services                      => services&.serialize,
         
     | 
| 
      
 45 
     | 
    
         
            +
                  :sub_total_price_excluding_tax => sub_total_price_excluding_tax,
         
     | 
| 
      
 46 
     | 
    
         
            +
                  :sub_total_price_including_tax => sub_total_price_including_tax,
         
     | 
| 
      
 47 
     | 
    
         
            +
                  :shipping_price_excluding_tax  => shipping_price_excluding_tax,
         
     | 
| 
      
 48 
     | 
    
         
            +
                  :shipping_price_including_tax  => shipping_price_including_tax,
         
     | 
| 
      
 49 
     | 
    
         
            +
                  :total_price_excluding_tax     => total_price_excluding_tax,
         
     | 
| 
      
 50 
     | 
    
         
            +
                  :total_price_including_tax     => total_price_including_tax,
         
     | 
| 
      
 51 
     | 
    
         
            +
                  :total_tax_amount              => total_tax_amount,
         
     | 
| 
      
 52 
     | 
    
         
            +
                  :currency                      => currency
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/smartsend/version.rb
    CHANGED