shipcloud 0.7.0 → 0.8.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.
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe Shipcloud::PickupRequest do
5
+ valid_attributes = {
6
+ carrier: "ups",
7
+ carrier_tracking_no: "723558934169",
8
+ }
9
+
10
+ describe "#initialize" do
11
+ it "initializes all attributes correctly" do
12
+ tracker = Shipcloud::Tracker.new(valid_attributes)
13
+
14
+ expect(tracker.carrier).to eq "ups"
15
+ expect(tracker.carrier_tracking_no).to eq "723558934169"
16
+ end
17
+ end
18
+
19
+ describe ".all" do
20
+ it "makes a new GET request using the correct API endpoint" do
21
+ expect(Shipcloud).to receive(:request).
22
+ with(:get, "trackers", {}, api_key: nil).
23
+ and_return("trackers" => [])
24
+
25
+ Shipcloud::Tracker.all
26
+ end
27
+
28
+ it "returns a list of Tracker objects" do
29
+ stub_trackers_requests
30
+
31
+ trackers = Shipcloud::Tracker.all
32
+
33
+ trackers.each do |tracker|
34
+ expect(tracker).to be_a Shipcloud::Tracker
35
+ end
36
+ end
37
+ end
38
+
39
+ describe ".create" do
40
+ it "makes a new POST request using the correct API endpoint" do
41
+ expect(Shipcloud).to receive(:request).
42
+ with(:post, "trackers", valid_attributes, api_key: nil).
43
+ and_return("data" => {})
44
+
45
+ Shipcloud::Tracker.create(valid_attributes)
46
+ end
47
+ end
48
+
49
+ describe ".find" do
50
+ it "makes a new GET request using the correct API endpoint to receive a specific tracker" do
51
+ expect(Shipcloud).to receive(:request).with(:get, "trackers/123", {}, api_key: nil).
52
+ and_return("id" => "123")
53
+
54
+ Shipcloud::Tracker.find("123")
55
+ end
56
+ end
57
+
58
+ def stub_trackers_requests
59
+ allow(Shipcloud).to receive(:request).
60
+ with(:get, "trackers", {}, api_key: nil).
61
+ and_return("trackers" => trackers_array)
62
+ end
63
+
64
+ def trackers_array
65
+ [
66
+ {
67
+ "id" => "4a6922e2-09ad-4724-807c-7b4e572d3c6b",
68
+ "carrier_tracking_no" => "723558934169",
69
+ "status" => "registered",
70
+ "created_at" => "2015-07-21T09:35:23+02:00",
71
+ "to" => {
72
+ "company" => nil,
73
+ "first_name" => "Hans",
74
+ "last_name" => "Meier",
75
+ "care_of" => nil,
76
+ "street" => "Semmelweg",
77
+ "street_no" => "1",
78
+ "zip_code" => "12345",
79
+ "city" => "Hamburg",
80
+ "state" => nil,
81
+ "country" => "DE",
82
+ },
83
+ "tracking_status_updated_at" => nil,
84
+ "last_polling_at" => nil,
85
+ "next_polling_at" => "2015-07-21T09:35:23+02:00",
86
+ "shipment_id" => "123456",
87
+ "carrier" => "ups",
88
+ "tracking_events" => [],
89
+ },
90
+ {
91
+ "id" => "7b4e572d3c6b-4a6922e2-09ad-4724-807c",
92
+ "carrier_tracking_no" => "723558934170",
93
+ "status" => "registered",
94
+ "created_at" => "2015-07-20T09:35:23+02:00",
95
+ "to" => {
96
+ "company" => nil,
97
+ "first_name" => "Rita",
98
+ "last_name" => "Rose",
99
+ "care_of" => nil,
100
+ "street" => "Geranienweg",
101
+ "street_no" => "2",
102
+ "zip_code" => "23456",
103
+ "city" => "Berlin",
104
+ "state" => nil,
105
+ "country" => "DE",
106
+ },
107
+ "tracking_status_updated_at" => nil,
108
+ "last_polling_at" => nil,
109
+ "next_polling_at" => "2015-07-21T09:35:23+02:00",
110
+ "shipment_id" => "654321",
111
+ "carrier" => "dpd",
112
+ "tracking_events" => [],
113
+ },
114
+ ]
115
+ end
116
+ end
@@ -52,6 +52,37 @@ describe Shipcloud::Webhook do
52
52
  end
53
53
  end
54
54
 
