shipcloud 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +17 -9
- data/.ruby-version +1 -1
- data/.travis.yml +0 -1
- data/CHANGELOG.md +7 -0
- data/bin/rubocop +29 -0
- data/lib/shipcloud.rb +17 -8
- data/lib/shipcloud/operations/all.rb +8 -2
- data/lib/shipcloud/operations/create.rb +8 -2
- data/lib/shipcloud/operations/delete.rb +8 -2
- data/lib/shipcloud/operations/find.rb +8 -2
- data/lib/shipcloud/operations/update.rb +8 -4
- data/lib/shipcloud/request/base.rb +3 -0
- data/lib/shipcloud/request/connection.rb +6 -5
- data/lib/shipcloud/request/info.rb +7 -6
- data/lib/shipcloud/shipcloud_error.rb +2 -0
- data/lib/shipcloud/version.rb +1 -1
- data/shipcloud.gemspec +6 -4
- data/spec/shipcloud/address_spec.rb +45 -7
- data/spec/shipcloud/carrier_spec.rb +10 -3
- data/spec/shipcloud/pickup_request_spec.rb +14 -1
- data/spec/shipcloud/request/base_spec.rb +9 -7
- data/spec/shipcloud/request/info_spec.rb +9 -3
- data/spec/shipcloud/shipment_quote_spec.rb +14 -1
- data/spec/shipcloud/shipment_spec.rb +54 -8
- data/spec/shipcloud/tracker_spec.rb +30 -5
- data/spec/shipcloud/webhooks_spec.rb +36 -7
- data/spec/shipcloud_spec.rb +17 -18
- metadata +43 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f3bf2ce4eed19aeb58efbeb8f94eec7e530564c8a576ef027a7c6d86f6e0317
|
4
|
+
data.tar.gz: e8c7ee9e7f832462d45889310890b38919d0edbde40c06d6c6837aafe0fc4d56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e488aa7992b5fd65a6b267d29e9b638d3256f453b16236e99195a85dd17fd5437ca5c03ec81a2ad0332ae593f8fb816da889d3dddcffbe7807fcdec2336c178c
|
7
|
+
data.tar.gz: 840df4369680ec64f38cbaeb5e5df4c223f641d7b1145a74fafba5f8ee40e6b6713d99599dd881781550690482a50debe1535c2edde3342d8ec9af3c8e7c35d0
|
data/.codeclimate.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
|
1
3
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.6
|
3
5
|
Exclude:
|
4
6
|
- vendor/**/*
|
7
|
+
- bin/*
|
5
8
|
|
6
9
|
Naming/AccessorMethodName:
|
7
10
|
Description: Check the naming of accessor methods for get_/set_.
|
@@ -39,6 +42,11 @@ Naming/PredicateName:
|
|
39
42
|
Exclude:
|
40
43
|
- spec/**/*
|
41
44
|
|
45
|
+
Naming/RescuedExceptionsVariableName:
|
46
|
+
Description: 'Use consistent rescued exceptions variables naming.'
|
47
|
+
Enabled: true
|
48
|
+
PreferredName: error
|
49
|
+
|
42
50
|
Style/Alias:
|
43
51
|
Description: 'Use alias_method instead of alias.'
|
44
52
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#alias-method'
|
@@ -133,7 +141,7 @@ Style/EvenOdd:
|
|
133
141
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods'
|
134
142
|
Enabled: false
|
135
143
|
|
136
|
-
|
144
|
+
Lint/FlipFlop:
|
137
145
|
Description: 'Checks for flip flops'
|
138
146
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops'
|
139
147
|
Enabled: false
|
@@ -266,6 +274,13 @@ Style/RegexpLiteral:
|
|
266
274
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#percent-r'
|
267
275
|
Enabled: false
|
268
276
|
|
277
|
+
Style/Sample:
|
278
|
+
Description: >-
|
279
|
+
Use `sample` instead of `shuffle.first`,
|
280
|
+
`shuffle.last`, and `shuffle[Fixnum]`.
|
281
|
+
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
282
|
+
Enabled: false
|
283
|
+
|
269
284
|
Style/SelfAssignment:
|
270
285
|
Description: >-
|
271
286
|
Checks for places where self-assignment shorthand should have
|
@@ -626,13 +641,6 @@ Performance/ReverseEach:
|
|
626
641
|
Reference: 'https://github.com/JuanitoFatas/fast-ruby#enumerablereverseeach-vs-enumerablereverse_each-code'
|
627
642
|
Enabled: false
|
628
643
|
|
629
|
-
Performance/Sample:
|
630
|
-
Description: >-
|
631
|
-
Use `sample` instead of `shuffle.first`,
|
632
|
-
`shuffle.last`, and `shuffle[Fixnum]`.
|
633
|
-
Reference: 'https://github.com/JuanitoFatas/fast-ruby#arrayshufflefirst-vs-arraysample-code'
|
634
|
-
Enabled: false
|
635
|
-
|
636
644
|
Performance/Size:
|
637
645
|
Description: >-
|
638
646
|
Use `size` instead of `count` for counting
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,13 @@
|
|
11
11
|
|
12
12
|
### Security
|
13
13
|
|
14
|
+
## [0.10.0] - 2019-08-07
|
15
|
+
### Added
|
16
|
+
- Add the possibility to specify custom affiliate_id on every request
|
17
|
+
|
18
|
+
### Removed
|
19
|
+
- Removed support for ruby < 2.3. Target ruby version is 2.6
|
20
|
+
|
14
21
|
## [0.9.0] - 2019-01-09
|
15
22
|
### Added
|
16
23
|
- Add attr_reader for `id` to class `Shipcloud::Address` to be able to get the id of a created address
|
data/bin/rubocop
ADDED
@@ -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")
|
data/lib/shipcloud.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require "net/http"
|
2
3
|
require "net/https"
|
3
4
|
require "json"
|
@@ -10,10 +11,11 @@ module Shipcloud
|
|
10
11
|
|
11
12
|
API_HEADERS = {
|
12
13
|
"Content-Type" => "application/json",
|
13
|
-
"User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION},
|
14
|
-
|
14
|
+
"User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
|
15
|
+
"#{RUBY_VERSION}, #{RUBY_PLATFORM}, #{RUBY_PATCHLEVEL}",
|
16
|
+
}.freeze
|
15
17
|
|
16
|
-
DEFAULT_AFFILIATE_ID = "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}"
|
18
|
+
DEFAULT_AFFILIATE_ID = "integration.shipcloud-ruby-gem.v#{Shipcloud::VERSION}"
|
17
19
|
|
18
20
|
autoload :Base, "shipcloud/base"
|
19
21
|
autoload :Shipment, "shipcloud/shipment"
|
@@ -39,12 +41,14 @@ module Shipcloud
|
|
39
41
|
end
|
40
42
|
|
41
43
|
class << self
|
42
|
-
|
44
|
+
attr_writer :configuration
|
43
45
|
end
|
44
46
|
|
47
|
+
# rubocop:disable Naming/MemoizedInstanceVariableName
|
45
48
|
def self.configuration
|
46
49
|
@configuration ||= Configuration.new
|
47
50
|
end
|
51
|
+
# rubocop:enable Naming/MemoizedInstanceVariableName
|
48
52
|
|
49
53
|
def self.configure
|
50
54
|
yield(configuration)
|
@@ -52,7 +56,7 @@ module Shipcloud
|
|
52
56
|
|
53
57
|
def self.api_headers
|
54
58
|
API_HEADERS.merge(
|
55
|
-
"Affiliate-ID" =>
|
59
|
+
"Affiliate-ID" => affiliate_id,
|
56
60
|
)
|
57
61
|
end
|
58
62
|
|
@@ -61,7 +65,7 @@ module Shipcloud
|
|
61
65
|
|
62
66
|
def initialize
|
63
67
|
@api_key = nil
|
64
|
-
@api_base =
|
68
|
+
@api_base = "api.shipcloud.io"
|
65
69
|
@use_ssl = true
|
66
70
|
@debug = false
|
67
71
|
end
|
@@ -81,6 +85,10 @@ module Shipcloud
|
|
81
85
|
configuration.api_key = api_key
|
82
86
|
end
|
83
87
|
|
88
|
+
def self.affiliate_id
|
89
|
+
configuration.affiliate_id || DEFAULT_AFFILIATE_ID
|
90
|
+
end
|
91
|
+
|
84
92
|
# Makes a request against the shipcloud API
|
85
93
|
#
|
86
94
|
# @param [Symbol] http_method The http method to use, must be one of :get, :post, :put and :delete
|
@@ -89,9 +97,10 @@ module Shipcloud
|
|
89
97
|
# @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key will
|
90
98
|
# be used for the request
|
91
99
|
# @return [Array] The parsed JSON response.
|
92
|
-
def self.request(http_method, api_url, data, api_key: nil)
|
100
|
+
def self.request(http_method, api_url, data, api_key: nil, affiliate_id: nil)
|
93
101
|
api_key ||= Shipcloud.api_key
|
94
|
-
|
102
|
+
affiliate_id ||= Shipcloud.affiliate_id
|
103
|
+
info = Request::Info.new(http_method, api_url, api_key, data, affiliate_id)
|
95
104
|
Request::Base.new(info).perform
|
96
105
|
end
|
97
106
|
end
|
@@ -7,8 +7,14 @@ module Shipcloud
|
|
7
7
|
# creteria
|
8
8
|
# @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
9
9
|
# will be used for the request
|
10
|
-
def all(filter = {}, api_key: nil)
|
11
|
-
response = Shipcloud.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
|
+
)
|
12
18
|
if index_response_root
|
13
19
|
response = response.fetch(index_response_root, [])
|
14
20
|
end
|
@@ -7,8 +7,14 @@ module Shipcloud
|
|
7
7
|
# @param [Hash] attributes The attributes of the created object
|
8
8
|
# @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
9
9
|
# will be used for the request
|
10
|
-
def create(attributes, api_key: nil)
|
11
|
-
response = Shipcloud.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
|
+
)
|
12
18
|
if create_response_root
|
13
19
|
response = response.fetch(create_response_root, {})
|
14
20
|
end
|
@@ -7,8 +7,14 @@ module Shipcloud
|
|
7
7
|
# @param [String] id The id of the object that gets deleted
|
8
8
|
# @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
9
9
|
# will be used for the request
|
10
|
-
def delete(id, api_key: nil)
|
11
|
-
Shipcloud.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
|
+
)
|
12
18
|
true
|
13
19
|
end
|
14
20
|
end
|
@@ -8,8 +8,14 @@ module Shipcloud
|
|
8
8
|
# @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
9
9
|
# will be used for the request
|
10
10
|
# @return [Shipcloud::Base] The found object
|
11
|
-
def find(id, api_key: nil)
|
12
|
-
response = Shipcloud.request(
|
11
|
+
def find(id, api_key: nil, affiliate_id: nil)
|
12
|
+
response = Shipcloud.request(
|
13
|
+
:get,
|
14
|
+
"#{base_url}/#{id}",
|
15
|
+
{},
|
16
|
+
api_key: api_key,
|
17
|
+
affiliate_id: affiliate_id,
|
18
|
+
)
|
13
19
|
self.new(response)
|
14
20
|
end
|
15
21
|
end
|
@@ -8,8 +8,10 @@ module Shipcloud
|
|
8
8
|
# @param [Hash] attributes The attributes that should be updated
|
9
9
|
# @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
10
10
|
# will be used for the request
|
11
|
-
def update(id, attributes, api_key: nil)
|
12
|
-
response = Shipcloud.request(
|
11
|
+
def update(id, attributes, api_key: nil, affiliate_id: nil)
|
12
|
+
response = Shipcloud.request(
|
13
|
+
:put, "#{base_url}/#{id}", attributes, api_key: api_key, affiliate_id: affiliate_id
|
14
|
+
)
|
13
15
|
self.new(response)
|
14
16
|
end
|
15
17
|
end
|
@@ -23,8 +25,10 @@ module Shipcloud
|
|
23
25
|
# @param [Hash] attributes The attributes that should be updated
|
24
26
|
# @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
|
25
27
|
# will be used for the request
|
26
|
-
def update(attributes, api_key: nil)
|
27
|
-
response = Shipcloud.request(
|
28
|
+
def update(attributes, api_key: nil, affiliate_id: nil)
|
29
|
+
response = Shipcloud.request(
|
30
|
+
:put, "#{base_url}/#{id}", attributes, api_key: api_key, affiliate_id: affiliate_id
|
31
|
+
)
|
28
32
|
set_attributes(response)
|
29
33
|
end
|
30
34
|
end
|
@@ -9,6 +9,7 @@ module Shipcloud
|
|
9
9
|
|
10
10
|
def perform
|
11
11
|
raise AuthenticationError unless @info.api_key
|
12
|
+
|
12
13
|
connection.setup_https
|
13
14
|
response = connection.request
|
14
15
|
validate_response(response)
|
@@ -26,9 +27,11 @@ module Shipcloud
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
30
|
+
# rubocop:disable Naming/MemoizedInstanceVariableName
|
29
31
|
def connection
|
30
32
|
@connection ||= Connection.new(info)
|
31
33
|
end
|
34
|
+
# rubocop:enable Naming/MemoizedInstanceVariableName
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -20,7 +20,7 @@ module Shipcloud
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def request
|
23
|
-
https.start do
|
23
|
+
https.start do
|
24
24
|
https.request(https_request)
|
25
25
|
end
|
26
26
|
end
|
@@ -28,18 +28,19 @@ module Shipcloud
|
|
28
28
|
protected
|
29
29
|
|
30
30
|
def https_request
|
31
|
+
headers = Shipcloud.api_headers.merge("Affiliate-ID" => @info.affiliate_id)
|
31
32
|
https_request =
|
32
33
|
case @info.http_method
|
33
34
|
when :post
|
34
|
-
Net::HTTP::Post.new(@info.url,
|
35
|
+
Net::HTTP::Post.new(@info.url, headers)
|
35
36
|
when :put
|
36
|
-
Net::HTTP::Put.new(@info.url,
|
37
|
+
Net::HTTP::Put.new(@info.url, headers)
|
37
38
|
when :delete
|
38
|
-
Net::HTTP::Delete.new(@info.url,
|
39
|
+
Net::HTTP::Delete.new(@info.url, headers)
|
39
40
|
else
|
40
41
|
Net::HTTP::Get.new(
|
41
42
|
@info.path_with_params(@info.url, @info.data),
|
42
|
-
|
43
|
+
headers,
|
43
44
|
)
|
44
45
|
end
|
45
46
|
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module Shipcloud
|
2
2
|
module Request
|
3
3
|
class Info
|
4
|
-
attr_accessor :http_method, :api_url, :api_key, :data
|
4
|
+
attr_accessor :http_method, :api_url, :api_key, :data, :affiliate_id
|
5
5
|
|
6
|
-
def initialize(http_method, api_url, api_key, data)
|
7
|
-
@api_key
|
8
|
-
@http_method
|
9
|
-
@api_url
|
10
|
-
@data
|
6
|
+
def initialize(http_method, api_url, api_key, data, affiliate_id)
|
7
|
+
@api_key = api_key
|
8
|
+
@http_method = http_method
|
9
|
+
@api_url = api_url
|
10
|
+
@data = data
|
11
|
+
@affiliate_id = affiliate_id
|
11
12
|
end
|
12
13
|
|
13
14
|
def url
|
@@ -39,6 +39,7 @@ module Shipcloud
|
|
39
39
|
|
40
40
|
def parse_errors
|
41
41
|
return [] unless response_body
|
42
|
+
|
42
43
|
data = JSON.parse(response_body)
|
43
44
|
if data.is_a?(Hash) && data["errors"]
|
44
45
|
data["errors"]
|
@@ -51,6 +52,7 @@ module Shipcloud
|
|
51
52
|
|
52
53
|
def response_body
|
53
54
|
return unless @response
|
55
|
+
|
54
56
|
@response.body
|
55
57
|
end
|
56
58
|
end
|
data/lib/shipcloud/version.rb
CHANGED
data/shipcloud.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path("
|
2
|
+
lib = File.expand_path("lib", __dir__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require "shipcloud/version"
|
5
5
|
|
@@ -19,12 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = ">= 2.
|
22
|
+
spec.required_ruby_version = ">= 2.3"
|
23
23
|
|
24
24
|
spec.add_runtime_dependency "json", ">= 1.8.0"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
25
26
|
spec.add_development_dependency "rake", "~> 12.0"
|
26
27
|
spec.add_development_dependency "rspec", "~> 3.6"
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
28
|
+
spec.add_development_dependency "rubocop", "~> 0.71.0"
|
29
|
+
spec.add_development_dependency "rubocop-performance"
|
29
30
|
spec.add_development_dependency "simplecov"
|
31
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
30
32
|
end
|
@@ -36,44 +36,72 @@ describe Shipcloud::Address do
|
|
36
36
|
describe '.create' do
|
37
37
|
it 'makes a new POST request using the correct API endpoint' do
|
38
38
|
expect(Shipcloud).to receive(:request).
|
39
|
-
with(:post, "addresses", valid_attributes, api_key: nil
|
39
|
+
with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: nil).
|
40
|
+
and_return("data" => {})
|
40
41
|
|
41
42
|
Shipcloud::Address.create(valid_attributes)
|
42
43
|
end
|
43
44
|
|
44
45
|
it "returns an address containing an id" do
|
45
46
|
expect(Shipcloud).to receive(:request).
|
46
|
-
with(:post, "addresses", valid_attributes, api_key: nil).
|
47
|
+
with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: nil).
|
47
48
|
and_return(returned_address)
|
48
49
|
|
49
50
|
address = Shipcloud::Address.create(valid_attributes)
|
50
51
|
|
51
52
|
expect(address.id).to eq("1c81efb7-9b95-4dd8-92e3-cac1bca3df6f")
|
52
53
|
end
|
54
|
+
|
55
|
+
it "use the affiliate ID provided for the request" do
|
56
|
+
expect(Shipcloud).to receive(:request).
|
57
|
+
with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: "affiliate_id").
|
58
|
+
and_return(returned_address)
|
59
|
+
|
60
|
+
address = Shipcloud::Address.create(valid_attributes, affiliate_id: "affiliate_id")
|
61
|
+
|
62
|
+
expect(address.id).to eq("1c81efb7-9b95-4dd8-92e3-cac1bca3df6f")
|
63
|
+
end
|
53
64
|
end
|
54
65
|
|
55
66
|
describe '.find' do
|
56
67
|
it 'makes a new GET request using the correct API endpoint to receive a specific address' do
|
57
68
|
expect(Shipcloud).to receive(:request).with(
|
58
|
-
:get, "addresses/123", {}, api_key: nil).and_return("id" => "123")
|
69
|
+
:get, "addresses/123", {}, api_key: nil, affiliate_id: nil).and_return("id" => "123")
|
59
70
|
|
60
71
|
Shipcloud::Address.find("123")
|
61
72
|
end
|
73
|
+
|
74
|
+
it "use the affiliate ID provided for the request" do
|
75
|
+
expect(Shipcloud).to receive(:request).with(
|
76
|
+
:get, "addresses/123", {}, api_key: nil, affiliate_id: "affiliate_id"
|
77
|
+
).and_return("id" => "123")
|
78
|
+
|
79
|
+
Shipcloud::Address.find("123", affiliate_id: "affiliate_id")
|
80
|
+
end
|
62
81
|
end
|
63
82
|
|
64
83
|
describe '.update' do
|
65
84
|
it 'makes a new PUT request using the correct API endpoint' do
|
66
85
|
expect(Shipcloud).to receive(:request).with(
|
67
|
-
:put, "addresses/123", { street: "Mittelweg" }, api_key: nil
|
86
|
+
:put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: nil
|
87
|
+
).and_return("data" => {})
|
68
88
|
|
69
89
|
Shipcloud::Address.update("123", street: "Mittelweg")
|
70
90
|
end
|
91
|
+
|
92
|
+
it "use the affiliate ID provided for the request" do
|
93
|
+
expect(Shipcloud).to receive(:request).with(
|
94
|
+
:put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: "affiliate_id"
|
95
|
+
).and_return("data" => {})
|
96
|
+
|
97
|
+
Shipcloud::Address.update("123", { street: "Mittelweg" }, affiliate_id: "affiliate_id")
|
98
|
+
end
|
71
99
|
end
|
72
100
|
|
73
101
|
describe '.all' do
|
74
102
|
it 'makes a new Get request using the correct API endpoint' do
|
75
103
|
expect(Shipcloud).to receive(:request).
|
76
|
-
with(:get, "addresses", {}, api_key: nil).and_return([])
|
104
|
+
with(:get, "addresses", {}, api_key: nil, affiliate_id: nil).and_return([])
|
77
105
|
|
78
106
|
Shipcloud::Address.all
|
79
107
|
end
|
@@ -87,11 +115,21 @@ describe Shipcloud::Address do
|
|
87
115
|
expect(address).to be_a Shipcloud::Address
|
88
116
|
end
|
89
117
|
end
|
118
|
+
|
119
|
+
it "use the affiliate ID provided for the request" do
|
120
|
+
stub_addresses_request(affiliate_id: "affiliate_id")
|
121
|
+
|
122
|
+
addresses = Shipcloud::Address.all(affiliate_id: "affiliate_id")
|
123
|
+
|
124
|
+
addresses.each do |address|
|
125
|
+
expect(address).to be_a Shipcloud::Address
|
126
|
+
end
|
127
|
+
end
|
90
128
|
end
|
91
129
|
|
92
|
-
def stub_addresses_request
|
130
|
+
def stub_addresses_request(affiliate_id: nil)
|
93
131
|
allow(Shipcloud).to receive(:request).
|
94
|
-
with(:get, "addresses", {}, api_key: nil).
|
132
|
+
with(:get, "addresses", {}, api_key: nil, affiliate_id: affiliate_id).
|
95
133
|
and_return(
|
96
134
|
[
|
97
135
|
{
|
@@ -24,7 +24,7 @@ describe Shipcloud::Carrier do
|
|
24
24
|
describe '.all' do
|
25
25
|
it 'makes a new Get request using the correct API endpoint' do
|
26
26
|
expect(Shipcloud).to receive(:request).
|
27
|
-
with(:get, "carriers", {}, api_key: nil).and_return([])
|
27
|
+
with(:get, "carriers", {}, api_key: nil, affiliate_id: nil).and_return([])
|
28
28
|
|
29
29
|
Shipcloud::Carrier.all
|
30
30
|
end
|
@@ -66,11 +66,18 @@ describe Shipcloud::Carrier do
|
|
66
66
|
)
|
67
67
|
)
|
68
68
|
end
|
69
|
+
|
70
|
+
it "use the affiliate ID provided for the request" do
|
71
|
+
expect(Shipcloud).to receive(:request).
|
72
|
+
with(:get, "carriers", {}, api_key: nil, affiliate_id: "affiliate_id").and_return([])
|
73
|
+
|
74
|
+
Shipcloud::Carrier.all(affiliate_id: "affiliate_id")
|
75
|
+
end
|
69
76
|
end
|
70
77
|
|
71
|
-
def stub_carriers_request
|
78
|
+
def stub_carriers_request(affiliate_id: nil)
|
72
79
|
allow(Shipcloud).to receive(:request).
|
73
|
-
with(:get, "carriers", {}, api_key: nil).
|
80
|
+
with(:get, "carriers", {}, api_key: nil, affiliate_id: affiliate_id).
|
74
81
|
and_return(
|
75
82
|
[
|
76
83
|
{
|
@@ -56,7 +56,7 @@ describe Shipcloud::PickupRequest do
|
|
56
56
|
describe ".create" do
|
57
57
|
it "makes a new POST request using the correct API endpoint" do
|
58
58
|
expect(Shipcloud).to receive(:request).
|
59
|
-
with(:post, "pickup_requests", valid_attributes, api_key: nil).
|
59
|
+
with(:post, "pickup_requests", valid_attributes, api_key: nil, affiliate_id: nil).
|
60
60
|
and_return("data" => {})
|
61
61
|
|
62
62
|
Shipcloud::PickupRequest.create(valid_attributes)
|
@@ -119,5 +119,18 @@ describe Shipcloud::PickupRequest do
|
|
119
119
|
"phone" => "555-555"
|
120
120
|
)
|
121
121
|
end
|
122
|
+
|
123
|
+
it "use the affiliate ID provided for the request" do
|
124
|
+
expect(Shipcloud).to receive(:request).
|
125
|
+
with(
|
126
|
+
:post,
|
127
|
+
"pickup_requests",
|
128
|
+
valid_attributes,
|
129
|
+
api_key: nil,
|
130
|
+
affiliate_id: "affiliate_id",
|
131
|
+
).and_return("data" => {})
|
132
|
+
|
133
|
+
Shipcloud::PickupRequest.create(valid_attributes, affiliate_id: "affiliate_id")
|
134
|
+
end
|
122
135
|
end
|
123
136
|
end
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Shipcloud::Request::Base do
|
4
4
|
context "#perform" do
|
5
5
|
it "checks for an api key" do
|
6
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", nil, {})
|
6
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", nil, {}, "affiliate_id")
|
7
7
|
|
8
8
|
expect{
|
9
9
|
Shipcloud::Request::Base.new(info).perform
|
@@ -16,7 +16,7 @@ describe Shipcloud::Request::Base do
|
|
16
16
|
expect(connection).to receive(:setup_https)
|
17
17
|
response = double(code: "200", body: { id: 1 }.to_json)
|
18
18
|
expect(connection).to receive(:request).and_return(response)
|
19
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
19
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
20
20
|
|
21
21
|
data = Shipcloud::Request::Base.new(info).perform
|
22
22
|
|
@@ -30,9 +30,10 @@ describe Shipcloud::Request::Base do
|
|
30
30
|
expect(connection).to receive(:setup_https)
|
31
31
|
response = double(code: "400", body: { id: 1 }.to_json)
|
32
32
|
expect(connection).to receive(:request).and_return(response)
|
33
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
33
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
34
34
|
|
35
|
-
expect { Shipcloud::Request::Base.new(info).perform }.
|
35
|
+
expect { Shipcloud::Request::Base.new(info).perform }.
|
36
|
+
to raise_error(Shipcloud::ClientError)
|
36
37
|
end
|
37
38
|
|
38
39
|
it "performs an https request and raises an Shipcloud::ServerError if the response "\
|
@@ -42,9 +43,10 @@ describe Shipcloud::Request::Base do
|
|
42
43
|
expect(connection).to receive(:setup_https)
|
43
44
|
response = double(code: "500", body: { id: 1 }.to_json)
|
44
45
|
expect(connection).to receive(:request).and_return(response)
|
45
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
46
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
46
47
|
|
47
|
-
expect { Shipcloud::Request::Base.new(info).perform }.
|
48
|
+
expect { Shipcloud::Request::Base.new(info).perform }.
|
49
|
+
to raise_error(Shipcloud::ServerError)
|
48
50
|
end
|
49
51
|
|
50
52
|
it "performs an https request and raises an Shipcloud::ShipcloudError if the body of the "\
|
@@ -54,7 +56,7 @@ describe Shipcloud::Request::Base do
|
|
54
56
|
expect(connection).to receive(:setup_https)
|
55
57
|
response = double(code: "200", body: "no json")
|
56
58
|
expect(connection).to receive(:request).and_return(response)
|
57
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
59
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
58
60
|
|
59
61
|
expect { Shipcloud::Request::Base.new(info).perform }.
|
60
62
|
to raise_error(Shipcloud::ShipcloudError)
|
@@ -4,7 +4,7 @@ require "spec_helper"
|
|
4
4
|
describe Shipcloud::Request::Info do
|
5
5
|
describe "#url" do
|
6
6
|
it "returns the correct url" do
|
7
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
7
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
8
8
|
|
9
9
|
expect(info.url).to eq "/v1/shipments"
|
10
10
|
end
|
@@ -12,14 +12,20 @@ describe Shipcloud::Request::Info do
|
|
12
12
|
|
13
13
|
describe "#path_with_params" do
|
14
14
|
it "returns just the path if there aren't any params" do
|
15
|
-
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {})
|
15
|
+
info = Shipcloud::Request::Info.new(:get, "shipments", "api_key", {}, "affiliate_id")
|
16
16
|
path = info.path_with_params(info.url, info.data)
|
17
17
|
|
18
18
|
expect(path).to eq "/v1/shipments"
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns the path and given params" do
|
22
|
-
info = Shipcloud::Request::Info.new(
|
22
|
+
info = Shipcloud::Request::Info.new(
|
23
|
+
:get,
|
24
|
+
"shipments",
|
25
|
+
"api_key",
|
26
|
+
{ foo: "bar" },
|
27
|
+
"affiliate_id",
|
28
|
+
)
|
23
29
|
path = info.path_with_params(info.url, info.data)
|
24
30
|
|
25
31
|
expect(path).to eq "/v1/shipments?foo=bar"
|
@@ -52,7 +52,7 @@ describe Shipcloud::ShipmentQuote do
|
|
52
52
|
describe ".create" do
|
53
53
|
it "makes a new POST request using the correct API endpoint" do
|
54
54
|
expect(Shipcloud).to receive(:request).
|
55
|
-
with(:post, "shipment_quotes", valid_attributes, api_key: nil).
|
55
|
+
with(:post, "shipment_quotes", valid_attributes, api_key: nil, affiliate_id: nil).
|
56
56
|
and_return("data" => {})
|
57
57
|
|
58
58
|
Shipcloud::ShipmentQuote.create(valid_attributes)
|
@@ -70,5 +70,18 @@ describe Shipcloud::ShipmentQuote do
|
|
70
70
|
|
71
71
|
expect(shipment_quote.price).to eq 42.12
|
72
72
|
end
|
73
|
+
|
74
|
+
it "use the affiliate ID provided for the request" do
|
75
|
+
expect(Shipcloud).to receive(:request).
|
76
|
+
with(
|
77
|
+
:post,
|
78
|
+
"shipment_quotes",
|
79
|
+
valid_attributes,
|
80
|
+
api_key: nil,
|
81
|
+
affiliate_id: "affiliate_id",
|
82
|
+
).and_return("data" => {})
|
83
|
+
|
84
|
+
Shipcloud::ShipmentQuote.create(valid_attributes, affiliate_id: "affiliate_id")
|
85
|
+
end
|
73
86
|
end
|
74
87
|
end
|
@@ -78,30 +78,61 @@ describe Shipcloud::Shipment do
|
|
78
78
|
describe ".create" do
|
79
79
|
it "makes a new POST request using the correct API endpoint" do
|
80
80
|
expect(Shipcloud).to receive(:request).
|
81
|
-
with(:post, "shipments", valid_attributes, api_key: nil
|
81
|
+
with(:post, "shipments", valid_attributes, api_key: nil, affiliate_id: nil).
|
82
|
+
and_return("data" => {})
|
82
83
|
Shipcloud::Shipment.create(valid_attributes)
|
83
84
|
end
|
85
|
+
|
86
|
+
it "use the affiliate ID provided for the request" do
|
87
|
+
expect(Shipcloud).to receive(:request).
|
88
|
+
with(
|
89
|
+
:post,
|
90
|
+
"shipments",
|
91
|
+
valid_attributes,
|
92
|
+
api_key: nil,
|
93
|
+
affiliate_id: "affiliate_id",
|
94
|
+
).and_return("data" => {})
|
95
|
+
Shipcloud::Shipment.create(valid_attributes, affiliate_id: "affiliate_id")
|
96
|
+
end
|
84
97
|
end
|
85
98
|
|
86
99
|
describe ".find" do
|
87
100
|
it "makes a new GET request using the correct API endpoint to receive a specific subscription" do
|
88
|
-
expect(Shipcloud).to receive(:request).
|
101
|
+
expect(Shipcloud).to receive(:request).
|
102
|
+
with(:get, "shipments/123", {}, api_key: nil, affiliate_id: nil).
|
89
103
|
and_return("id" => "123")
|
90
104
|
Shipcloud::Shipment.find("123")
|
91
105
|
end
|
106
|
+
|
107
|
+
it "use the affiliate ID provided for the request" do
|
108
|
+
expect(Shipcloud).to receive(:request).with(
|
109
|
+
:get, "shipments/123", {}, api_key: nil, affiliate_id: "affiliate_id"
|
110
|
+
).and_return("id" => "123")
|
111
|
+
Shipcloud::Shipment.find("123", affiliate_id: "affiliate_id")
|
112
|
+
end
|
92
113
|
end
|
93
114
|
|
94
115
|
describe ".update" do
|
95
116
|
it "makes a new PUT request using the correct API endpoint" do
|
96
117
|
expect(Shipcloud).to receive(:request).
|
97
|
-
with(:put, "shipments/123", { carrier: "ups" }, api_key: nil
|
118
|
+
with(:put, "shipments/123", { carrier: "ups" }, api_key: nil, affiliate_id: nil).
|
119
|
+
and_return("data" => {})
|
98
120
|
Shipcloud::Shipment.update("123", carrier: "ups")
|
99
121
|
end
|
122
|
+
|
123
|
+
it "use the affiliate ID provided for the request" do
|
124
|
+
expect(Shipcloud).to receive(:request).
|
125
|
+
with(
|
126
|
+
:put, "shipments/123", { carrier: "ups" }, api_key: nil, affiliate_id: "affiliate_id"
|
127
|
+
).and_return("data" => {})
|
128
|
+
Shipcloud::Shipment.update("123", { carrier: "ups" }, affiliate_id: "affiliate_id")
|
129
|
+
end
|
100
130
|
end
|
101
131
|
|
102
132
|
describe ".delete" do
|
103
133
|
it "makes a new DELETE request using the correct API endpoint" do
|
104
|
-
expect(Shipcloud).to receive(:request).
|
134
|
+
expect(Shipcloud).to receive(:request).
|
135
|
+
with(:delete, "shipments/123", {}, api_key: nil, affiliate_id: nil).
|
105
136
|
and_return(true)
|
106
137
|
Shipcloud::Shipment.delete("123")
|
107
138
|
end
|
@@ -113,12 +144,19 @@ describe Shipcloud::Shipment do
|
|
113
144
|
expect { Shipcloud::Shipment.delete("123", api_key: "your-api-key") }.
|
114
145
|
to_not raise_error
|
115
146
|
end
|
147
|
+
|
148
|
+
it "use the affiliate ID provided for the request" do
|
149
|
+
expect(Shipcloud).to receive(:request).with(
|
150
|
+
:delete, "shipments/123", {}, api_key: nil, affiliate_id: "affiliate_id"
|
151
|
+
).and_return(true)
|
152
|
+
Shipcloud::Shipment.delete("123", affiliate_id: "affiliate_id")
|
153
|
+
end
|
116
154
|
end
|
117
155
|
|
118
156
|
describe ".all" do
|
119
157
|
it "makes a new Get request using the correct API endpoint" do
|
120
158
|
expect(Shipcloud).to receive(:request).
|
121
|
-
with(:get, "shipments", {}, api_key: nil).
|
159
|
+
with(:get, "shipments", {}, api_key: nil, affiliate_id: nil).
|
122
160
|
and_return("shipments" => [])
|
123
161
|
|
124
162
|
Shipcloud::Shipment.all
|
@@ -146,16 +184,24 @@ describe Shipcloud::Shipment do
|
|
146
184
|
}
|
147
185
|
|
148
186
|
expect(Shipcloud).to receive(:request).
|
149
|
-
with(:get, "shipments", filter, api_key: nil).
|
187
|
+
with(:get, "shipments", filter, api_key: nil, affiliate_id: nil).
|
150
188
|
and_return("shipments" => shipments_array)
|
151
189
|
|
152
190
|
Shipcloud::Shipment.all(filter, api_key: nil)
|
153
191
|
end
|
192
|
+
|
193
|
+
it "use the affiliate ID provided for the request" do
|
194
|
+
expect(Shipcloud).to receive(:request).
|
195
|
+
with(:get, "shipments", {}, api_key: nil, affiliate_id: "affiliate_id").
|
196
|
+
and_return("shipments" => [])
|
197
|
+
|
198
|
+
Shipcloud::Shipment.all(affiliate_id: "affiliate_id")
|
199
|
+
end
|
154
200
|
end
|
155
201
|
|
156
|
-
def stub_shipments_requests
|
202
|
+
def stub_shipments_requests(affiliate_id: nil)
|
157
203
|
allow(Shipcloud).to receive(:request).
|
158
|
-
with(:get, "shipments", {}, api_key: nil).
|
204
|
+
with(:get, "shipments", {}, api_key: nil, affiliate_id: affiliate_id).
|
159
205
|
and_return("shipments" => shipments_array)
|
160
206
|
end
|
161
207
|
|
@@ -19,7 +19,7 @@ describe Shipcloud::PickupRequest do
|
|
19
19
|
describe ".all" do
|
20
20
|
it "makes a new GET request using the correct API endpoint" do
|
21
21
|
expect(Shipcloud).to receive(:request).
|
22
|
-
with(:get, "trackers", {}, api_key: nil).
|
22
|
+
with(:get, "trackers", {}, api_key: nil, affiliate_id: nil).
|
23
23
|
and_return("trackers" => [])
|
24
24
|
|
25
25
|
Shipcloud::Tracker.all
|
@@ -34,30 +34,55 @@ describe Shipcloud::PickupRequest do
|
|
34
34
|
expect(tracker).to be_a Shipcloud::Tracker
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
it "use the affiliate ID provided for the request" do
|
39
|
+
expect(Shipcloud).to receive(:request).
|
40
|
+
with(:get, "trackers", {}, api_key: nil, affiliate_id: "affiliate_id").
|
41
|
+
and_return("trackers" => [])
|
42
|
+
|
43
|
+
Shipcloud::Tracker.all(affiliate_id: "affiliate_id")
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
describe ".create" do
|
40
48
|
it "makes a new POST request using the correct API endpoint" do
|
41
49
|
expect(Shipcloud).to receive(:request).
|
42
|
-
with(:post, "trackers", valid_attributes, api_key: nil).
|
50
|
+
with(:post, "trackers", valid_attributes, api_key: nil, affiliate_id: nil).
|
43
51
|
and_return("data" => {})
|
44
52
|
|
45
53
|
Shipcloud::Tracker.create(valid_attributes)
|
46
54
|
end
|
55
|
+
|
56
|
+
it "use the affiliate ID provided for the request" do
|
57
|
+
expect(Shipcloud).to receive(:request).
|
58
|
+
with(:post, "trackers", valid_attributes, api_key: nil, affiliate_id: "affiliate_id").
|
59
|
+
and_return("data" => {})
|
60
|
+
|
61
|
+
Shipcloud::Tracker.create(valid_attributes, affiliate_id: "affiliate_id")
|
62
|
+
end
|
47
63
|
end
|
48
64
|
|
49
65
|
describe ".find" do
|
50
66
|
it "makes a new GET request using the correct API endpoint to receive a specific tracker" do
|
51
|
-
expect(Shipcloud).to receive(:request).
|
67
|
+
expect(Shipcloud).to receive(:request).
|
68
|
+
with(:get, "trackers/123", {}, api_key: nil, affiliate_id: nil).
|
52
69
|
and_return("id" => "123")
|
53
70
|
|
54
71
|
Shipcloud::Tracker.find("123")
|
55
72
|
end
|
73
|
+
|
74
|
+
it "use the affiliate ID provided for the request" do
|
75
|
+
expect(Shipcloud).to receive(:request).
|
76
|
+
with(:get, "trackers/123", {}, api_key: nil, affiliate_id: "affiliate_id").
|
77
|
+
and_return("id" => "123")
|
78
|
+
|
79
|
+
Shipcloud::Tracker.find("123", affiliate_id: "affiliate_id")
|
80
|
+
end
|
56
81
|
end
|
57
82
|
|
58
|
-
def stub_trackers_requests
|
83
|
+
def stub_trackers_requests(affiliate_id: nil)
|
59
84
|
allow(Shipcloud).to receive(:request).
|
60
|
-
with(:get, "trackers", {}, api_key: nil).
|
85
|
+
with(:get, "trackers", {}, api_key: nil, affiliate_id: affiliate_id).
|
61
86
|
and_return("trackers" => trackers_array)
|
62
87
|
end
|
63
88
|
|
@@ -19,25 +19,39 @@ describe Shipcloud::Webhook do
|
|
19
19
|
describe ".create" do
|
20
20
|
it "makes a new POST request using the correct API endpoint" do
|
21
21
|
expect(Shipcloud).to receive(:request).
|
22
|
-
with(:post, "webhooks", valid_attributes, api_key: nil).
|
22
|
+
with(:post, "webhooks", valid_attributes, api_key: nil, affiliate_id: nil).
|
23
23
|
and_return("data" => {})
|
24
24
|
Shipcloud::Webhook.create(valid_attributes)
|
25
25
|
end
|
26
|
+
|
27
|
+
it "use the affiliate ID provided for the request" do
|
28
|
+
expect(Shipcloud).to receive(:request).
|
29
|
+
with(:post, "webhooks", valid_attributes, api_key: nil, affiliate_id: "affiliate_id").
|
30
|
+
and_return("data" => {})
|
31
|
+
Shipcloud::Webhook.create(valid_attributes, affiliate_id: "affiliate_id")
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
describe ".find" do
|
29
36
|
it "makes a new GET request using the correct API endpoint to receive a specific webhook" do
|
30
37
|
expect(Shipcloud).to receive(:request).
|
31
|
-
with(:get, "webhooks/123", {}, api_key: nil).
|
38
|
+
with(:get, "webhooks/123", {}, api_key: nil, affiliate_id: nil).
|
32
39
|
and_return("id" => "123")
|
33
40
|
Shipcloud::Webhook.find("123")
|
34
41
|
end
|
42
|
+
|
43
|
+
it "use the affiliate ID provided for the request" do
|
44
|
+
expect(Shipcloud).to receive(:request).
|
45
|
+
with(:get, "webhooks/123", {}, api_key: nil, affiliate_id: "affiliate_id").
|
46
|
+
and_return("id" => "123")
|
47
|
+
Shipcloud::Webhook.find("123", affiliate_id: "affiliate_id")
|
48
|
+
end
|
35
49
|
end
|
36
50
|
|
37
51
|
describe ".all" do
|
38
52
|
it "makes a new Get request using the correct API endpoint" do
|
39
53
|
expect(Shipcloud).to receive(:request).
|
40
|
-
with(:get, "webhooks", {}, api_key: nil).
|
54
|
+
with(:get, "webhooks", {}, api_key: nil, affiliate_id: nil).
|
41
55
|
and_return("webhooks" => [])
|
42
56
|
|
43
57
|
Shipcloud::Webhook.all
|
@@ -52,15 +66,30 @@ describe Shipcloud::Webhook do
|
|
52
66
|
expect(webhook).to be_a Shipcloud::Webhook
|
53
67
|
end
|
54
68
|
end
|
69
|
+
|
70
|
+
it "use the affiliate ID provided for the request" do
|
71
|
+
expect(Shipcloud).to receive(:request).
|
72
|
+
with(:get, "webhooks", {}, api_key: nil, affiliate_id: "affiliate_id").
|
73
|
+
and_return("webhooks" => [])
|
74
|
+
|
75
|
+
Shipcloud::Webhook.all(affiliate_id: "affiliate_id")
|
76
|
+
end
|
55
77
|
end
|
56
78
|
|
57
79
|
describe ".delete" do
|
58
80
|
it "makes a DELETE request using the correct API endpoint" do
|
59
81
|
expect(Shipcloud).to receive(:request).
|
60
|
-
with(:delete, "webhooks/123", {}, api_key: nil).
|
82
|
+
with(:delete, "webhooks/123", {}, api_key: nil, affiliate_id: nil).
|
61
83
|
and_return(true)
|
62
84
|
Shipcloud::Webhook.delete("123")
|
63
85
|
end
|
86
|
+
|
87
|
+
it "use the affiliate ID provided for the request" do
|
88
|
+
expect(Shipcloud).to receive(:request).
|
89
|
+
with(:delete, "webhooks/123", {}, api_key: nil, affiliate_id: "affiliate_id").
|
90
|
+
and_return(true)
|
91
|
+
Shipcloud::Webhook.delete("123", affiliate_id: "affiliate_id")
|
92
|
+
end
|
64
93
|
end
|
65
94
|
|
66
95
|
describe ".deactivated" do
|
@@ -70,7 +99,7 @@ describe Shipcloud::Webhook do
|
|
70
99
|
|
71
100
|
before do
|
72
101
|
expect(Shipcloud).to receive(:request).
|
73
|
-
with(:get, "webhooks/#{id}", {}, api_key: nil).
|
102
|
+
with(:get, "webhooks/#{id}", {}, api_key: nil, affiliate_id: nil).
|
74
103
|
and_return("id" => id, "deactivated" => deactivated)
|
75
104
|
end
|
76
105
|
|
@@ -85,9 +114,9 @@ describe Shipcloud::Webhook do
|
|
85
114
|
end
|
86
115
|
end
|
87
116
|
|
88
|
-
def stub_webhooks_request
|
117
|
+
def stub_webhooks_request(affiliate_id: nil)
|
89
118
|
allow(Shipcloud).to receive(:request).
|
90
|
-
with(:get, "webhooks", {}, api_key: nil).
|
119
|
+
with(:get, "webhooks", {}, api_key: nil, affiliate_id: affiliate_id).
|
91
120
|
and_return("webhooks" => webhooks_array)
|
92
121
|
end
|
93
122
|
|
data/spec/shipcloud_spec.rb
CHANGED
@@ -52,55 +52,55 @@ describe Shipcloud do
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
describe
|
55
|
+
describe ".configure" do
|
56
56
|
before :each do
|
57
57
|
Shipcloud.configuration = nil
|
58
58
|
end
|
59
59
|
|
60
|
-
it
|
60
|
+
it "defaults api_key to nil" do
|
61
61
|
expect(Shipcloud.configuration.api_key).to be_nil
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it "sets the api_key" do
|
65
65
|
Shipcloud.configure do |config|
|
66
|
-
config.api_key =
|
66
|
+
config.api_key = "your-api-key"
|
67
67
|
end
|
68
|
-
expect(Shipcloud.configuration.api_key).to eq
|
68
|
+
expect(Shipcloud.configuration.api_key).to eq "your-api-key"
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
Shipcloud.api_key =
|
73
|
-
expect(Shipcloud.api_key).to eq
|
74
|
-
expect(Shipcloud.configuration.api_key).to eq
|
71
|
+
it "gets the api key, set as a class variable (DEPRECATED)" do
|
72
|
+
Shipcloud.api_key = "old-school-api-key"
|
73
|
+
expect(Shipcloud.api_key).to eq "old-school-api-key"
|
74
|
+
expect(Shipcloud.configuration.api_key).to eq "old-school-api-key"
|
75
75
|
end
|
76
76
|
|
77
77
|
it "defaults api_base to 'api.shipcloud.io'" do
|
78
|
-
expect(Shipcloud.configuration.api_base).to eq
|
78
|
+
expect(Shipcloud.configuration.api_base).to eq "api.shipcloud.io"
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it "overwrites the default api base" do
|
82
82
|
Shipcloud.configure do |config|
|
83
|
-
config.api_base =
|
83
|
+
config.api_base = "api.shipcloud.dev"
|
84
84
|
end
|
85
|
-
expect(Shipcloud.configuration.api_base).to eq
|
85
|
+
expect(Shipcloud.configuration.api_base).to eq "api.shipcloud.dev"
|
86
86
|
end
|
87
87
|
|
88
|
-
it
|
88
|
+
it "defaults use_ssl to true" do
|
89
89
|
expect(Shipcloud.configuration.use_ssl).to be true
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
92
|
+
it "overwrites the default ssl mode" do
|
93
93
|
Shipcloud.configure do |config|
|
94
94
|
config.use_ssl = false
|
95
95
|
end
|
96
96
|
expect(Shipcloud.configuration.use_ssl).to be false
|
97
97
|
end
|
98
98
|
|
99
|
-
it
|
99
|
+
it "defaults debug to false" do
|
100
100
|
expect(Shipcloud.configuration.debug).to be false
|
101
101
|
end
|
102
102
|
|
103
|
-
it
|
103
|
+
it "overwrites the default debug mode" do
|
104
104
|
Shipcloud.configure do |config|
|
105
105
|
config.debug = true
|
106
106
|
end
|
@@ -136,7 +136,6 @@ describe Shipcloud do
|
|
136
136
|
Shipcloud.configure do |config|
|
137
137
|
config.affiliate_id = "integration.my_rails_app.1234567"
|
138
138
|
end
|
139
|
-
|
140
139
|
expect(Shipcloud.api_headers).to eq(
|
141
140
|
"Content-Type" => "application/json",
|
142
141
|
"User-Agent" => "shipcloud-ruby v#{Shipcloud::VERSION}, API #{Shipcloud::API_VERSION}, " \
|
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.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sthollmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.10'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,33 +67,33 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.6'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rubocop
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 0.71.0
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 0.71.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop-performance
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0
|
89
|
+
version: '0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: simplecov
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,10 +108,25 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
97
125
|
description: A wrapper for the shipcloud API. Fore more details visit https://developers.shipcloud.io/
|
98
126
|
email:
|
99
127
|
- stefan@shipcloud.io
|
100
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- rubocop
|
101
130
|
extensions: []
|
102
131
|
extra_rdoc_files: []
|
103
132
|
files:
|
@@ -113,6 +142,7 @@ files:
|
|
113
142
|
- LICENSE.txt
|
114
143
|
- README.md
|
115
144
|
- Rakefile
|
145
|
+
- bin/rubocop
|
116
146
|
- install-cc-test-reporter.sh
|
117
147
|
- lib/shipcloud.rb
|
118
148
|
- lib/shipcloud/address.rb
|
@@ -159,15 +189,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
189
|
requirements:
|
160
190
|
- - ">="
|
161
191
|
- !ruby/object:Gem::Version
|
162
|
-
version: '2.
|
192
|
+
version: '2.3'
|
163
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
194
|
requirements:
|
165
195
|
- - ">="
|
166
196
|
- !ruby/object:Gem::Version
|
167
197
|
version: '0'
|
168
198
|
requirements: []
|
169
|
-
|
170
|
-
rubygems_version: 2.7.6
|
199
|
+
rubygems_version: 3.0.3
|
171
200
|
signing_key:
|
172
201
|
specification_version: 4
|
173
202
|
summary: A wrapper for the shipcloud API
|