shipcloud 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +25 -0
- data/.hound.yml +12 -0
- data/.rubocop.yml +2 -0
- data/.ruby-style.yml +240 -0
- data/.travis.yml +11 -4
- data/CHANGELOG.md +95 -0
- data/README.md +40 -4
- data/lib/shipcloud.rb +3 -0
- data/lib/shipcloud/address.rb +13 -0
- data/lib/shipcloud/base.rb +23 -1
- data/lib/shipcloud/carrier.rb +1 -2
- data/lib/shipcloud/operations/all.rb +6 -4
- data/lib/shipcloud/operations/create.rb +4 -1
- data/lib/shipcloud/operations/delete.rb +1 -1
- data/lib/shipcloud/operations/find.rb +1 -1
- data/lib/shipcloud/operations/update.rb +2 -2
- data/lib/shipcloud/shipment.rb +6 -1
- data/lib/shipcloud/shipment_quote.rb +16 -0
- data/lib/shipcloud/version.rb +1 -1
- data/lib/shipcloud/webhook.rb +11 -0
- data/shipcloud.gemspec +14 -10
- data/spec/shipcloud/address_spec.rb +114 -0
- data/spec/shipcloud/carrier_spec.rb +53 -11
- data/spec/shipcloud/shipment_quote_spec.rb +74 -0
- data/spec/shipcloud/shipment_spec.rb +115 -0
- data/spec/shipcloud/webhooks_spec.rb +75 -0
- data/spec/spec_helper.rb +5 -0
- metadata +33 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be261ed61c16ba184adf29c75d3c40721eefc397
|
4
|
+
data.tar.gz: 54e6e380adc84a996c581726a8e3c0a47e60a6bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d988f7fdf9d858e240f132282da454c0bd814b30accc290d045ca17bcf73fce67c370293d1db75b53facff9d9918ace79fcaa4fd99e592fdad0398cfad3340
|
7
|
+
data.tar.gz: 19ca529bafdf0764d357e0652fe55019a7a84b0d1a5ce8d5c3d5514b571635af6eac92291b2381d084596dc14fbede14a3caf3119997a8518f9603b45645eb83
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
duplication:
|
4
|
+
enabled: true
|
5
|
+
config:
|
6
|
+
languages:
|
7
|
+
- ruby
|
8
|
+
- javascript
|
9
|
+
- python
|
10
|
+
- php
|
11
|
+
fixme:
|
12
|
+
enabled: true
|
13
|
+
rubocop:
|
14
|
+
enabled: true
|
15
|
+
ratings:
|
16
|
+
paths:
|
17
|
+
- "**.inc"
|
18
|
+
- "**.js"
|
19
|
+
- "**.jsx"
|
20
|
+
- "**.module"
|
21
|
+
- "**.php"
|
22
|
+
- "**.py"
|
23
|
+
- "**.rb"
|
24
|
+
exclude_paths:
|
25
|
+
- spec/**/*
|
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
data/.ruby-style.yml
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
AllCops:
|
2
|
+
RunRailsCops: true
|
3
|
+
Exclude:
|
4
|
+
- "vendor/**/*"
|
5
|
+
- "db/schema.rb"
|
6
|
+
UseCache: false
|
7
|
+
Rails/FindBy:
|
8
|
+
Enabled: false
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 100
|
11
|
+
Style/CollectionMethods:
|
12
|
+
Description: Preferred collection methods.
|
13
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
14
|
+
Enabled: true
|
15
|
+
PreferredMethods:
|
16
|
+
collect: map
|
17
|
+
collect!: map!
|
18
|
+
find: detect
|
19
|
+
find_all: select
|
20
|
+
reduce: inject
|
21
|
+
Style/DotPosition:
|
22
|
+
Description: Checks the position of the dot in multi-line method calls.
|
23
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
24
|
+
Enabled: true
|
25
|
+
EnforcedStyle: trailing
|
26
|
+
SupportedStyles:
|
27
|
+
- trailing
|
28
|
+
Style/FileName:
|
29
|
+
Description: Use snake_case for source file names.
|
30
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
31
|
+
Enabled: false
|
32
|
+
Exclude: []
|
33
|
+
Style/GuardClause:
|
34
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
35
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
36
|
+
Enabled: false
|
37
|
+
MinBodyLength: 1
|
38
|
+
Style/IfUnlessModifier:
|
39
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
40
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
41
|
+
Enabled: false
|
42
|
+
MaxLineLength: 80
|
43
|
+
Style/OptionHash:
|
44
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
45
|
+
Enabled: false
|
46
|
+
Style/PercentLiteralDelimiters:
|
47
|
+
Description: Use `%`-literal delimiters consistently
|
48
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
49
|
+
Enabled: false
|
50
|
+
PreferredDelimiters:
|
51
|
+
"%": "()"
|
52
|
+
"%i": "()"
|
53
|
+
"%q": "()"
|
54
|
+
"%Q": "()"
|
55
|
+
"%r": "{}"
|
56
|
+
"%s": "()"
|
57
|
+
"%w": "()"
|
58
|
+
"%W": "()"
|
59
|
+
"%x": "()"
|
60
|
+
Style/PredicateName:
|
61
|
+
Description: Check the names of predicate methods.
|
62
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
63
|
+
Enabled: true
|
64
|
+
NamePrefix:
|
65
|
+
- is_
|
66
|
+
- has_
|
67
|
+
- have_
|
68
|
+
NamePrefixBlacklist:
|
69
|
+
- is_
|
70
|
+
Exclude:
|
71
|
+
- spec/**/*
|
72
|
+
Style/RaiseArgs:
|
73
|
+
Description: Checks the arguments passed to raise/fail.
|
74
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
75
|
+
Enabled: false
|
76
|
+
EnforcedStyle: exploded
|
77
|
+
SupportedStyles:
|
78
|
+
- compact
|
79
|
+
- exploded
|
80
|
+
Style/SignalException:
|
81
|
+
Description: Checks for proper usage of fail and raise.
|
82
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
83
|
+
Enabled: false
|
84
|
+
EnforcedStyle: semantic
|
85
|
+
SupportedStyles:
|
86
|
+
- only_raise
|
87
|
+
- only_fail
|
88
|
+
- semantic
|
89
|
+
Style/SingleLineBlockParams:
|
90
|
+
Description: Enforces the names of some block params.
|
91
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
92
|
+
Enabled: false
|
93
|
+
Methods:
|
94
|
+
- reduce:
|
95
|
+
- a
|
96
|
+
- e
|
97
|
+
- inject:
|
98
|
+
- a
|
99
|
+
- e
|
100
|
+
Style/SingleLineMethods:
|
101
|
+
Description: Avoid single-line methods.
|
102
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
103
|
+
Enabled: false
|
104
|
+
AllowIfMethodIsEmpty: true
|
105
|
+
Style/StringLiterals:
|
106
|
+
Description: Checks if uses of quotes match the configured preference.
|
107
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
108
|
+
Enabled: true
|
109
|
+
EnforcedStyle: double_quotes
|
110
|
+
SupportedStyles:
|
111
|
+
- single_quotes
|
112
|
+
- double_quotes
|
113
|
+
Style/StringLiteralsInInterpolation:
|
114
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
115
|
+
match the configured preference.
|
116
|
+
Enabled: true
|
117
|
+
EnforcedStyle: single_quotes
|
118
|
+
SupportedStyles:
|
119
|
+
- single_quotes
|
120
|
+
- double_quotes
|
121
|
+
Style/TrailingComma:
|
122
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
123
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
124
|
+
Enabled: false
|
125
|
+
EnforcedStyleForMultiline: no_comma
|
126
|
+
SupportedStyles:
|
127
|
+
- comma
|
128
|
+
Metrics/AbcSize:
|
129
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
130
|
+
conditions.
|
131
|
+
Enabled: false
|
132
|
+
Max: 15
|
133
|
+
Metrics/ClassLength:
|
134
|
+
Description: Avoid classes longer than 100 lines of code.
|
135
|
+
Enabled: false
|
136
|
+
CountComments: false
|
137
|
+
Max: 100
|
138
|
+
Metrics/ModuleLength:
|
139
|
+
CountComments: false
|
140
|
+
Max: 100
|
141
|
+
Description: Avoid modules longer than 100 lines of code.
|
142
|
+
Enabled: false
|
143
|
+
Metrics/CyclomaticComplexity:
|
144
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
145
|
+
cases needed to validate a method.
|
146
|
+
Enabled: false
|
147
|
+
Max: 6
|
148
|
+
Metrics/MethodLength:
|
149
|
+
Description: Avoid methods longer than 10 lines of code.
|
150
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
151
|
+
Enabled: false
|
152
|
+
CountComments: false
|
153
|
+
Max: 10
|
154
|
+
Metrics/ParameterLists:
|
155
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
156
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
157
|
+
Enabled: false
|
158
|
+
Max: 5
|
159
|
+
CountKeywordArgs: true
|
160
|
+
Metrics/PerceivedComplexity:
|
161
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
162
|
+
reader.
|
163
|
+
Enabled: false
|
164
|
+
Max: 7
|
165
|
+
Lint/AssignmentInCondition:
|
166
|
+
Description: Don't use assignment in conditions.
|
167
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
168
|
+
Enabled: false
|
169
|
+
AllowSafeAssignment: true
|
170
|
+
Style/InlineComment:
|
171
|
+
Description: Avoid inline comments.
|
172
|
+
Enabled: false
|
173
|
+
Style/AccessorMethodName:
|
174
|
+
Description: Check the naming of accessor methods for get_/set_.
|
175
|
+
Enabled: false
|
176
|
+
Style/Alias:
|
177
|
+
Description: Use alias_method instead of alias.
|
178
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
179
|
+
Enabled: false
|
180
|
+
Style/Documentation:
|
181
|
+
Description: Document classes and non-namespace modules.
|
182
|
+
Enabled: false
|
183
|
+
Style/DoubleNegation:
|
184
|
+
Description: Checks for uses of double negation (!!).
|
185
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
186
|
+
Enabled: false
|
187
|
+
Style/EachWithObject:
|
188
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
189
|
+
Enabled: false
|
190
|
+
Style/EmptyLiteral:
|
191
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
192
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
193
|
+
Enabled: false
|
194
|
+
Style/ModuleFunction:
|
195
|
+
Description: Checks for usage of `extend self` in modules.
|
196
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
197
|
+
Enabled: false
|
198
|
+
Style/OneLineConditional:
|
199
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
200
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
201
|
+
Enabled: false
|
202
|
+
Style/PerlBackrefs:
|
203
|
+
Description: Avoid Perl-style regex back references.
|
204
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
205
|
+
Enabled: false
|
206
|
+
Style/Send:
|
207
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
208
|
+
may overlap with existing methods.
|
209
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
210
|
+
Enabled: false
|
211
|
+
Style/SpecialGlobalVars:
|
212
|
+
Description: Avoid Perl-style global variables.
|
213
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
214
|
+
Enabled: false
|
215
|
+
Style/VariableInterpolation:
|
216
|
+
Description: Don't interpolate global, instance and class variables directly in
|
217
|
+
strings.
|
218
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
219
|
+
Enabled: false
|
220
|
+
Style/WhenThen:
|
221
|
+
Description: Use when x then ... for one-line cases.
|
222
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
223
|
+
Enabled: false
|
224
|
+
Lint/EachWithObjectArgument:
|
225
|
+
Description: Check for immutable argument given to each_with_object.
|
226
|
+
Enabled: true
|
227
|
+
Lint/EndAlignment:
|
228
|
+
Description: This cop checks whether the end keywords are aligned properly.
|
229
|
+
AlignWith: variable
|
230
|
+
Enabled: true
|
231
|
+
Lint/HandleExceptions:
|
232
|
+
Description: Don't suppress exception.
|
233
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
234
|
+
Enabled: false
|
235
|
+
Lint/LiteralInCondition:
|
236
|
+
Description: Checks of literals used in conditions.
|
237
|
+
Enabled: false
|
238
|
+
Lint/LiteralInInterpolation:
|
239
|
+
Description: Checks for literals used in interpolation.
|
240
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
3
|
rvm:
|
3
|
-
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
- 2.1.
|
6
|
-
- 2.2.
|
7
|
-
-
|
5
|
+
- 2.1.7
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3.0
|
8
|
+
- jruby-9.0.0.0
|
8
9
|
- rbx-2
|
10
|
+
notifications:
|
11
|
+
flowdock:
|
12
|
+
secure: fSZxX5z3bHWT8aCFKBFrDDt5o3Jb6EFWcm+pAcMabpfDHc4iktWuCUlSM405798TRdKdws1A2RncQGYiQyLbqNvtLz48dvj4BxgYW7P/vg0koN+I/H2MjpZeuIQ7BRSEJIq2sAYNVya+hSil+SPEBMTngJiP6VYG0dm6fFnRkyk=
|
13
|
+
addons:
|
14
|
+
code_climate:
|
15
|
+
repo_token: 704eb62133d951ce460a6047a15a58e0a521aa20ec6a533fa7a37585f8a75602
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
## [0.6.0] - 2016-01-21
|
2
|
+
### Added
|
3
|
+
- This CHANGELOG file (Following "[Keep a CHANGELOG](http://keepachangelog.com/)")
|
4
|
+
- Create, find, update and index operations for address resource. (#4)
|
5
|
+
- Services attribute to carriers call (#5)
|
6
|
+
- Index operation for shipment resources with optional filter parameters. (#6)
|
7
|
+
- Create, find and index operations for webhook resource. (#7)
|
8
|
+
- Added the following ruby versions to travis-ci test runs:
|
9
|
+
- 2.1.7
|
10
|
+
- 2.2.4
|
11
|
+
- 2.3.0
|
12
|
+
- Add ShipmentQuotes class returning the price for a certain shipment (#9)
|
13
|
+
|
14
|
+
### Removed
|
15
|
+
- Dropped support for ruby 1.9.x in order to use the new language features of ruby 2.x. The official support of ruby 1.9.3 already ended on February 23, 2015 (https://www.ruby-lang.org/en/news/2014/01/10/ruby-1-9-3-will-end-on-2015/)
|
16
|
+
- Removed the following ruby versions from travis-ci test runs:
|
17
|
+
- 2.1.5
|
18
|
+
- 2.2.1
|
19
|
+
- 2.2.2
|
20
|
+
- 2.2.3
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
- Start following [SemVer](http://semver.org) properly.
|
24
|
+
- The link to the developer documenation for the Shipment ressource still pointed at Apiary; it now correctly points to the shipcloud Developer Portal's API section on Shipments.
|
25
|
+
|
26
|
+
## [0.5.0] - 2015-04-02
|
27
|
+
### Added
|
28
|
+
- Call to list carriers (from @axelerator - #1)
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- Fixed bug in error handling and array responses
|
32
|
+
|
33
|
+
## [0.4.0] - 2014-06-27
|
34
|
+
## Added
|
35
|
+
- Added a console task to the rakefile to provide an easy accessible
|
36
|
+
playground for the gem (15c5719)- http://erniemiller.org/2014/02/05/7-lines-every-gems-rakefile-should-have/
|
37
|
+
- Added debug option to configuration to control debug output (4fd9dc529cb3862c2c7091007f39b54bbc91c14e)
|
38
|
+
|
39
|
+
## Changed
|
40
|
+
- Updated Gemfile and shipcloud.gemspec
|
41
|
+
- bundler version 1.6.0
|
42
|
+
- rake version ~> 10.3.0
|
43
|
+
- rspec version ~> 2.99.0'
|
44
|
+
- webmock version ~> 1.18.0
|
45
|
+
- pry version ~> 0.10.0
|
46
|
+
|
47
|
+
## [0.3.0] - 2013-09-12
|
48
|
+
## Added
|
49
|
+
- Added shipment usage info to Readme
|
50
|
+
- Added DELETE request for shipment resource
|
51
|
+
- Added configuration via config block
|
52
|
+
- Added possibility to configure http mode
|
53
|
+
|
54
|
+
## [0.2.0] - 2013-08-30
|
55
|
+
## Added
|
56
|
+
- Added find operation
|
57
|
+
- Added shipments attributes to allow easier access to response data
|
58
|
+
|
59
|
+
## [0.1.0] - 2013-08-30
|
60
|
+
## Added
|
61
|
+
- Added basic request handling
|
62
|
+
- Added Shipment class
|
63
|
+
- Added user agent
|
64
|
+
|
65
|
+
## Removed
|
66
|
+
- Removed ssl certificate reference
|
67
|
+
- Removed debug code
|
68
|
+
|
69
|
+
## Fixed
|
70
|
+
- Fixed request content-type and response validation
|
71
|
+
|
72
|
+
|
73
|
+
-----------------------------------------------------------------------------------------
|
74
|
+
|
75
|
+
Template:
|
76
|
+
## [0.0.0] - 2014-05-31
|
77
|
+
### Added
|
78
|
+
- something was added
|
79
|
+
|
80
|
+
### Changed
|
81
|
+
- something changed
|
82
|
+
|
83
|
+
### Deprecated
|
84
|
+
- something is depricated
|
85
|
+
|
86
|
+
### Removed
|
87
|
+
- something was removed
|
88
|
+
|
89
|
+
### Fixed
|
90
|
+
- something was fixed
|
91
|
+
|
92
|
+
### Security
|
93
|
+
- a security fix
|
94
|
+
|
95
|
+
Following "[Keep a CHANGELOG](http://keepachangelog.com/)"
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
[![Code Climate](https://codeclimate.com/github/shipcloud/shipcloud-ruby.png)](https://codeclimate.com/github/shipcloud/shipcloud-ruby) [![Build Status](https://travis-ci.org/shipcloud/shipcloud-ruby.png?branch=master)](https://travis-ci.org/shipcloud/shipcloud-ruby)
|
1
|
+
[![Code Climate](https://codeclimate.com/github/shipcloud/shipcloud-ruby.png)](https://codeclimate.com/github/shipcloud/shipcloud-ruby) [![Build Status](https://travis-ci.org/shipcloud/shipcloud-ruby.png?branch=master)](https://travis-ci.org/shipcloud/shipcloud-ruby) [![Dependency Status](https://gemnasium.com/shipcloud/shipcloud-ruby.svg)](https://gemnasium.com/shipcloud/shipcloud-ruby)
|
2
|
+
|
2
3
|
# shipcloud
|
3
4
|
|
4
5
|
A Ruby wrapper for the shipcloud API
|
@@ -38,7 +39,7 @@ You can sign up for a developer account at *[shipcloud.io](http://www.shipcloud.
|
|
38
39
|
### Create a new shipment
|
39
40
|
|
40
41
|
To create a new Shipment on the shipclod platform, you need to provide the name of the carrier, to- and from-address, and the package dimensions.
|
41
|
-
For details, see *[shipcloud API documentation on Shipments](http://
|
42
|
+
For details, see *[shipcloud API documentation on Shipments](http://developers.shipcloud.io/reference/#shipments)*
|
42
43
|
```
|
43
44
|
Shipcloud::Shipment.create(
|
44
45
|
carrier: 'ups',
|
@@ -56,10 +57,45 @@ shipment = Shipcloud::Shipment.create(...) # parameters ommitted
|
|
56
57
|
shipment.tracking_url # -> http://track.shipcloud.io/uzdgu22z3ed12
|
57
58
|
```
|
58
59
|
|
60
|
+
### Get a shipment quote
|
61
|
+
|
62
|
+
To get a shipment qoute from the shipclod platform, you need to provide the name of the carrier, the service, to- and from-address, and the package dimensions.
|
63
|
+
For details, see *[shipcloud API documentation on shipment quotes](https://developers.shipcloud.io/reference/#shipment-quotes)*
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
shipment_quote = Shipcloud::ShipmentQuote.create(
|
67
|
+
carrier: 'ups',
|
68
|
+
service: 'standard',
|
69
|
+
to: {
|
70
|
+
street: "Receiver street",
|
71
|
+
street_no: "123",
|
72
|
+
zip_code: "12345",
|
73
|
+
city: "Receiver town",
|
74
|
+
country: "DE"
|
75
|
+
},
|
76
|
+
from: {
|
77
|
+
street: "Sender street",
|
78
|
+
street_no: "321",
|
79
|
+
zip_code: "54321",
|
80
|
+
city: "Sender town",
|
81
|
+
country: "DE"
|
82
|
+
},
|
83
|
+
package: {
|
84
|
+
weight: 8,
|
85
|
+
width: 15,
|
86
|
+
length: 32,
|
87
|
+
height: 46,
|
88
|
+
},
|
89
|
+
)
|
90
|
+
|
91
|
+
shipment_quote.price # => 6.2
|
92
|
+
```
|
93
|
+
|
59
94
|
## Contributing
|
60
95
|
|
61
96
|
1. Fork it
|
62
97
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
98
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
-
4.
|
65
|
-
5.
|
99
|
+
4. Update the "Unreleased" section of the [CHANGELOG.md](CHANGELOG.md) ([Keep a CHANGELOG](http://keepachangelog.com/))
|
100
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
6. Create new Pull Request
|
data/lib/shipcloud.rb
CHANGED
@@ -17,6 +17,9 @@ module Shipcloud
|
|
17
17
|
autoload :Base, "shipcloud/base"
|
18
18
|
autoload :Shipment, "shipcloud/shipment"
|
19
19
|
autoload :Carrier, "shipcloud/carrier"
|
20
|
+
autoload :Address, "shipcloud/address"
|
21
|
+
autoload :ShipmentQuote, "shipcloud/shipment_quote"
|
22
|
+
autoload :Webhook, "shipcloud/webhook"
|
20
23
|
|
21
24
|
module Operations
|
22
25
|
autoload :Create, "shipcloud/operations/create"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Shipcloud
|
2
|
+
class Address < Base
|
3
|
+
include Shipcloud::Operations::Update
|
4
|
+
include Shipcloud::Operations::All
|
5
|
+
|
6
|
+
attr_accessor :company, :first_name, :last_name, :care_of, :street,
|
7
|
+
:street_no, :zip_code, :city, :state, :country, :phone
|
8
|
+
|
9
|
+
def self.base_url
|
10
|
+
"#{class_name.downcase}es"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/shipcloud/base.rb
CHANGED
@@ -18,5 +18,27 @@ module Shipcloud
|
|
18
18
|
instance_variable_set("@#{key}", value)
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
def self.camel_to_snakecase(string)
|
23
|
+
string.gsub(/::/, "/").
|
24
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
25
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
26
|
+
tr("-", "_").
|
27
|
+
downcase
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.class_name
|
31
|
+
self.name.split("::").last
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.base_url
|
35
|
+
"#{class_name.downcase}s"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.create_response_root
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.index_response_root
|
42
|
+
end
|
21
43
|
end
|
22
|
-
end
|
44
|
+
end
|
data/lib/shipcloud/carrier.rb
CHANGED
@@ -3,9 +3,12 @@ module Shipcloud
|
|
3
3
|
module All
|
4
4
|
module ClassMethods
|
5
5
|
# Loads all Objects of the resource
|
6
|
-
def all
|
7
|
-
response = Shipcloud.request(:get,
|
8
|
-
|
6
|
+
def all(filter = {})
|
7
|
+
response = Shipcloud.request(:get, base_url, filter)
|
8
|
+
if index_response_root
|
9
|
+
response = response.fetch(index_response_root, [])
|
10
|
+
end
|
11
|
+
response.map { |hash| new(hash) }
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
@@ -15,4 +18,3 @@ module Shipcloud
|
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
18
|
-
|
@@ -6,7 +6,10 @@ module Shipcloud
|
|
6
6
|
#
|
7
7
|
# @param [Hash] attributes The attributes of the created object
|
8
8
|
def create(attributes)
|
9
|
-
response = Shipcloud.request(:post,
|
9
|
+
response = Shipcloud.request(:post, base_url, attributes)
|
10
|
+
if create_response_root
|
11
|
+
response = response.fetch(create_response_root, {})
|
12
|
+
end
|
10
13
|
self.new(response)
|
11
14
|
end
|
12
15
|
end
|
@@ -6,7 +6,7 @@ module Shipcloud
|
|
6
6
|
#
|
7
7
|
# @param [String] id The id of the object that gets deleted
|
8
8
|
def delete(id)
|
9
|
-
response = Shipcloud.request(:delete, "#{
|
9
|
+
response = Shipcloud.request(:delete, "#{base_url}/#{id}", {})
|
10
10
|
true
|
11
11
|
end
|
12
12
|
end
|
@@ -7,7 +7,7 @@ module Shipcloud
|
|
7
7
|
# @param [String] id The id of the object that should be found
|
8
8
|
# @return [Shipcloud::Base] The found object
|
9
9
|
def find(id)
|
10
|
-
response = Shipcloud.request(:get, "#{
|
10
|
+
response = Shipcloud.request(:get, "#{base_url}/#{id}", {})
|
11
11
|
self.new(response)
|
12
12
|
end
|
13
13
|
end
|
@@ -7,7 +7,7 @@ module Shipcloud
|
|
7
7
|
# @param [String] id The id of the object that should be updated
|
8
8
|
# @param [Hash] attributes The attributes that should be updated
|
9
9
|
def update(id, attributes)
|
10
|
-
response = Shipcloud.request(:put, "#{
|
10
|
+
response = Shipcloud.request(:put, "#{base_url}/#{id}", attributes)
|
11
11
|
self.new(response)
|
12
12
|
end
|
13
13
|
end
|
@@ -20,7 +20,7 @@ module Shipcloud
|
|
20
20
|
#
|
21
21
|
# @param [Hash] attributes The attributes that should be updated
|
22
22
|
def update(attributes)
|
23
|
-
response = Shipcloud.request(:put, "#{
|
23
|
+
response = Shipcloud.request(:put, "#{base_url}/#{id}", attributes)
|
24
24
|
set_attributes(response)
|
25
25
|
end
|
26
26
|
end
|
data/lib/shipcloud/shipment.rb
CHANGED
@@ -2,8 +2,13 @@ module Shipcloud
|
|
2
2
|
class Shipment < Base
|
3
3
|
include Shipcloud::Operations::Delete
|
4
4
|
include Shipcloud::Operations::Update
|
5
|
+
include Shipcloud::Operations::All
|
5
6
|
|
6
7
|
attr_accessor :from, :to, :carrier, :package, :reference_number
|
7
8
|
attr_reader :id, :created_at, :carrier_tracking_no, :tracking_url, :label_url, :packages, :price
|
9
|
+
|
10
|
+
def self.index_response_root
|
11
|
+
"#{class_name.downcase}s"
|
12
|
+
end
|
8
13
|
end
|
9
|
-
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Shipcloud
|
2
|
+
class ShipmentQuote < Base
|
3
|
+
include Shipcloud::Operations::Create
|
4
|
+
|
5
|
+
attr_accessor :from, :to, :carrier, :package, :service
|
6
|
+
attr_reader :price
|
7
|
+
|
8
|
+
def self.base_url
|
9
|
+
"shipment_quotes"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create_response_root
|
13
|
+
"shipment_quote"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/shipcloud/version.rb
CHANGED
data/shipcloud.gemspec
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "shipcloud/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "shipcloud"
|
8
8
|
spec.version = Shipcloud::VERSION
|
9
9
|
spec.authors = ["sthollmann"]
|
10
10
|
spec.email = ["stefan@shipcloud.io"]
|
11
|
-
spec.
|
12
|
-
spec.
|
11
|
+
spec.summary = "A wrapper for the shipcloud API"
|
12
|
+
spec.description = "A wrapper for the shipcloud API. " \
|
13
|
+
"Fore more details visit https://developers.shipcloud.io/"
|
13
14
|
spec.homepage = "https://github.com/shipcloud/shipcloud-ruby"
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
@@ -18,10 +19,13 @@ Gem::Specification.new do |spec|
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
20
|
spec.require_paths = ["lib"]
|
20
21
|
|
21
|
-
spec.
|
22
|
-
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
22
|
+
spec.required_ruby_version = ">= 2.0"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "json", "~> 1.8", ">= 1.8.0"
|
25
|
+
spec.add_development_dependency "bundler", ">= 1.3.0", "< 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.3"
|
27
|
+
spec.add_development_dependency "rspec", "~> 2.99"
|
28
|
+
spec.add_development_dependency "webmock", "~> 1.18"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
30
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
27
31
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Shipcloud::Address do
|
5
|
+
valid_attributes = {
|
6
|
+
company: 'shipcloud GmbH',
|
7
|
+
first_name: 'Maxi',
|
8
|
+
last_name: 'Musterfrau',
|
9
|
+
care_of: 'Mustermann',
|
10
|
+
street: 'Musterstraße',
|
11
|
+
street_no: '123',
|
12
|
+
zip_code: '12345',
|
13
|
+
city: 'Hamburg',
|
14
|
+
state: 'Hamburg',
|
15
|
+
country: 'DE',
|
16
|
+
phone: '040/123456789'
|
17
|
+
}
|
18
|
+
|
19
|
+
describe '#initialize' do
|
20
|
+
it 'initializes all attributes correctly' do
|
21
|
+
address = Shipcloud::Address.new(valid_attributes)
|
22
|
+
expect(address.company).to eq 'shipcloud GmbH'
|
23
|
+
expect(address.first_name).to eq 'Maxi'
|
24
|
+
expect(address.last_name).to eq 'Musterfrau'
|
25
|
+
expect(address.care_of).to eq 'Mustermann'
|
26
|
+
expect(address.street).to eq 'Musterstraße'
|
27
|
+
expect(address.street_no).to eq '123'
|
28
|
+
expect(address.zip_code).to eq '12345'
|
29
|
+
expect(address.city).to eq 'Hamburg'
|
30
|
+
expect(address.state).to eq 'Hamburg'
|
31
|
+
expect(address.country).to eq 'DE'
|
32
|
+
expect(address.phone).to eq '040/123456789'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.create' do
|
37
|
+
it 'makes a new POST request using the correct API endpoint' do
|
38
|
+
Shipcloud.should_receive(:request).with(:post, 'addresses', valid_attributes).and_return('data' => {})
|
39
|
+
Shipcloud::Address.create(valid_attributes)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.find' do
|
44
|
+
it 'makes a new GET request using the correct API endpoint to receive a specific address' do
|
45
|
+
Shipcloud.should_receive(:request).with(
|
46
|
+
:get, 'addresses/123', {}).and_return('id' => '123')
|
47
|
+
Shipcloud::Address.find('123')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '.update' do
|
52
|
+
it 'makes a new PUT request using the correct API endpoint' do
|
53
|
+
Shipcloud.should_receive(:request).with(
|
54
|
+
:put, 'addresses/123', {:street => 'Mittelweg' }).and_return('data' => {})
|
55
|
+
Shipcloud::Address.update('123', {:street => 'Mittelweg' })
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.all' do
|
60
|
+
it 'makes a new Get request using the correct API endpoint' do
|
61
|
+
expect(Shipcloud).to receive(:request).
|
62
|
+
with(:get, 'addresses', {}).and_return([])
|
63
|
+
|
64
|
+
Shipcloud::Address.all
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns a list of Address objects' do
|
68
|
+
stub_addresses_request
|
69
|
+
|
70
|
+
addresses = Shipcloud::Address.all
|
71
|
+
|
72
|
+
addresses.each do |address|
|
73
|
+
expect(address).to be_a Shipcloud::Address
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def stub_addresses_request
|
79
|
+
allow(Shipcloud).to receive(:request).
|
80
|
+
with(:get, 'addresses', {}).
|
81
|
+
and_return(
|
82
|
+
[
|
83
|
+
{
|
84
|
+
'id' => '1c81efb7-9b95-4dd8-92e3-cac1bca3df6f',
|
85
|
+
'company' => '',
|
86
|
+
'first_name' => 'Max',
|
87
|
+
'last_name' => 'Mustermann',
|
88
|
+
'care_of' => '',
|
89
|
+
'street' => 'Musterstraße',
|
90
|
+
'street_no' => '42',
|
91
|
+
'zip_code' => '12345',
|
92
|
+
'city' => 'Musterstadt',
|
93
|
+
'state' => '',
|
94
|
+
'country' => 'DE',
|
95
|
+
'phone' => ''
|
96
|
+
},
|
97
|
+
{
|
98
|
+
'id' => '7ea2a290-b456-4ecf-9010-e82b3da298f0',
|
99
|
+
'company' => 'Muster-Company',
|
100
|
+
'first_name' => 'Max',
|
101
|
+
'last_name' => 'Mustermann',
|
102
|
+
'care_of' => '',
|
103
|
+
'street' => 'Musterstraße',
|
104
|
+
'street_no' => '42',
|
105
|
+
'zip_code' => '54321',
|
106
|
+
'city' => 'Musterstadt',
|
107
|
+
'state' => '',
|
108
|
+
'country' => 'DE',
|
109
|
+
'phone' => ''
|
110
|
+
}
|
111
|
+
]
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
@@ -3,11 +3,21 @@ require 'spec_helper'
|
|
3
3
|
describe Shipcloud::Carrier do
|
4
4
|
describe '#initialize' do
|
5
5
|
it 'initializes all attributes correctly' do
|
6
|
-
valid_attributes = {
|
6
|
+
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
|
+
)
|
15
|
+
}
|
7
16
|
carrier = Shipcloud::Carrier.new(valid_attributes)
|
8
17
|
|
9
18
|
expect(carrier.name).to eq 'bogus'
|
10
19
|
expect(carrier.display_name).to eq 'Bogus Carrier'
|
20
|
+
expect(carrier.services).to eq %w(standard, returns, one_day, one_day_early)
|
11
21
|
end
|
12
22
|
end
|
13
23
|
|
@@ -33,22 +43,54 @@ describe Shipcloud::Carrier do
|
|
33
43
|
stub_carriers_request
|
34
44
|
allow(Shipcloud::Carrier).to receive(:new)
|
35
45
|
|
36
|
-
|
46
|
+
Shipcloud::Carrier.all
|
37
47
|
|
38
|
-
expect(Shipcloud::Carrier).to have_received(:new)
|
39
|
-
with(
|
40
|
-
|
41
|
-
|
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
|
+
)
|
58
|
+
)
|
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
|
+
)
|
67
|
+
)
|
42
68
|
end
|
43
69
|
end
|
44
70
|
|
45
71
|
def stub_carriers_request
|
46
|
-
allow(Shipcloud).to receive(:request)
|
47
|
-
with(:get, 'carriers', {})
|
48
|
-
and_return(
|
72
|
+
allow(Shipcloud).to receive(:request)
|
73
|
+
.with(:get, 'carriers', {})
|
74
|
+
.and_return(
|
49
75
|
[
|
50
|
-
{
|
51
|
-
|
76
|
+
{
|
77
|
+
'name' => 'carrier_1',
|
78
|
+
'display_name' => 'Carrier 1',
|
79
|
+
'services' => %w(
|
80
|
+
standard,
|
81
|
+
returns,
|
82
|
+
one_day,
|
83
|
+
one_day_early
|
84
|
+
)
|
85
|
+
},
|
86
|
+
{
|
87
|
+
'name' => 'carrier_2',
|
88
|
+
'display_name' => 'Carrier 2',
|
89
|
+
'services' => %w(
|
90
|
+
standard,
|
91
|
+
returns
|
92
|
+
)
|
93
|
+
}
|
52
94
|
]
|
53
95
|
)
|
54
96
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Shipcloud::ShipmentQuote do
|
4
|
+
valid_attributes = {
|
5
|
+
to: {
|
6
|
+
company: "Beispielfirma",
|
7
|
+
street: "Beispielstrasse",
|
8
|
+
street_no: "42",
|
9
|
+
city: "Berlin",
|
10
|
+
zip_code: "10000",
|
11
|
+
},
|
12
|
+
from: {
|
13
|
+
company: "shipcloud GmbH",
|
14
|
+
street: "Musterallee",
|
15
|
+
street_no: "23",
|
16
|
+
city: "Hamburg",
|
17
|
+
zip_code: "20000",
|
18
|
+
},
|
19
|
+
service: "standard",
|
20
|
+
carrier: "dhl",
|
21
|
+
package: {
|
22
|
+
weight: 2.5,
|
23
|
+
length: 40,
|
24
|
+
width: 20,
|
25
|
+
height: 20
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
describe "#initialize" do
|
30
|
+
it "initializes all attributes correctly" do
|
31
|
+
quote = Shipcloud::ShipmentQuote.new(valid_attributes)
|
32
|
+
|
33
|
+
expect(quote.to[:company]).to eq "Beispielfirma"
|
34
|
+
expect(quote.to[:street]).to eq "Beispielstrasse"
|
35
|
+
expect(quote.to[:street_no]).to eq "42"
|
36
|
+
expect(quote.to[:city]).to eq "Berlin"
|
37
|
+
expect(quote.to[:zip_code]).to eq "10000"
|
38
|
+
expect(quote.from[:company]).to eq "shipcloud GmbH"
|
39
|
+
expect(quote.from[:street]).to eq "Musterallee"
|
40
|
+
expect(quote.from[:street_no]).to eq "23"
|
41
|
+
expect(quote.from[:city]).to eq "Hamburg"
|
42
|
+
expect(quote.from[:zip_code]).to eq "20000"
|
43
|
+
expect(quote.carrier).to eq "dhl"
|
44
|
+
expect(quote.service).to eq "standard"
|
45
|
+
expect(quote.package[:weight]).to eq 2.5
|
46
|
+
expect(quote.package[:length]).to eq 40
|
47
|
+
expect(quote.package[:width]).to eq 20
|
48
|
+
expect(quote.package[:height]).to eq 20
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe ".create" do
|
53
|
+
it "makes a new POST request using the correct API endpoint" do
|
54
|
+
expect(Shipcloud).to receive(:request).
|
55
|
+
with(:post, "shipment_quotes", valid_attributes).
|
56
|
+
and_return("data" => {})
|
57
|
+
|
58
|
+
Shipcloud::ShipmentQuote.create(valid_attributes)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "initializes a ShipmentQuote with price" do
|
62
|
+
allow(Shipcloud).to receive(:request).
|
63
|
+
and_return(
|
64
|
+
"shipment_quote" => {
|
65
|
+
"price" => 42.12
|
66
|
+
}
|
67
|
+
)
|
68
|
+
|
69
|
+
shipment_quote = Shipcloud::ShipmentQuote.create(valid_attributes)
|
70
|
+
|
71
|
+
expect(shipment_quote.price).to eq 42.12
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -72,4 +72,119 @@ describe Shipcloud::Shipment do
|
|
72
72
|
Shipcloud::Shipment.delete("123")
|
73
73
|
end
|
74
74
|
end
|
75
|
+
|
76
|
+
describe ".all" do
|
77
|
+
it "makes a new Get request using the correct API endpoint" do
|
78
|
+
expect(Shipcloud).to receive(:request).
|
79
|
+
with(:get, "shipments", {}).
|
80
|
+
and_return("shipments" => [])
|
81
|
+
|
82
|
+
Shipcloud::Shipment.all
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns a list of Shipment objects" do
|
86
|
+
stub_shipments_requests
|
87
|
+
|
88
|
+
shipments = Shipcloud::Shipment.all
|
89
|
+
|
90
|
+
shipments.each do |shipment|
|
91
|
+
expect(shipment).to be_a Shipcloud::Shipment
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns a filtered list of Shipment objects when using filter parameters" do
|
96
|
+
filter = {
|
97
|
+
"carrier" => "dhl",
|
98
|
+
"service" => "returns",
|
99
|
+
"reference_number" => "ref123456",
|
100
|
+
"carrier_tracking_no" => "43128000105",
|
101
|
+
"tracking_status" => "out_for_delivery",
|
102
|
+
"page" => 2,
|
103
|
+
"per_page" => 25,
|
104
|
+
}
|
105
|
+
|
106
|
+
expect(Shipcloud).to receive(:request).
|
107
|
+
with(:get, "shipments", filter).
|
108
|
+
and_return("shipments" => shipments_array)
|
109
|
+
|
110
|
+
Shipcloud::Shipment.all(filter)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def stub_shipments_requests
|
115
|
+
allow(Shipcloud).to receive(:request).
|
116
|
+
with(:get, "shipments", {}).
|
117
|
+
and_return("shipments" => shipments_array)
|
118
|
+
end
|
119
|
+
|
120
|
+
def shipments_array
|
121
|
+
[
|
122
|
+
{ "id" => "86afb143f9c9c0cfd4eb7a7c26a5c616585a6271",
|
123
|
+
"carrier_tracking_no" => "43128000105",
|
124
|
+
"carrier" => "hermes",
|
125
|
+
"service" => "standard",
|
126
|
+
"created_at" => "2014-11-12T14:03:45+01:00",
|
127
|
+
"price" => 3.5,
|
128
|
+
"tracking_url" => "http://track.shipcloud.dev/de/86afb143f9",
|
129
|
+
"to" => {
|
130
|
+
"first_name" => "Hans",
|
131
|
+
"last_name" => "Meier",
|
132
|
+
"street" => "Semmelweg",
|
133
|
+
"street_no" => "1",
|
134
|
+
"zip_code" => "12345",
|
135
|
+
"city" => "Hamburg",
|
136
|
+
"country" => "DE"
|
137
|
+
},
|
138
|
+
"from" => {
|
139
|
+
"company" => "webionate GmbH",
|
140
|
+
"last_name" => "Fahlbusch",
|
141
|
+
"street" => "Lüdmoor",
|
142
|
+
"street_no" => "35a",
|
143
|
+
"zip_code" => "22175",
|
144
|
+
"city" => "Hamburg",
|
145
|
+
"country" => "DE"
|
146
|
+
},
|
147
|
+
"packages" => {
|
148
|
+
"id" => "be81573799958587ae891b983aabf9c4089fc462",
|
149
|
+
"length" => 10.0,
|
150
|
+
"width" => 10.0,
|
151
|
+
"height" => 10.0,
|
152
|
+
"weight" => 1.5
|
153
|
+
}
|
154
|
+
},
|
155
|
+
{ "id" => "be81573799958587ae891b983aabf9c4089fc462",
|
156
|
+
"carrier_tracking_no" => "1Z12345E1305277940",
|
157
|
+
"carrier" => "ups",
|
158
|
+
"service" => "standard",
|
159
|
+
"created_at" => "2014-11-12T14:03:45+01:00",
|
160
|
+
"price" => 3.0,
|
161
|
+
"tracking_url" => "http://track.shipcloud.dev/de/be598a2fd2",
|
162
|
+
"to" => {
|
163
|
+
"first_name" => "Test",
|
164
|
+
"last_name" => "Kunde",
|
165
|
+
"street" => "Gluckstr.",
|
166
|
+
"street_no" => "57",
|
167
|
+
"zip_code" => "22081",
|
168
|
+
"city" => "Hamburg",
|
169
|
+
"country" => "DE"
|
170
|
+
},
|
171
|
+
"from" => {
|
172
|
+
"company" => "webionate GmbH",
|
173
|
+
"last_name" => "Fahlbusch",
|
174
|
+
"street" => "Lüdmoor",
|
175
|
+
"street_no" => "35a",
|
176
|
+
"zip_code" => "22175",
|
177
|
+
"city" => "Hamburg",
|
178
|
+
"country" => "DE"
|
179
|
+
},
|
180
|
+
"packages" => {
|
181
|
+
"id" => "74d4f1fc193d8a7ca542d1ee4e2021f3ddb82242",
|
182
|
+
"length" => 15.0,
|
183
|
+
"width" => 20.0,
|
184
|
+
"height" => 10.0,
|
185
|
+
"weight" => 2.0
|
186
|
+
}
|
187
|
+
}
|
188
|
+
]
|
189
|
+
end
|
75
190
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Shipcloud::Webhook do
|
4
|
+
valid_attributes = {
|
5
|
+
url: "https://example.com/webhook",
|
6
|
+
event_types: ["shipment.tracking.delayed", "shipment.tracking.delivered"]
|
7
|
+
}
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
it "initializes all attributes correctly" do
|
11
|
+
webhook = Shipcloud::Webhook.new(valid_attributes)
|
12
|
+
expect(webhook.url).to eq "https://example.com/webhook"
|
13
|
+
expect(webhook.event_types).to eq ["shipment.tracking.delayed", "shipment.tracking.delivered"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".create" do
|
18
|
+
it "makes a new POST request using the correct API endpoint" do
|
19
|
+
Shipcloud.should_receive(:request).
|
20
|
+
with(:post, "webhooks", valid_attributes).
|
21
|
+
and_return("data" => {})
|
22
|
+
Shipcloud::Webhook.create(valid_attributes)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".find" do
|
27
|
+
it "makes a new GET request using the correct API endpoint to receive a specific webhook" do
|
28
|
+
Shipcloud.should_receive(:request).with(:get, "webhooks/123", {}).and_return("id" => "123")
|
29
|
+
Shipcloud::Webhook.find("123")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".all" do
|
34
|
+
it "makes a new Get request using the correct API endpoint" do
|
35
|
+
expect(Shipcloud).to receive(:request).
|
36
|
+
with(:get, "webhooks", {}).
|
37
|
+
and_return("webhooks" => [])
|
38
|
+
|
39
|
+
Shipcloud::Webhook.all
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns a list of Webhook objects" do
|
43
|
+
stub_webhooks_request
|
44
|
+
|
45
|
+
webhooks = Shipcloud::Webhook.all
|
46
|
+
|
47
|
+
webhooks.each do |webhook|
|
48
|
+
expect(webhook).to be_a Shipcloud::Webhook
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def stub_webhooks_request
|
54
|
+
allow(Shipcloud).to receive(:request).
|
55
|
+
with(:get, "webhooks", {}).
|
56
|
+
and_return("webhooks" => webhooks_array)
|
57
|
+
end
|
58
|
+
|
59
|
+
def webhooks_array
|
60
|
+
[
|
61
|
+
{
|
62
|
+
"id" => "583cfd8b-77c7-4447-a3a0-1568bb9cc553",
|
63
|
+
"url" => "https://example.com/webhook",
|
64
|
+
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
|
65
|
+
"deactivated" => false
|
66
|
+
},
|
67
|
+
{
|
68
|
+
"id" => "e0ff4250-6c8e-494d-a069-afd9d566e372",
|
69
|
+
"url" => "https://example.com/webhook",
|
70
|
+
"event_types" => ["shipment.tracking.delayed", "shipment.tracking.delivered"],
|
71
|
+
"deactivated" => false
|
72
|
+
}
|
73
|
+
]
|
74
|
+
end
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
1
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
3
6
|
require 'shipcloud'
|
@@ -5,6 +8,8 @@ require 'rspec'
|
|
5
8
|
require "webmock/rspec"
|
6
9
|
require "pry"
|
7
10
|
|
11
|
+
WebMock.disable_net_connect!(allow_localhost: true, allow: "codeclimate.com")
|
12
|
+
|
8
13
|
RSpec.configure do |config|
|
9
14
|
config.after(:each) do
|
10
15
|
Shipcloud.api_key = nil
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sthollmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -106,21 +106,41 @@ dependencies:
|
|
106
106
|
- - "~>"
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0.10'
|
109
|
-
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: codeclimate-test-reporter
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
description: A wrapper for the shipcloud API. Fore more details visit https://developers.shipcloud.io/
|
110
124
|
email:
|
111
125
|
- stefan@shipcloud.io
|
112
126
|
executables: []
|
113
127
|
extensions: []
|
114
128
|
extra_rdoc_files: []
|
115
129
|
files:
|
130
|
+
- ".codeclimate.yml"
|
116
131
|
- ".gitignore"
|
132
|
+
- ".hound.yml"
|
117
133
|
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".ruby-style.yml"
|
118
136
|
- ".travis.yml"
|
137
|
+
- CHANGELOG.md
|
119
138
|
- Gemfile
|
120
139
|
- LICENSE.txt
|
121
140
|
- README.md
|
122
141
|
- Rakefile
|
123
142
|
- lib/shipcloud.rb
|
143
|
+
- lib/shipcloud/address.rb
|
124
144
|
- lib/shipcloud/base.rb
|
125
145
|
- lib/shipcloud/carrier.rb
|
126
146
|
- lib/shipcloud/operations/all.rb
|
@@ -133,13 +153,18 @@ files:
|
|
133
153
|
- lib/shipcloud/request/info.rb
|
134
154
|
- lib/shipcloud/request/validator.rb
|
135
155
|
- lib/shipcloud/shipment.rb
|
156
|
+
- lib/shipcloud/shipment_quote.rb
|
136
157
|
- lib/shipcloud/version.rb
|
158
|
+
- lib/shipcloud/webhook.rb
|
137
159
|
- shipcloud.gemspec
|
160
|
+
- spec/shipcloud/address_spec.rb
|
138
161
|
- spec/shipcloud/carrier_spec.rb
|
139
162
|
- spec/shipcloud/request/base_spec.rb
|
140
163
|
- spec/shipcloud/request/connection_spec.rb
|
141
164
|
- spec/shipcloud/request/validator_spec.rb
|
165
|
+
- spec/shipcloud/shipment_quote_spec.rb
|
142
166
|
- spec/shipcloud/shipment_spec.rb
|
167
|
+
- spec/shipcloud/webhooks_spec.rb
|
143
168
|
- spec/shipcloud_spec.rb
|
144
169
|
- spec/spec_helper.rb
|
145
170
|
homepage: https://github.com/shipcloud/shipcloud-ruby
|
@@ -154,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
179
|
requirements:
|
155
180
|
- - ">="
|
156
181
|
- !ruby/object:Gem::Version
|
157
|
-
version: '0'
|
182
|
+
version: '2.0'
|
158
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
184
|
requirements:
|
160
185
|
- - ">="
|
@@ -162,15 +187,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
187
|
version: '0'
|
163
188
|
requirements: []
|
164
189
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.
|
190
|
+
rubygems_version: 2.5.1
|
166
191
|
signing_key:
|
167
192
|
specification_version: 4
|
168
193
|
summary: A wrapper for the shipcloud API
|
169
194
|
test_files:
|
195
|
+
- spec/shipcloud/address_spec.rb
|
170
196
|
- spec/shipcloud/carrier_spec.rb
|
171
197
|
- spec/shipcloud/request/base_spec.rb
|
172
198
|
- spec/shipcloud/request/connection_spec.rb
|
173
199
|
- spec/shipcloud/request/validator_spec.rb
|
200
|
+
- spec/shipcloud/shipment_quote_spec.rb
|
174
201
|
- spec/shipcloud/shipment_spec.rb
|
202
|
+
- spec/shipcloud/webhooks_spec.rb
|
175
203
|
- spec/shipcloud_spec.rb
|
176
204
|
- spec/spec_helper.rb
|