55
+ describe ".delete" do
56
+ it "makes a DELETE request using the correct API endpoint" do
57
+ expect(Shipcloud).to receive(:request).
58
+ with(:delete, "webhooks/123", {}, api_key: nil).
59
+ and_return(true)
60
+ Shipcloud::Webhook.delete("123")
61
+ end
62
+ end
63
+
64
+ describe ".deactivated" do
65
+ let(:id) { "123" }
66
+
67
+ subject { Shipcloud::Webhook.find(id).deactivated }
68
+
69
+ before do
70
+ expect(Shipcloud).to receive(:request).
71
+ with(:get, "webhooks/#{id}", {}, api_key: nil).
72
+ and_return("id" => id, "deactivated" => deactivated)
73
+ end
74
+
75
+ context "when the webhook is deactivated" do
76
+ let(:deactivated) { true }
77
+ it { is_expected.to be true }
78
+ end
79
+
80
+ context "when the webhook is not deactivated" do
81
+ let(:deactivated) { false }
82
+ it { is_expected.to be false }
83
+ end
84
+ end
85
+
55
86
  def stub_webhooks_request
56
87
  allow(Shipcloud).to receive(:request).
57
88
  with(:get, "webhooks", {}, api_key: nil).
@@ -99,5 +99,43 @@ describe Shipcloud do
99
99
  end
100
100
  expect(Shipcloud.configuration.debug).to be true
101
101
  end
102
+
103
+ it "defaults affiliate_id to nil" do
104
+ expect(Shipcloud.configuration.affiliate_id).to be_nil
105
+ end
106
+
107
+ it "sets and gets the affiliate_id" do
108
+ Shipcloud.configure do |config|
109
+ config.affiliate_id = "integration.my_rails_app.1234567"
110
+ end
111
+
112
+ expect(Shipcloud.configuration.affiliate_id).to eq "integration.my_rails_app.1234567"
113
+ end
114
+ end
115
+
116
+ describe ".api_headers" do
117
+ it "returns the correct api headers with default affiliate id" do
118
+ Shipcloud.configuration = nil # reset configuration
119
+
120
+ expect(Shipcloud.api_headers).to eq(
121
+ "Content-Type" => "application/json",
122
+ "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
123
+ "#{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}",
124
+ "Affiliate-ID" => "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}",
125
+ )
126
+ end
127
+
128
+ it "returns the correct api headers with affiliate id if configured" do
129
+ Shipcloud.configure do |config|
130
+ config.affiliate_id = "integration.my_rails_app.1234567"
131
+ end
132
+
133
+ expect(Shipcloud.api_headers).to eq(
134
+ "Content-Type" => "application/json",
135
+ "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
136
+ "#{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}",
137
+ "Affiliate-ID" => "integration.my_rails_app.1234567",
138
+ )
139
+ end
102
140
  end
103
141
  end
@@ -1,5 +1,5 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
1
+ require "simplecov"
2
+ SimpleCov.start
3
3
 
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sthollmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2017-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -132,7 +132,6 @@ files:
132
132
  - ".hound.yml"
133
133
  - ".rspec"
134
134
  - ".rubocop.yml"
135
- - ".ruby-style.yml"
136
135
  - ".travis.yml"
137
136
  - CHANGELOG.md
138
137
  - Gemfile
@@ -148,22 +147,27 @@ files:
148
147
  - lib/shipcloud/operations/delete.rb
149
148
  - lib/shipcloud/operations/find.rb
150
149
  - lib/shipcloud/operations/update.rb
150
+ - lib/shipcloud/pickup_request.rb
151
151
  - lib/shipcloud/request/base.rb
152
152
  - lib/shipcloud/request/connection.rb
153
153
  - lib/shipcloud/request/info.rb
154
154
  - lib/shipcloud/shipcloud_error.rb
155
155
  - lib/shipcloud/shipment.rb
156
156
  - lib/shipcloud/shipment_quote.rb
157
+ - lib/shipcloud/tracker.rb
157
158
  - lib/shipcloud/version.rb
158
159
  - lib/shipcloud/webhook.rb
159
160
  - shipcloud.gemspec
160
161
  - spec/shipcloud/address_spec.rb
161
162
  - spec/shipcloud/carrier_spec.rb
163
+ - spec/shipcloud/pickup_request_spec.rb
162
164
  - spec/shipcloud/request/base_spec.rb
163
165
  - spec/shipcloud/request/connection_spec.rb
166
+ - spec/shipcloud/request/info_spec.rb
164
167
  - spec/shipcloud/shipcloud_error_spec.rb
165
168
  - spec/shipcloud/shipment_quote_spec.rb
166
169
  - spec/shipcloud/shipment_spec.rb
170
+ - spec/shipcloud/tracker_spec.rb
167
171
  - spec/shipcloud/webhooks_spec.rb
168
172
  - spec/shipcloud_spec.rb
169
173
  - spec/spec_helper.rb
@@ -187,18 +191,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
191
  version: '0'
188
192
  requirements: []
189
193
  rubyforge_project:
190
- rubygems_version: 2.5.1
194
+ rubygems_version: 2.6.11
191
195
  signing_key:
