shipcloud 0.10.0 → 0.12.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +62 -0
  3. data/.rubocop.yml +310 -313
  4. data/CHANGELOG.md +32 -0
  5. data/Gemfile +2 -1
  6. data/README.md +3 -1
  7. data/Rakefile +5 -4
  8. data/bin/setup +7 -0
  9. data/lib/shipcloud/address.rb +3 -1
  10. data/lib/shipcloud/base.rb +5 -5
  11. data/lib/shipcloud/carrier.rb +2 -0
  12. data/lib/shipcloud/operations/all.rb +2 -0
  13. data/lib/shipcloud/operations/create.rb +3 -1
  14. data/lib/shipcloud/operations/delete.rb +2 -0
  15. data/lib/shipcloud/operations/find.rb +3 -1
  16. data/lib/shipcloud/operations/update.rb +19 -13
  17. data/lib/shipcloud/order.rb +15 -0
  18. data/lib/shipcloud/pickup_request.rb +2 -0
  19. data/lib/shipcloud/request/base.rb +2 -0
  20. data/lib/shipcloud/request/connection.rb +11 -3
  21. data/lib/shipcloud/request/info.rb +6 -5
  22. data/lib/shipcloud/shipcloud_error.rb +7 -0
  23. data/lib/shipcloud/shipment.rb +5 -2
  24. data/lib/shipcloud/shipment_quote.rb +2 -0
  25. data/lib/shipcloud/tracker.rb +1 -0
  26. data/lib/shipcloud/version.rb +3 -1
  27. data/lib/shipcloud/webhook.rb +2 -0
  28. data/lib/shipcloud.rb +1 -0
  29. data/shipcloud.gemspec +7 -6
  30. data/spec/shipcloud/address_spec.rb +66 -40
  31. data/spec/shipcloud/carrier_spec.rb +53 -52
  32. data/spec/shipcloud/order_spec.rb +188 -0
  33. data/spec/shipcloud/pickup_request_spec.rb +14 -13
  34. data/spec/shipcloud/request/base_spec.rb +3 -2
  35. data/spec/shipcloud/request/connection_spec.rb +1 -0
  36. data/spec/shipcloud/shipcloud_error_spec.rb +8 -7
  37. data/spec/shipcloud/shipment_quote_spec.rb +5 -4
  38. data/spec/shipcloud/shipment_spec.rb +146 -62
  39. data/spec/shipcloud/webhooks_spec.rb +5 -4
  40. data/spec/shipcloud_spec.rb +5 -2
  41. data/spec/spec_helper.rb +3 -2
  42. metadata +25 -24
  43. data/.hound.yml +0 -12
  44. data/.travis.yml +0 -27
  45. data/install-cc-test-reporter.sh +0 -4
@@ -1,35 +1,36 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
2
3
 
3
4
  describe Shipcloud::Carrier do
4
- describe '#initialize' do
5
- it 'initializes all attributes correctly' do
5
+ describe "#initialize" do
6
+ it "initializes all attributes correctly" do
6
7
  valid_attributes = {
7
- name: 'bogus',
8
- display_name: 'Bogus Carrier',
9
- services: %w(
10
- standard,
11
- returns,
12
- one_day,
13
- one_day_early
14
- )
8
+ name: "bogus",
9
+ display_name: "Bogus Carrier",
10
+ services: [
11
+ "standard",
12
+ "returns",
13
+ "one_day",
14
+ "one_day_early",
15
+ ],
15
16
  }
16
17
  carrier = Shipcloud::Carrier.new(valid_attributes)
17
18
 
18
- expect(carrier.name).to eq 'bogus'
19
- expect(carrier.display_name).to eq 'Bogus Carrier'
20
- expect(carrier.services).to eq %w(standard, returns, one_day, one_day_early)
19
+ expect(carrier.name).to eq "bogus"
20
+ expect(carrier.display_name).to eq "Bogus Carrier"
21
+ expect(carrier.services).to eq ["standard", "returns", "one_day", "one_day_early"]
21
22
  end
22
23
  end
23
24
 
24
- describe '.all' do
25
- it 'makes a new Get request using the correct API endpoint' do
25
+ describe ".all" do
26
+ it "makes a new Get request using the correct API endpoint" do
26
27
  expect(Shipcloud).to receive(:request).
