shipcloud 0.6.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +1 -0
  3. data/.hound.yml +1 -1
  4. data/.rubocop.yml +713 -2
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +18 -6
  7. data/CHANGELOG.md +70 -0
  8. data/README.md +76 -8
  9. data/bin/rubocop +29 -0
  10. data/install-cc-test-reporter.sh +4 -0
  11. data/lib/shipcloud.rb +28 -14
  12. data/lib/shipcloud/address.rb +2 -1
  13. data/lib/shipcloud/operations/all.rb +12 -2
  14. data/lib/shipcloud/operations/create.rb +10 -2
  15. data/lib/shipcloud/operations/delete.rb +10 -2
  16. data/lib/shipcloud/operations/find.rb +10 -2
  17. data/lib/shipcloud/operations/update.rb +12 -4
  18. data/lib/shipcloud/pickup_request.rb +12 -0
  19. data/lib/shipcloud/request/base.rb +14 -10
  20. data/lib/shipcloud/request/connection.rb +18 -12
  21. data/lib/shipcloud/request/info.rb +7 -5
  22. data/lib/shipcloud/shipcloud_error.rb +70 -0
  23. data/lib/shipcloud/shipment.rb +3 -2
  24. data/lib/shipcloud/tracker.rb +13 -0
  25. data/lib/shipcloud/version.rb +1 -1
  26. data/lib/shipcloud/webhook.rb +2 -1
  27. data/shipcloud.gemspec +9 -8
  28. data/spec/shipcloud/address_spec.rb +114 -43
  29. data/spec/shipcloud/carrier_spec.rb +12 -5
  30. data/spec/shipcloud/pickup_request_spec.rb +136 -0
  31. data/spec/shipcloud/request/base_spec.rb +51 -13
  32. data/spec/shipcloud/request/connection_spec.rb +3 -3
  33. data/spec/shipcloud/request/info_spec.rb +34 -0
  34. data/spec/shipcloud/shipcloud_error_spec.rb +125 -0
  35. data/spec/shipcloud/shipment_quote_spec.rb +14 -1
  36. data/spec/shipcloud/shipment_spec.rb +126 -11
  37. data/spec/shipcloud/tracker_spec.rb +141 -0
  38. data/spec/shipcloud/webhooks_spec.rb +70 -6
  39. data/spec/shipcloud_spec.rb +82 -20
  40. data/spec/spec_helper.rb +2 -2
  41. metadata +55 -43
  42. data/.ruby-style.yml +0 -240
  43. data/lib/shipcloud/request/validator.rb +0 -33
  44. data/spec/shipcloud/request/validator_spec.rb +0 -24
@@ -0,0 +1 @@
1
+ 2.6.6
@@ -1,15 +1,27 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
- - 2.0.0
5
- - 2.1.7
6
- - 2.2.4
7
- - 2.3.0
8
- - jruby-9.0.0.0
9
- - rbx-2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - ruby-head
10
+ - jruby
11
+ - rbx
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: rbx
16
+ - rvm: jruby
10
17
  notifications:
11
18
  flowdock:
12
19
  secure: fSZxX5z3bHWT8aCFKBFrDDt5o3Jb6EFWcm+pAcMabpfDHc4iktWuCUlSM405798TRdKdws1A2RncQGYiQyLbqNvtLz48dvj4BxgYW7P/vg0koN+I/H2MjpZeuIQ7BRSEJIq2sAYNVya+hSil+SPEBMTngJiP6VYG0dm6fFnRkyk=
13
20
  addons:
14
21
  code_climate:
15
22
  repo_token: 704eb62133d951ce460a6047a15a58e0a521aa20ec6a533fa7a37585f8a75602