192
196
  specification_version: 4
193
197
  summary: A wrapper for the shipcloud API
194
198
  test_files:
195
199
  - spec/shipcloud/address_spec.rb
196
200
  - spec/shipcloud/carrier_spec.rb
201
+ - spec/shipcloud/pickup_request_spec.rb
197
202
  - spec/shipcloud/request/base_spec.rb
198
203
  - spec/shipcloud/request/connection_spec.rb
204
+ - spec/shipcloud/request/info_spec.rb
199
205
  - spec/shipcloud/shipcloud_error_spec.rb
200
206
  - spec/shipcloud/shipment_quote_spec.rb
201
207
  - spec/shipcloud/shipment_spec.rb
208
+ - spec/shipcloud/tracker_spec.rb
202
209
  - spec/shipcloud/webhooks_spec.rb
203
210
  - spec/shipcloud_spec.rb
204
211
  - spec/spec_helper.rb
@@ -1,267 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - "vendor/**/*"
4
- - "db/schema.rb"
5
- UseCache: false
6
- Rails:
7
- Enabled: true
8
- Rails/FindBy:
9
- Enabled: false
10
- Metrics/LineLength:
11
- Max: 100
12
- Style/CollectionMethods:
13
- Description: Preferred collection methods.
14
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
15
- Enabled: true
16
- PreferredMethods:
17
- collect: map
18
- collect!: map!
19
- find: detect
20
- find_all: select
21
- reduce: inject
22
- Style/DotPosition:
23
- Description: Checks the position of the dot in multi-line method calls.
24
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
25
- Enabled: true
26
- EnforcedStyle: trailing
27
- SupportedStyles:
28
- - trailing
29
- Style/FileName:
30
- Description: Use snake_case for source file names.
31
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
32
- Enabled: false
33
- Exclude: []
34
- Style/FirstArrayElementLineBreak:
35
- Description: >-
36
- Checks for a line break before the first element in a
37
- multi-line array.
38
- Enabled: true
39
- Style/FirstHashElementLineBreak:
40
- Description: >-
41
- Checks for a line break before the first element in a
42
- multi-line hash.
43
- Enabled: true
44
- Style/FirstMethodArgumentLineBreak:
45
- Description: >-
46
- Checks for a line break before the first argument in a
47
- multi-line method call.
48
- Enabled: true
49
- Style/GuardClause:
50
- Description: Check for conditionals that can be replaced with guard clauses
51
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
52
- Enabled: false
53
- MinBodyLength: 1
54
- Style/IfUnlessModifier:
55
- Description: Favor modifier if/unless usage when you have a single-line body.
56
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
57
- Enabled: false
58
- MaxLineLength: 80
59
- Style/OptionHash:
60
- Description: Don't use option hashes when you can use keyword arguments.
61
- Enabled: false
62
- Style/PercentLiteralDelimiters:
63
- Description: Use `%`-literal delimiters consistently
64
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
65
- Enabled: false
66
- PreferredDelimiters:
67
- "%": "()"
68
- "%i": "()"
69
- "%q": "()"
70
- "%Q": "()"
71
- "%r": "{}"
72
- "%s": "()"
73
- "%w": "()"
74
- "%W": "()"
75
- "%x": "()"
76
- Style/PredicateName:
77
- Description: Check the names of predicate methods.
78
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
79
- Enabled: true
80
- NamePrefix:
81
- - is_
82
- - has_
83
- - have_
84
- NamePrefixBlacklist:
85
- - is_
86
- Exclude:
87
- - spec/**/*
88
- Style/RaiseArgs:
89
- Description: Checks the arguments passed to raise/fail.
90
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
91
- Enabled: false
92
- EnforcedStyle: exploded
93
- SupportedStyles:
94
- - compact
95
- - exploded
96
- Style/SignalException:
97
- Description: Checks for proper usage of fail and raise.
98
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
99
- Enabled: false
100
- EnforcedStyle: semantic
101
- SupportedStyles:
102
- - only_raise
103
- - only_fail
104
- - semantic
105
- Style/SingleLineBlockParams:
106
- Description: Enforces the names of some block params.
107
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
108
- Enabled: false
109
- Methods:
110
- - reduce:
111
- - a
112
- - e
113
- - inject:
114
- - a
115
- - e
116
- Style/SingleLineMethods:
117
- Description: Avoid single-line methods.
118
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
119
- Enabled: false
120
- AllowIfMethodIsEmpty: true
121
- Style/StringLiterals:
122
- Description: Checks if uses of quotes match the configured preference.
123
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
124
- Enabled: true
125
- EnforcedStyle: double_quotes
126
- SupportedStyles:
127
- - single_quotes
128
- - double_quotes
129
- Style/StringLiteralsInInterpolation:
130
- Description: Checks if uses of quotes inside expressions in interpolated strings
131
- match the configured preference.
132
- Enabled: true
133
- EnforcedStyle: single_quotes
134
- SupportedStyles:
135
- - single_quotes
136
- - double_quotes
137
- Style/TrailingCommaInArguments:
138
- Description: 'Checks for trailing comma in argument lists.'
139
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
140
- Enabled: false
141
- EnforcedStyleForMultiline: no_comma
142
- SupportedStyles:
143
- - comma
144
- - consistent_comma
145
- - no_comma
146
- Style/TrailingCommaInLiteral:
147
- Description: 'Checks for trailing comma in array and hash literals.'
148
- StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
149
- Enabled: false
150
- EnforcedStyleForMultiline: no_comma
151
- SupportedStyles:
152
- - comma
153
- - consistent_comma
154
- - no_comma
155
- Metrics/AbcSize:
156
- Description: A calculated magnitude based on number of assignments, branches, and
157
- conditions.
158
- Enabled: false
159
- Max: 15
160
- Metrics/ClassLength:
161
- Description: Avoid classes longer than 100 lines of code.
162
- Enabled: false
163
- CountComments: false
164
- Max: 100
165
- Metrics/ModuleLength:
166
- CountComments: false
167
- Max: 100
168
- Description: Avoid modules longer than 100 lines of code.
169
- Enabled: false
170
- Metrics/CyclomaticComplexity:
171
- Description: A complexity metric that is strongly correlated to the number of test
172
- cases needed to validate a method.
173
- Enabled: false
174
- Max: 6
175
- Metrics/MethodLength:
176
- Description: Avoid methods longer than 10 lines of code.
177
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
178
- Enabled: false
179
- CountComments: false
180
- Max: 10
181
- Metrics/ParameterLists:
182
- Description: Avoid parameter lists longer than three or four parameters.
183
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
184
- Enabled: false
185
- Max: 5
186
- CountKeywordArgs: true
187
- Metrics/PerceivedComplexity:
188
- Description: A complexity metric geared towards measuring complexity for a human
189
- reader.
190
- Enabled: false
191
- Max: 7
192
- Lint/AssignmentInCondition:
193
- Description: Don't use assignment in conditions.
194
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
195
- Enabled: false
196
- AllowSafeAssignment: true
197
- Style/InlineComment:
198
- Description: Avoid inline comments.
199
- Enabled: false
200
- Style/AccessorMethodName:
201
- Description: Check the naming of accessor methods for get_/set_.
202
- Enabled: false
203
- Style/Alias:
204
- Description: Use alias_method instead of alias.
205
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
206
- Enabled: false
207
- Style/Documentation:
208
- Description: Document classes and non-namespace modules.
209
- Enabled: false
210
- Style/DoubleNegation:
211
- Description: Checks for uses of double negation (!!).
212
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
213
- Enabled: false
214
- Style/EachWithObject:
215
- Description: Prefer `each_with_object` over `inject` or `reduce`.
216
- Enabled: false
217
- Style/EmptyLiteral:
218
- Description: Prefer literals to Array.new/Hash.new/String.new.
219
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
220
- Enabled: false
221
- Style/ModuleFunction:
222
- Description: Checks for usage of `extend self` in modules.
223
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
224
- Enabled: false
225
- Style/OneLineConditional:
226
- Description: Favor the ternary operator(?:) over if/then/else/end constructs.
227
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
228
- Enabled: false
229
- Style/PerlBackrefs:
230
- Description: Avoid Perl-style regex back references.
231
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
232
- Enabled: false
233
- Style/Send:
234
- Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
235
- may overlap with existing methods.
236
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
237
- Enabled: false
238
- Style/SpecialGlobalVars:
239
- Description: Avoid Perl-style global variables.
240
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
241
- Enabled: false
242
- Style/VariableInterpolation:
243
- Description: Don't interpolate global, instance and class variables directly in
244
- strings.
245
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
246
- Enabled: false
247
- Style/WhenThen:
248
- Description: Use when x then ... for one-line cases.
249
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
250
- Enabled: false
251
- Lint/EachWithObjectArgument:
252
- Description: Check for immutable argument given to each_with_object.
253
- Enabled: true
254
- Lint/EndAlignment:
255
- Description: This cop checks whether the end keywords are aligned properly.
256
- AlignWith: variable
257
- Enabled: true
258
- Lint/HandleExceptions:
259
- Description: Don't suppress exception.
260
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
261
- Enabled: false
262
- Lint/LiteralInCondition:
263
- Description: Checks of literals used in conditions.
264
- Enabled: false
265
- Lint/LiteralInInterpolation:
266
- Description: Checks for literals used in interpolation.
267
- Enabled: false