27
28
  with(:get, "carriers", {}, api_key: nil, affiliate_id: nil).and_return([])
28
29
 
29
30
  Shipcloud::Carrier.all
30
31
  end
31
32
 
32
- it 'returns a list of Carrier objects' do
33
+ it "returns a list of Carrier objects" do
33
34
  stub_carriers_request
34
35
 
35
36
  carriers = Shipcloud::Carrier.all
@@ -39,31 +40,31 @@ describe Shipcloud::Carrier do
39
40
  end
40
41
  end
41
42
 
42
- it 'initializes the Carrier objects correctly' do
43
+ it "initializes the Carrier objects correctly" do
43
44
  stub_carriers_request
44
45
  allow(Shipcloud::Carrier).to receive(:new)
45
46
 
46
47
  Shipcloud::Carrier.all
47
48
 
48
- expect(Shipcloud::Carrier).to have_received(:new)
49
- .with(
50
- 'name' => 'carrier_1',
51
- 'display_name' => 'Carrier 1',
52
- 'services' => %w(
53
- standard,
54
- returns,
55
- one_day,
56
- one_day_early
57
- )
49
+ expect(Shipcloud::Carrier).to have_received(:new).
50
+ with(
51
+ "name" => "carrier_1",
52
+ "display_name" => "Carrier 1",
53
+ "services" => [
54
+ "standard",
55
+ "returns",
56
+ "one_day",
57
+ "one_day_early",
58
+ ],
58
59
  )
59
- expect(Shipcloud::Carrier).to have_received(:new)
60
- .with(
61
- 'name' => 'carrier_2',
62
- 'display_name' => 'Carrier 2',
63
- 'services' => %w(
64
- standard,
65
- returns
66
- )
60
+ expect(Shipcloud::Carrier).to have_received(:new).
61
+ with(
62
+ "name" => "carrier_2",
63
+ "display_name" => "Carrier 2",
64
+ "services" => [
65
+ "standard",
66
+ "returns",
67
+ ],
67
68
  )
68
69
  end
69
70
 
@@ -81,24 +82,24 @@ describe Shipcloud::Carrier do
81
82
  and_return(
82
83
  [
83
84
  {
84
- 'name' => 'carrier_1',
85
- 'display_name' => 'Carrier 1',
86
- 'services' => %w(
87
- standard,
88
- returns,
89
- one_day,
90
- one_day_early
91
- )
85
+ "name" => "carrier_1",
86
+ "display_name" => "Carrier 1",
87
+ "services" => [
88
+ "standard",
89
+ "returns",
90
+ "one_day",
91
+ "one_day_early",
92
+ ],
92
93
  },
93
94
  {
94
- 'name' => 'carrier_2',
95
- 'display_name' => 'Carrier 2',
96
- 'services' => %w(
97
- standard,
98
- returns
99
- )
100
- }
101
- ]
95
+ "name" => "carrier_2",
96
+ "display_name" => "Carrier 2",
97
+ "services" => [
98
+ "standard",
99
+ "returns",
100
+ ],
101
+ },
102
+ ],
102
103
  )
103
104
  end
104
105
  end