23
+ before_script:
24
+ - ./install-cc-test-reporter.sh
25
+ - ./cc-test-reporter before-build
26
+ after_script:
27
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,3 +1,73 @@
1
+ ## [0.11.0] - 2020-07-28
2
+ ### Added
3
+ - Support shipments with pickup requests as required for [TNT](https://developers.shipcloud.io/carriers/tnt.html).
4
+ - Add attr_accessor for `email` to class `Shipcloud::Address` to be able to access the email attribute at the address object.
5
+
6
+ ### Changed
7
+
8
+ ### Deprecated
9
+
10
+ ### Removed
11
+
12
+ ### Fixed
13
+
14
+ ### Security
15
+
16
+ ## [Unreleased]
17
+ ### Added
18
+
19
+ ### Changed
20
+
21
+ ### Deprecated
22
+
23
+ ### Removed
24
+
25
+ ### Fixed
26
+
27
+ ### Security
28
+
29
+ ## [0.10.0] - 2019-08-07
30
+ ### Added
31
+ - Add the possibility to specify custom affiliate_id on every request
32
+
33
+ ### Removed
34
+ - Removed support for ruby < 2.3. Target ruby version is 2.6
35
+
36
+ ## [0.9.0] - 2019-01-09
37
+ ### Added
38
+ - Add attr_reader for `id` to class `Shipcloud::Address` to be able to get the id of a created address
39
+ - Add attr_reader for `id` to class `Shipcloud::Webhook` to be able to get the id of a created webhook
40
+ - Add attr_reader for `customs_declaration` to class `Shipcloud::Shipment` to be able to get the `customs_declaration` of a created shipment
41
+
42
+ ## [0.8.0] - 2017-07-03
43
+ ### Added
44
+ - Add attribute ```metadata``` to class ```Shipcloud::Shipment``` in order to transmit JSON data (#16).
45
+ - Add resource pickup_request in order to submit pickup request to shipcloud
46
+ - Add attribute ```pickup_address``` to class ```Shipcloud::PickupRequest``` to submit an alternative address for pickup request to shipcloud
47
+ - Add ```delete``` operation for ```webhook``` resource
48
+ - Add attribute ```deactivated``` to class ```Shipcloud::Webhook```
49
+ - Add ```affiliate_id``` to ```Shipcloud::Configuration``` and submit it (or a default affiliate id) via API headers to shipcloud
50
+ - Add class ```Shipcloud::Tracker``` with create, find, and index operations
51
+
52
+ ### Fixed
53
+ - Parse response only when it is not empty
54
+
55
+ ## [0.7.0] - 2016-01-21
56
+ ### Added
57
+ - Add the possibility to specify the api key on every request. (#8)
58
+ - Add some more specific error classes ```Shipcloud::ClientError```,```Shipcloud::ServerError```,
59
+ ```Shipcloud::InvalidRequestError```, ```Shipcloud::TooManyRequests``` and ```Shipcloud::NotFoundError``` (#11).
60
+ - Access to the entire response and error descriptions from the error object (#11).
61
+
62
+ ### Removed
63
+ - Removed the following ruby versions from travis-ci test runs:
64
+ - jruby-9.0.0.0
65
+ - Removed ```Shipcloud::APIError``` in preference to more granular error classes (#11).
66
+
67
+ ### Changed
68
+
69
+ ### Fixed
70
+
1
71
  ## [0.6.0] - 2016-01-21
2
72
  ### Added
3
73
  - This CHANGELOG file (Following "[Keep a CHANGELOG](http://keepachangelog.com/)")
data/README.md CHANGED
@@ -1,9 +1,11 @@
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)
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)
2
2
 
3
3
  # shipcloud
4
4
 
5
5
  A Ruby wrapper for the shipcloud API
6
6
 
7
+ We have dropped the support of jruby-9, because there is an issue with mixing hash and keyword arguments (https://github.com/jruby/jruby/issues/3138). When this issue is fixed, we will support jruby-9 again.
8
+
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
@@ -20,27 +22,42 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- Before using the shipcloud API, you need to set the API access key:
25
+ Before using the shipcloud API, you may want to set the API access key.
24
26
 
25
- ```
27
+ ```ruby
26
28
  Shipcloud.api_key = 'your-api-key-goes-here'
27
29
  ```
28
30
 
29
31
  Since Version 0.4.0, you can also do this via a configuration block, e.g. in an initializer:
30
32
 
31
- ```
33
+ ```ruby
32
34
  Shipcloud.configure do |config|
33
35
  config.api_key = 'your-api-key-goes-here'
34
36
  end
35
37
  ```
36
38
 
39
+ You can also pass the API key with each request:
40
+ ```ruby
41
+ Shipcloud::Shipment.create(
42
+ {
43
+ carrier: 'ups',
44
+ from: from-address-params,
45
+ to: to-address-params,
46
+ package: package-params,
47
+ create_shipping_label: true
48
+ },
49
+ api_key: "your-api-key"
50
+ )
51
+ ```
52
+ If you pass in the ```api_key``` option, the value will be used as API key for the current request, even if you have set the ```Shipcloud.api_key``` before.
53
+
37
54
  You can sign up for a developer account at *[shipcloud.io](http://www.shipcloud.io)*
38
55
 
39
56
  ### Create a new shipment
40
57
 
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.
58
+ To create a new Shipment on the shipcloud platform, you need to provide the name of the carrier, to- and from-address, and the package dimensions.
42
59
  For details, see *[shipcloud API documentation on Shipments](http://developers.shipcloud.io/reference/#shipments)*
43
- ```
60
+ ```ruby
44
61
  Shipcloud::Shipment.create(
45
62
  carrier: 'ups',
46
63
  from: from-address-params,
@@ -52,14 +69,28 @@ Shipcloud::Shipment.create(
52
69
 
53
70
  `Shipment#create` will return shipping label and tracking information, encapsulated in a `Shipcloud::Shipment` object:
54
71
 
55
- ```
72
+ ```ruby
56
73
  shipment = Shipcloud::Shipment.create(...) # parameters ommitted
57
74
  shipment.tracking_url # -> http://track.shipcloud.io/uzdgu22z3ed12
58
75
  ```
59
76
 
77
+ ### Get a list of shipments
78
+
79
+ You can get a list of all shipments from the shipcloud platform. Shipments can be filtered by providing optional parameters. For more information and a list of valid parameters see *[shipcloud API documentation on Shipments Index](https://developers.shipcloud.io/reference/#getting-a-list-of-shipments)*
80
+
81
+ ```ruby
82
+ Shipcloud::Shipment.all(
83
+ carrier: 'ups',
84
+ per_page: 25,
85
+ page: 2
86
+ )
87
+ ```
88
+
89
+ `Shipment#all` will return an array of `Shipcloud::Shipment` objects, matching the given parameters.
90
+
60
91
  ### Get a shipment quote
61
92
 
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.
93
+ To get a shipment qoute from the shipcloud platform, you need to provide the name of the carrier, the service, to- and from-address, and the package dimensions.
63
94
  For details, see *[shipcloud API documentation on shipment quotes](https://developers.shipcloud.io/reference/#shipment-quotes)*
64
95
 
65
96
  ```ruby
@@ -91,6 +122,43 @@ shipment_quote = Shipcloud::ShipmentQuote.create(
91
122
  shipment_quote.price # => 6.2
92
123
  ```
93
124
 
125
+ ### Create a pickup request
126
+
127
+ To request parcels being picked up, you need to provide the carrier name and the time (earliest and latest) your shipments shall be fetched.
128
+
129
+ ```ruby
130
+ pickup_request = Shipcloud::PickupRequest.create(
131
+ carrier: 'dpd',
132
+ pickup_time: {
133
+ earliest: "2016-04-04T09:00:00+02:00",
134
+ latest: "2016-04-04T18:00:00+02:00"
135
+ }
136
+ )
137
+
138
+ pickup_request.id # => "dje892dj20d2odj20"
139
+ pickup_request.carrier_pickup_number # => "12345"
140
+ ```
141
+
142
+ You may also provide a list of shipment ids to specify only certain shipments to be included in the pickup request.
143
+
144
+ ```ruby
145
+ pickup_request = Shipcloud::PickupRequest.create(
146
+ carrier: 'dpd',
147
+ pickup_time: {
148
+ earliest: "2016-04-04T09:00:00+02:00",
149
+ latest: "2016-04-04T18:00:00+02:00"
150
+ },
151
+ shipments: [
152
+ { id: "abc_123"}
153
+ ]
154
+ )
155
+
156
+ pickup_request.id # => "dje892dj20d2odj20"
157
+ pickup_request.carrier_pickup_number # => "12345"
158
+ ```
159
+
160
+
161
+
94
162
  ## Contributing
95
163
 
96
164
  1. Fork it
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+
3
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
4
+ chmod +x ./cc-test-reporter
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require "net/http"
2
3
  require "net/https"
3
4
  require "json"
4
5
  require "shipcloud/version"
6
+ require "shipcloud/shipcloud_error"
5
7
 
6
8
  module Shipcloud
7
9
  API_VERSION = "v1"
@@ -9,16 +11,19 @@ module Shipcloud
9
11
 
10
12
  API_HEADERS = {
11
13
  "Content-Type" => "application/json",
12
- "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, #{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}"
13
- }
14
+ "User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
15
+ "#{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}",
16
+ }.freeze
14
17
 
15
- @@api_key = nil
18
+ DEFAULT_AFFILIATE_ID = "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}"
16
19
 
17
20
  autoload :Base, "shipcloud/base"
18
21
  autoload :Shipment, "shipcloud/shipment"
19
22
  autoload :Carrier, "shipcloud/carrier"
20
23
  autoload :Address, "shipcloud/address"
24
+ autoload :PickupRequest, "shipcloud/pickup_request"
21
25
  autoload :ShipmentQuote, "shipcloud/shipment_quote"
26
+ autoload :Tracker, "shipcloud/tracker"
22
27
  autoload :Webhook, "shipcloud/webhook"
23
28
 
24
29
  module Operations
@@ -33,32 +38,34 @@ module Shipcloud
33
38
  autoload :Base, "shipcloud/request/base"
34
39
  autoload :Connection, "shipcloud/request/connection"
35
40
  autoload :Info, "shipcloud/request/info"
36
- autoload :Validator, "shipcloud/request/validator"
37
41
  end
38
42
 
39
- class ShipcloudError < StandardError; end
40
- class AuthenticationError < ShipcloudError; end
41
- class APIError < ShipcloudError; end
42
-
43
43
  class << self
44
- attr_accessor :configuration
44
+ attr_writer :configuration
45
45
  end
46
46
 
47
+ # rubocop:disable Naming/MemoizedInstanceVariableName
47
48
  def self.configuration
48
49
  @configuration ||= Configuration.new
49
50
  end
51
+ # rubocop:enable Naming/MemoizedInstanceVariableName
50
52
 
51
53
  def self.configure
52
54
  yield(configuration)
53
55
  end
54
56
 
57
+ def self.api_headers
58
+ API_HEADERS.merge(
59
+ "Affiliate-ID" => affiliate_id,
60
+ )
61
+ end
55
62
 
56
63
  class Configuration
57
- attr_accessor :api_key, :api_base, :use_ssl, :debug
64
+ attr_accessor :affiliate_id, :api_key, :api_base, :use_ssl, :debug
58
65
 
59
66
  def initialize
60
67
  @api_key = nil
61
- @api_base = 'api.shipcloud.io'
68
+ @api_base = "api.shipcloud.io"
62
69
  @use_ssl = true
63
70
  @debug = false
64
71
  end
@@ -75,18 +82,25 @@ module Shipcloud
75
82
  #
76
83
  # @param [String] api_key The api key
77
84
  def self.api_key=(api_key)
78
- @@api_key = api_key
79
85
  configuration.api_key = api_key
80
86
  end
81
87
 
88
+ def self.affiliate_id
89
+ configuration.affiliate_id || DEFAULT_AFFILIATE_ID
90
+ end
91
+
82
92
  # Makes a request against the shipcloud API
83
93
  #
84
94
  # @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
85
95
  # @param [String] api_url The API url to use
86
96
  # @param [Hash] data The data to send, e.g. used when creating new objects.
97
+ # @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key will
98
+ # be used for the request
87
99
  # @return [Array] The parsed JSON response.
88
- def self.request(http_method, api_url, data)
89
- info = Request::Info.new(http_method, api_url, data)
100
+ def self.request(http_method, api_url, data, api_key: nil, affiliate_id: nil)
101
+ api_key ||= Shipcloud.api_key
102
+ affiliate_id ||= Shipcloud.affiliate_id
103
+ info = Request::Info.new(http_method, api_url, api_key, data, affiliate_id)
90
104
  Request::Base.new(info).perform
91
105
  end
92
106
  end
@@ -3,8 +3,9 @@ module Shipcloud
3
3
  include Shipcloud::Operations::Update
4
4
  include Shipcloud::Operations::All
5
5
 
6
- attr_accessor :company, :first_name, :last_name, :care_of, :street,
6
+ attr_accessor :company, :first_name, :last_name, :care_of, :street, :email,
7
7
  :street_no, :zip_code, :city, :state, :country, :phone
8
+ attr_reader :id
8
9
 
9
10
  def self.base_url
10
11
  "#{class_name.downcase}es"
@@ -3,8 +3,18 @@ module Shipcloud
3
3
  module All
4
4
  module ClassMethods
5
5
  # Loads all Objects of the resource
6
- def all(filter = {})
7
- response = Shipcloud.request(:get, base_url, filter)
6
+ # @param [Hash] optional filter Filter the shipments list using one or more filter
7
+ # creteria
8
+ # @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key
9
+ # will be used for the request
10
+ def all(filter = {}, api_key: nil, affiliate_id: nil)
11
+ response = Shipcloud.request(
12
+ :get,
13
+ base_url,
14
+ filter,
15
+ api_key: api_key,
16
+ affiliate_id: affiliate_id,
17
+ )
8
18
  if index_response_root
9
19
  response = response.fetch(index_response_root, [])
10
20
  end
@@ -5,8 +5,16 @@ module Shipcloud
5
5
  # Creates a new object
6
6
  #
7
7
  # @param [Hash] attributes The attributes of the created object
8
- def create(attributes)
9
- response = Shipcloud.request(:post, base_url, attributes)
8
+ # @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
9
+ # will be used for the request
10
+ def create(attributes, api_key: nil, affiliate_id: nil)
11
+ response = Shipcloud.request(
12
+ :post,
13
+ base_url,
14
+ attributes,
15
+ api_key: api_key,
16
+ affiliate_id: affiliate_id,
17
+ )
10
18
  if create_response_root
11
19
  response = response.fetch(create_response_root, {})
12
20
  end
@@ -5,8 +5,16 @@ module Shipcloud
5
5
  # Deletes the given object
6
6
  #
7
7
  # @param [String] id The id of the object that gets deleted
8
- def delete(id)
9
- response = Shipcloud.request(:delete, "#{base_url}/#{id}", {})
8
+ # @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
9
+ # will be used for the request
10
+ def delete(id, api_key: nil, affiliate_id: nil)
11
+ Shipcloud.request(
12
+ :delete,
13
+ "#{base_url}/#{id}",
14
+ {},
15
+ api_key: api_key,
16
+ affiliate_id: affiliate_id,
17
+ )
10
18
  true
11
19
  end
12
20
  end