@@ -0,0 +1,188 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe Shipcloud::Order do
5
+ describe "#initialize" do
6
+ it "initializes all attributes correctly" do
7
+ valid_attributes = {
8
+ external_order_id: "external_order_id",
9
+ external_customer_id: "external_customer_id",
10
+ refundable_until: "refundable_until",
11
+ total_weight: 12.34,
12
+ refund_deduction_amount: 4.32,
13
+ delivery_address: {
14
+ id: "adress_id",
15
+ },
16
+ order_line_items: [
17
+ {
18
+ id: "order_line_item_id",
19
+ },
20
+ ],
21
+ }
22
+ order = Shipcloud::Order.new(valid_attributes)
23
+
24
+ expect(order.external_order_id).to eq "external_order_id"
25
+ expect(order.external_customer_id).to eq "external_customer_id"
26
+ expect(order.refundable_until).to eq "refundable_until"
27
+ expect(order.total_weight).to eq 12.34
28
+ expect(order.refund_deduction_amount).to eq 4.32
29
+ expect(order.delivery_address).to eq(id: "adress_id")
30
+ expect(order.order_line_items).to eq [
31
+ { id: "order_line_item_id" },
32
+ ]
33
+ end
34
+ end
35
+
36
+ describe ".all" do
37
+ it "executes a GET request to the 'orders' API endpoint" do
38
+ expect(Shipcloud).to receive(:request).
39
+ with(:get, "orders", {}, api_key: nil, affiliate_id: nil).
40
+ and_return([])
41
+
42
+ Shipcloud::Order.all
43
+ end
44
+
45
+ it "returns a list of Order objects" do
46
+ stub_orders_request
47
+
48
+ orders = Shipcloud::Order.all
49
+
50
+ orders.each do |order|
51
+ expect(order).to be_a Shipcloud::Order
52
+ end
53
+ end
54
+
55
+ it "returns a filtered list of order objects when using filter parameters" do
56
+ filter = {
57
+ "external_customer_id" => "external_customer_id",
58
+ "external_order_id" => "external_order_id",
59
+ }
60
+
61
+ expect(Shipcloud).to receive(:request).
62
+ with(:get, "orders", filter, api_key: nil, affiliate_id: nil).
63
+ and_return(orders_array)
64
+
65
+ Shipcloud::Order.all(filter, api_key: nil)
66
+ end
67
+
68
+ it "uses the affiliate ID provided for the request" do
69
+ expect(Shipcloud).to receive(:request).
70
+ with(:get, "orders", {}, api_key: nil, affiliate_id: "affiliate_id").
71
+ and_return([])
72
+
73
+ Shipcloud::Order.all(affiliate_id: "affiliate_id")
74
+ end
75
+ end
76
+
77
+ describe ".find" do
78
+ it "executes a GET request to the 'orders/:id' API endpoint" do
79
+ expect(Shipcloud).to receive(:request).
80
+ with(:get, "orders/order_id", {}, api_key: nil, affiliate_id: nil).
81
+ and_return("id" => "order_id")
82
+
83
+ Shipcloud::Order.find("order_id")
84
+ end
85
+ end
86
+
87
+ describe ".create" do
88
+ it "executes a POST request to the 'orders' API endpoint" do
89
+ expect(Shipcloud).to receive(:request).
90
+ with(:post, "orders", valid_attributes, api_key: nil, affiliate_id: nil).
91
+ and_return("data" => {})
92
+
93
+ Shipcloud::Order.create(valid_attributes)
94
+ end
95
+
96
+ it "uses the affiliate ID provided for the request" do
97
+ expect(Shipcloud).to receive(:request).
98
+ with(
99
+ :post,
100
+ "orders",
101
+ valid_attributes,
102
+ api_key: nil,
103
+ affiliate_id: "affiliate_id",
104
+ ).and_return("data" => {})
105
+
106
+ Shipcloud::Order.create(valid_attributes, affiliate_id: "affiliate_id")
107
+ end
108
+ end
109
+
110
+ describe ".delete" do
111
+ it "executes a DELETE request to the 'orders/:id' API endpoint" do
112
+ expect(Shipcloud).to receive(:request).
113
+ with(:delete, "orders/123", {}, api_key: nil, affiliate_id: nil).
114
+ and_return(true)
115
+
116
+ Shipcloud::Order.delete("123")
117
+ end
118
+
119
+ it "does not raise an error" do
120
+ stub_request(:delete, "https://api.shipcloud.io/v1/orders/123").
121
+ to_return(status: 204, body: "")
122
+
123
+ expect { Shipcloud::Order.delete("123", api_key: "your-api-key") }.
124
+ to_not raise_error
125
+ end
126
+
127
+ it "uses the affiliate ID provided for the request" do
128
+ expect(Shipcloud).to receive(:request).with(
129
+ :delete, "orders/123", {}, api_key: nil, affiliate_id: "affiliate_id"
130
+ ).and_return(true)
131
+
132
+ Shipcloud::Order.delete("123", affiliate_id: "affiliate_id")
133
+ end
134
+ end
135
+
136
+ def stub_orders_request(params: {}, affiliate_id: nil)
137
+ allow(Shipcloud).to receive(:request).
138
+ with(:get, "orders", params, api_key: nil, affiliate_id: affiliate_id).
139
+ and_return(orders_array)
140
+ end
141
+
142
+ def orders_array
143
+ [
144
+ {
145
+ id: "order_id",
146
+ external_order_id: "external_order_id",
147
+ external_customer_id: "external_customer_id",
148
+ delivery_address: {
149
+ id: "adress_id",
150
+ },
151
+ order_line_items: [
152
+ {
153
+ id: "order_line_item_id",
154
+ },
155
+ ],
156
+ },
157
+ {
158
+ id: "order_id1",
159
+ external_order_id: "external_order_id1",
160
+ external_customer_id: "external_customer_id1",
161
+ delivery_address: {
162
+ id: "adress_id1",
163
+ },
164
+ order_line_items: [
165
+ {
166
+ id: "order_line_item_id1",
167
+ },
168
+ ],
169
+ },
170
+ ]
171
+ end
172
+
173
+ def valid_attributes
174
+ {
175
+ id: "order_id",
176
+ external_order_id: "external_order_id",
177
+ external_customer_id: "external_customer_id",
178
+ delivery_address: {
179
+ id: "adress_id",
180
+ },
181
+ order_line_items: [
182
+ {
183
+ id: "order_line_item_id",
184
+ },
185
+ ],
186
+ }
187
+ end
188
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe Shipcloud::PickupRequest do
@@ -5,18 +6,18 @@ describe Shipcloud::PickupRequest do
5
6
  carrier: "dpd",
6
7
  pickup_time: {
7
8
  earliest: "2015-09-15T09:00:00+02:00",
8
- latest: "2015-09-15T18:00:00+02:00"
9
+ latest: "2015-09-15T18:00:00+02:00",
9
10
  },
10
11
  shipments: [
11
- { id: "abc_123" }
12
- ]
12
+ { id: "abc_123" },
13
+ ],
13
14
  }
14
15
 
15
16
  valid_attributes_with_pickup_address = {
16
17
  carrier: "dpd",
17
18
  pickup_time: {
18
19
  earliest: "2015-09-15T09:00:00+02:00",
19
- latest: "2015-09-15T18:00:00+02:00"
20
+ latest: "2015-09-15T18:00:00+02:00",
20
21
  },
21
22
  pickup_address: {
22
23
  company: "Muster-Company",
@@ -27,11 +28,11 @@ describe Shipcloud::PickupRequest do
27
28
  zip_code: "54321",
28
29
  city: "Musterstadt",
29
30
  country: "DE",
30
- phone: "555-555"
31
+ phone: "555-555",
31
32
  },
32
33
  shipments: [
33
- { id: "abc_123" }
34
- ]
34
+ { id: "abc_123" },
35
+ ],
35
36
  }
36
37
 
37
38
  describe "#initialize" do
@@ -70,8 +71,8 @@ describe Shipcloud::PickupRequest do
70
71
  "carrier" => "dpd",
71
72
  "pickup_time" => {
72
73
  "earliest" => "2015-09-15T09:00:00+02:00",
73
- "latest" => "2015-09-15T18:00:00+02:00"
74
- }
74
+ "latest" => "2015-09-15T18:00:00+02:00",
75
+ },
75
76
  )
76
77
 
77
78
  pickup_request = Shipcloud::PickupRequest.create(valid_attributes)
@@ -88,7 +89,7 @@ describe Shipcloud::PickupRequest do
88
89
  "carrier" => "dpd",
89
90
  "pickup_time" => {
90
91
  "earliest" => "2015-09-15T09:00:00+02:00",
91
- "latest" => "2015-09-15T18:00:00+02:00"
92
+ "latest" => "2015-09-15T18:00:00+02:00",
92
93
  },
93
94
  "pickup_address" => {
94
95
  "id" => "522a7cb1-d6c8-418c-ac26-011127ab5bbe",
@@ -100,8 +101,8 @@ describe Shipcloud::PickupRequest do
100
101
  "zip_code" => "54321",
101
102
  "city" => "Musterstadt",
102
103
  "country" => "DE",
103
- "phone" => "555-555"
104
- }
104
+ "phone" => "555-555",
105
+ },
105
106
  )
106
107
 
107
108
  pickup_request = Shipcloud::PickupRequest.create(valid_attributes_with_pickup_address)
@@ -116,7 +117,7 @@ describe Shipcloud::PickupRequest do
116
117
  "zip_code" => "54321",
117
118
  "city" => "Musterstadt",
118
119
  "country" => "DE",
119
- "phone" => "555-555"
120
+ "phone" => "555-555",
120
121
  )
121
122
  end
122
123
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe Shipcloud::Request::Base do
@@ -5,9 +6,9 @@ describe Shipcloud::Request::Base do
5
6
  it "checks for an api key" do
6
7
  info = Shipcloud::Request::Info.new(:get, "shipments", nil, {}, "affiliate_id")
7
8
 
8
- expect{
9
+ expect do
9
10
  Shipcloud::Request::Base.new(info).perform
10
- }.to raise_error Shipcloud::AuthenticationError
11
+ end.to raise_error Shipcloud::AuthenticationError
11
12
  end
12
13
 
13
14
  it "performs an https request and returns a response hash" do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe Shipcloud::Request::Connection do
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe Shipcloud::ShipcloudError do
@@ -5,7 +6,7 @@ describe Shipcloud::ShipcloudError do
5
6
  context "with a response with status code 400" do
6
7
  it "returns a Shipcloud::InvalidRequestError" do
7
8
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 400))).to be_a(
8
- Shipcloud::InvalidRequestError
9
+ Shipcloud::InvalidRequestError,
9
10
  )
10
11
  end
11
12
  end
@@ -13,7 +14,7 @@ describe Shipcloud::ShipcloudError do
13
14
  context "with a response with status code 422" do
14
15
  it "returns a Shipcloud::InvalidRequestError" do
15
16
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 422))).to be_a(
16
- Shipcloud::InvalidRequestError
17
+ Shipcloud::InvalidRequestError,
17
18
  )
18
19
  end
19
20
  end
@@ -21,7 +22,7 @@ describe Shipcloud::ShipcloudError do
21
22
  context "with a response with status code 401" do
22
23
  it "returns a Shipcloud::AuthenticationError" do
23
24
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 401))).to be_a(
24
- Shipcloud::AuthenticationError
25
+ Shipcloud::AuthenticationError,
25
26
  )
26
27
  end
27
28
  end
@@ -29,7 +30,7 @@ describe Shipcloud::ShipcloudError do
29
30
  context "with a response with status code 402" do
30
31
  it "returns a Shipcloud::TooManyRequests" do
31
32
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 402))).to be_a(
32
- Shipcloud::TooManyRequests
33
+ Shipcloud::TooManyRequests,
33
34
  )
34
35
  end
35
36
  end
@@ -37,7 +38,7 @@ describe Shipcloud::ShipcloudError do
37
38
  context "with a response with status code 404" do
38
39
  it "returns a Shipcloud::NotFoundError" do
39
40
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 404))).to be_a(
40
- Shipcloud::NotFoundError
41
+ Shipcloud::NotFoundError,
41
42
  )
42
43
  end
43
44
  end
@@ -45,7 +46,7 @@ describe Shipcloud::ShipcloudError do
45
46
  context "with a response with a 4xx status code" do
46
47
  it "returns a Shipcloud::ClientError" do
47
48
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 400))).to be_a(
48
- Shipcloud::ClientError
49
+ Shipcloud::ClientError,
49
50
  )
50
51
  end
51
52
  end
@@ -53,7 +54,7 @@ describe Shipcloud::ShipcloudError do
53
54
  context "with a response with a 5xx status code" do
54
55
  it "returns a Shipcloud::ClientError" do
55
56
  expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 500))).to be_a(
56
- Shipcloud::ServerError
57
+ Shipcloud::ServerError,
57
58
  )
58
59
  end
59
60
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "spec_helper"
2
3
 
3
4
  describe Shipcloud::ShipmentQuote do
@@ -22,8 +23,8 @@ describe Shipcloud::ShipmentQuote do
22
23
  weight: 2.5,
23
24
  length: 40,
24
25
  width: 20,
25
- height: 20
26
- }
26
+ height: 20,
27
+ },
27
28
  }
28
29
 
29
30
  describe "#initialize" do
@@ -62,8 +63,8 @@ describe Shipcloud::ShipmentQuote do
62
63
  allow(Shipcloud).to receive(:request).
63
64
  and_return(
64
65
  "shipment_quote" => {
65
- "price" => 42.12
66
- }
66
+ "price" => 42.12,
67
+ },
67
68
  )
68
69
 
69
70
  shipment_quote = Shipcloud::ShipmentQuote.create(valid_attributes)