shipcloud 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +62 -0
  3. data/.rubocop.yml +310 -313
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +21 -4
  6. data/Gemfile +2 -1
  7. data/README.md +3 -1
  8. data/Rakefile +5 -4
  9. data/bin/setup +7 -0
  10. data/lib/shipcloud/address.rb +2 -0
  11. data/lib/shipcloud/base.rb +5 -5
  12. data/lib/shipcloud/carrier.rb +2 -0
  13. data/lib/shipcloud/operations/all.rb +2 -0
  14. data/lib/shipcloud/operations/create.rb +3 -1
  15. data/lib/shipcloud/operations/delete.rb +2 -0
  16. data/lib/shipcloud/operations/find.rb +3 -1
  17. data/lib/shipcloud/operations/update.rb +19 -13
  18. data/lib/shipcloud/order.rb +15 -0
  19. data/lib/shipcloud/pickup_request.rb +2 -0
  20. data/lib/shipcloud/request/base.rb +2 -0
  21. data/lib/shipcloud/request/connection.rb +11 -3
  22. data/lib/shipcloud/request/info.rb +6 -5
  23. data/lib/shipcloud/shipcloud_error.rb +7 -0
  24. data/lib/shipcloud/shipment.rb +5 -2
  25. data/lib/shipcloud/shipment_quote.rb +2 -0
  26. data/lib/shipcloud/tracker.rb +1 -0
  27. data/lib/shipcloud/version.rb +3 -1
  28. data/lib/shipcloud/webhook.rb +2 -0
  29. data/lib/shipcloud.rb +1 -0
  30. data/shipcloud.gemspec +7 -6
  31. data/spec/shipcloud/address_spec.rb +66 -42
  32. data/spec/shipcloud/carrier_spec.rb +53 -52
  33. data/spec/shipcloud/order_spec.rb +188 -0
  34. data/spec/shipcloud/pickup_request_spec.rb +14 -13
  35. data/spec/shipcloud/request/base_spec.rb +3 -2
  36. data/spec/shipcloud/request/connection_spec.rb +1 -0
  37. data/spec/shipcloud/shipcloud_error_spec.rb +8 -7
  38. data/spec/shipcloud/shipment_quote_spec.rb +5 -4
  39. data/spec/shipcloud/shipment_spec.rb +135 -78
  40. data/spec/shipcloud/webhooks_spec.rb +5 -4
  41. data/spec/shipcloud_spec.rb +5 -2
  42. data/spec/spec_helper.rb +3 -2
  43. metadata +22 -21
  44. data/.hound.yml +0 -12
  45. data/.travis.yml +0 -27
  46. data/install-cc-test-reporter.sh +0 -4
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.6
1
+ 2.6.3
data/CHANGELOG.md CHANGED
@@ -1,7 +1,5 @@
1
- ## [0.11.0] - 2020-07-28
1
+ ## [Unreleased]
2
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
3
 
6
4
  ### Changed
7
5
 
@@ -13,19 +11,38 @@
13
11
 
14
12
  ### Security
15
13
 
16
- ## [Unreleased]
14
+ ## [0.12.0] - 2022-12-06
17
15
  ### Added
16
+ - Add order model
17
+ - Add attr_accessor for `service` to class `Shipcloud::Shipment` to be able to access the service attribute at the shipment object.
18
+ - Add attr_accessor for `additional_services` to class `Shipcloud::Shipment` to be able to access the additional_services attribute at the shipment object.
19
+ - Add attr_reader for `label_voucher_url` to class `Shipcloud::Shipment` to be able to read the label_voucher_url (QR Code url) attribute at the shipment object.
20
+ - Added missing `frozen_string_literal: true` magic comments to files
18
21
 
19
22
  ### Changed
23
+ - Ensure compatibility with ruby 2.x and 3.x
24
+ - Set required ruby version to >= 2.6
25
+ - Replace Travis CI with CircleCI
26
+ - Specify simplecov to be ~> 0.21.0
27
+ - Specify `rubocop` to be `~> 1.10.0`
28
+ - Specify `rubocop-performance` to be `~> 1.7.0`
20
29
 
21
30
  ### Deprecated
22
31
 
23
32
  ### Removed
33
+ - Drop support for Ruby <= 2.5
34
+ - Drop support for RBX
24
35
 
25
36
  ### Fixed
37
+ - Fix rubocop styling issues
26
38
 
27
39
  ### Security
28
40
 
41
+ ## [0.11.0] - 2020-07-28
42
+ ### Added
43
+ - Support shipments with pickup requests as required for [TNT](https://developers.shipcloud.io/carriers/tnt.html).
44
+ - Add attr_accessor for `email` to class `Shipcloud::Address` to be able to access the email attribute at the address object.
45
+
29
46
  ## [0.10.0] - 2019-08-07
30
47
  ### Added
31
48
  - Add the possibility to specify custom affiliate_id on every request
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in shipcloud.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -1,4 +1,6 @@
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
+ [![CircleCI](https://circleci.com/gh/shipcloud/shipcloud-ruby/tree/master.svg?style=svg)](https://circleci.com/gh/shipcloud/shipcloud-ruby/tree/master)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/c8c3cba2068e5d649567/maintainability)](https://codeclimate.com/github/shipcloud/shipcloud-ruby/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/c8c3cba2068e5d649567/test_coverage)](https://codeclimate.com/github/shipcloud/shipcloud-ruby/test_coverage)
2
4
 
3
5
  # shipcloud
4
6
 
data/Rakefile CHANGED
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
3
+ require "rspec/core/rake_task"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
7
  task :console do
7
- require 'irb'
8
- require 'irb/completion'
9
- require 'shipcloud'
8
+ require "irb"
9
+ require "irb/completion"
10
+ require "shipcloud"
10
11
  ARGV.clear
11
12
  IRB.start
12
13
  end
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler -v "~> 2.0"
7
+ bundle install
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class Address < Base
3
5
  include Shipcloud::Operations::Update
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class Base
3
5
  include Shipcloud::Operations::Create
@@ -28,17 +30,15 @@ module Shipcloud
28
30
  end
29
31
 
30
32
  def self.class_name
31
- self.name.split("::").last
33
+ name.split("::").last
32
34
  end
33
35
 
34
36
  def self.base_url
35
37
  "#{class_name.downcase}s"
36
38
  end
37
39
 
38
- def self.create_response_root
39
- end
40
+ def self.create_response_root; end
40
41
 
41
- def self.index_response_root
42
- end
42
+ def self.index_response_root; end
43
43
  end
44
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class Carrier < Base
3
5
  include Shipcloud::Operations::All
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Operations
3
5
  module All
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Operations
3
5
  module Create
@@ -18,7 +20,7 @@ module Shipcloud
18
20
  if create_response_root
19
21
  response = response.fetch(create_response_root, {})
20
22
  end
21
- self.new(response)
23
+ new(response)
22
24
  end
23
25
  end
24
26
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Operations
3
5
  module Delete
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Operations
3
5
  module Find
@@ -16,7 +18,7 @@ module Shipcloud
16
18
  api_key: api_key,
17
19
  affiliate_id: affiliate_id,
18
20
  )
19
- self.new(response)
21
+ new(response)
20
22
  end
21
23
  end
22
24
 
@@ -1,18 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Operations
3
5
  module Update
4
-
5
6
  module ClassMethods
6
- # Updates a object
7
+ # Updates an object
7
8
  # @param [String] id The id of the object that should be updated
8
9
  # @param [Hash] attributes The attributes that should be updated
9
- # @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
10
+ # @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key
10
11
  # will be used for the request
11
- def update(id, attributes, api_key: nil, affiliate_id: nil)
12
+ # @param [String] optional affiliate_id Your affiliate ID. If no affiliate ID is given,
13
+ # Shipcloud.affiliate_id will be used for the request
14
+ def update(id, attributes = {}, **kwargs)
15
+ attributes.merge!(kwargs)
16
+ options = attributes.slice(:api_key, :affiliate_id) || {}
17
+ attributes.reject! { |key| [:api_key, :affiliate_id].include?(key) }
12
18
  response = Shipcloud.request(
13
- :put, "#{base_url}/#{id}", attributes, api_key: api_key, affiliate_id: affiliate_id
19
+ :put, "#{base_url}/#{id}", attributes,
20
+ api_key: options[:api_key], affiliate_id: options[:affiliate_id]
14
21
  )
15
- self.new(response)
22
+ new(response)
16
23
  end
17
24
  end
18
25
 
@@ -20,16 +27,15 @@ module Shipcloud
20
27
  base.extend(ClassMethods)
21
28
  end
22
29
 
23
- # Updates a object
30
+ # Updates an object
24
31
  #
25
32
  # @param [Hash] attributes The attributes that should be updated
26
- # @param \[String\] optional api_key The api key. If no api key is given, Shipcloud.api_key
33
+ # @param [String] optional api_key The api key. If no api key is given, Shipcloud.api_key
27
34
  # will be used for the 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
- )
32
- set_attributes(response)
35
+ # @param [String] optional affiliate_id Your affiliate ID. If no affiliate ID is given,
36
+ # Shipcloud.affiliate_id will be used for the request
37
+ def update(attributes = {}, **kwargs)
38
+ self.class.update(id, attributes, **kwargs)
33
39
  end
34
40
  end
35
41
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shipcloud
4
+ class Order < Base
5
+ include Shipcloud::Operations::All
6
+ include Shipcloud::Operations::Find
7
+ include Shipcloud::Operations::Create
8
+ include Shipcloud::Operations::Delete
9
+
10
+ attr_reader :id
11
+ attr_accessor :external_customer_id, :external_order_id, :placed_at, :total_price, :total_vat,
12
+ :currency, :total_weight, :weight_unit, :refundable_until,
13
+ :refund_deduction_amount, :delivery_address, :order_line_items, :metadata
14
+ end
15
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class PickupRequest < Base
3
5
  include Shipcloud::Operations::Create
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Request
3
5
  class Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Request
3
5
  class Connection
@@ -9,12 +11,18 @@ module Shipcloud
9
11
 
10
12
  def setup_https
11
13
  if Shipcloud.configuration.use_ssl
12
- @https = Net::HTTP.new(Shipcloud.configuration.api_base, Net::HTTP.https_default_port)
14
+ @https = Net::HTTP.new(
15
+ Shipcloud.configuration.api_base,
16
+ Net::HTTP.https_default_port,
17
+ )
13
18
  @https.use_ssl = true
14
19
  @https.verify_mode = OpenSSL::SSL::VERIFY_PEER
15
20
  else
16
- @https = Net::HTTP.new(Shipcloud.configuration.api_base, Net::HTTP.http_default_port)
17
- @https.use_ssl = false
21
+ @https = Net::HTTP.new(
22
+ Shipcloud.configuration.api_base,
23
+ Net::HTTP.http_default_port,
24
+ )
25
+ @https.use_ssl = false
18
26
  end
19
27
  @https.set_debug_output $stdout if Shipcloud.configuration.debug
20
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  module Request
3
5
  class Info
@@ -12,16 +14,15 @@ module Shipcloud
12
14
  end
13
15
 
14
16
  def url
15
- url = "/#{API_VERSION}/#{api_url}"
16
- url
17
+ "/#{API_VERSION}/#{api_url}"
17
18
  end
18
19
 
19
20
  def path_with_params(path, params)
20
- unless params.empty?
21
+ if params.empty?
22
+ path
23
+ else
21
24
  encoded_params = URI.encode_www_form(params)
22
25
  [path, encoded_params].join("?")
23
- else
24
- path
25
26
  end
26
27
  end
27
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class ShipcloudError < StandardError
3
5
  attr_reader :errors, :response
@@ -59,10 +61,15 @@ module Shipcloud
59
61
 
60
62
  # Raised on errors in the 400-499 range
61
63
  class ClientError < ShipcloudError; end
64
+
62
65
  class AuthenticationError < ClientError; end
66
+
63
67
  class ForbiddenError < ClientError; end
68
+
64
69
  class InvalidRequestError < ClientError; end
70
+
65
71
  class TooManyRequests < ClientError; end
72
+
66
73
  class NotFoundError < ClientError; end
67
74
 
68
75
  # Raised on errors in the 500-599 range
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class Shipment < Base
3
5
  include Shipcloud::Operations::Delete
4
6
  include Shipcloud::Operations::Update
5
7
  include Shipcloud::Operations::All
6
8
 
7
- attr_accessor :from, :to, :carrier, :package, :reference_number, :metadata
9
+ attr_accessor :from, :to, :carrier, :service, :package, :reference_number, :metadata,
10
+ :additional_services
8
11
  attr_reader :id, :created_at, :carrier_tracking_no, :tracking_url, :label_url,
9
- :packages, :price, :customs_declaration, :pickup
12
+ :packages, :price, :customs_declaration, :pickup, :label_voucher_url
10
13
 
11
14
  def self.index_response_root
12
15
  "#{class_name.downcase}s"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class ShipmentQuote < Base
3
5
  include Shipcloud::Operations::Create
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Shipcloud
3
4
  class Tracker < Base
4
5
  include Shipcloud::Operations::All
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
- VERSION = "0.11.0".freeze
4
+ VERSION = "0.12.0"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Shipcloud
2
4
  class Webhook < Base
3
5
  include Shipcloud::Operations::All
data/lib/shipcloud.rb CHANGED
@@ -21,6 +21,7 @@ module Shipcloud
21
21
  autoload :Shipment, "shipcloud/shipment"
22
22
  autoload :Carrier, "shipcloud/carrier"
23
23
  autoload :Address, "shipcloud/address"
24
+ autoload :Order, "shipcloud/order"
24
25
  autoload :PickupRequest, "shipcloud/pickup_request"
25
26
  autoload :ShipmentQuote, "shipcloud/shipment_quote"
26
27
  autoload :Tracker, "shipcloud/tracker"
data/shipcloud.gemspec CHANGED
@@ -1,4 +1,6 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
3
+
2
4
  lib = File.expand_path("lib", __dir__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "shipcloud/version"
@@ -15,18 +17,17 @@ Gem::Specification.new do |spec|
15
17
  spec.license = "MIT"
16
18
 
17
19
  spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
20
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
21
  spec.require_paths = ["lib"]
21
22
 
22
- spec.required_ruby_version = ">= 2.3"
23
+ spec.required_ruby_version = ">= 2.6"
23
24
 
24
25
  spec.add_runtime_dependency "json", ">= 1.8.0"
25
26
  spec.add_development_dependency "pry", "~> 0.10"
26
- spec.add_development_dependency "rake", "~> 12.0"
27
+ spec.add_development_dependency "rake", "~> 13.0"
27
28
  spec.add_development_dependency "rspec", "~> 3.6"
28
- spec.add_development_dependency "rubocop", "~> 0.71.0"
29
- spec.add_development_dependency "rubocop-performance"
30
- spec.add_development_dependency "simplecov"
29
+ spec.add_development_dependency "rubocop", "~> 1.10.0"
30
+ spec.add_development_dependency "rubocop-performance", "~> 1.7.0"
31
+ spec.add_development_dependency "simplecov", "~> 0.21.0"
31
32
  spec.add_development_dependency "webmock", "~> 3.0"
32
33
  end
@@ -1,42 +1,43 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ require "spec_helper"
3
4
 
4
5
  describe Shipcloud::Address do
5
6
  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
- email: 'max@mustermail.com',
7
+ company: "shipcloud GmbH",
8
+ first_name: "Maxi",
9
+ last_name: "Musterfrau",
10
+ care_of: "Mustermann",
11
+ street: "Musterstraße",
12
+ street_no: "123",
13
+ zip_code: "12345",
14
+ city: "Hamburg",
15
+ state: "Hamburg",
16
+ country: "DE",
17
+ phone: "040/123456789",
18
+ email: "max@mustermail.com",
18
19
  }
19
20
 
20
- describe '#initialize' do
21
- it 'initializes all attributes correctly' do
21
+ describe "#initialize" do
22
+ it "initializes all attributes correctly" do
22
23
  address = Shipcloud::Address.new(valid_attributes)
23
- expect(address.company).to eq 'shipcloud GmbH'
24
- expect(address.first_name).to eq 'Maxi'
25
- expect(address.last_name).to eq 'Musterfrau'
26
- expect(address.care_of).to eq 'Mustermann'
27
- expect(address.street).to eq 'Musterstraße'
28
- expect(address.street_no).to eq '123'
29
- expect(address.zip_code).to eq '12345'
30
- expect(address.city).to eq 'Hamburg'
31
- expect(address.state).to eq 'Hamburg'
32
- expect(address.country).to eq 'DE'
33
- expect(address.phone).to eq '040/123456789'
34
- expect(address.email).to eq 'max@mustermail.com'
24
+ expect(address.company).to eq "shipcloud GmbH"
25
+ expect(address.first_name).to eq "Maxi"
26
+ expect(address.last_name).to eq "Musterfrau"
27
+ expect(address.care_of).to eq "Mustermann"
28
+ expect(address.street).to eq "Musterstraße"
29
+ expect(address.street_no).to eq "123"
30
+ expect(address.zip_code).to eq "12345"
31
+ expect(address.city).to eq "Hamburg"
32
+ expect(address.state).to eq "Hamburg"
33
+ expect(address.country).to eq "DE"
34
+ expect(address.phone).to eq "040/123456789"
35
+ expect(address.email).to eq "max@mustermail.com"
35
36
  end
36
37
  end
37
38
 
38
- describe '.create' do
39
- it 'makes a new POST request using the correct API endpoint' do
39
+ describe ".create" do
40
+ it "makes a new POST request using the correct API endpoint" do
40
41
  expect(Shipcloud).to receive(:request).
41
42
  with(:post, "addresses", valid_attributes, api_key: nil, affiliate_id: nil).
42
43
  and_return("data" => {})
@@ -65,10 +66,11 @@ describe Shipcloud::Address do
65
66
  end
66
67
  end
67
68
 
68
- describe '.find' do
69
- it 'makes a new GET request using the correct API endpoint to receive a specific address' do
69
+ describe ".find" do
70
+ it "makes a new GET request using the correct API endpoint to receive a specific address" do
70
71
  expect(Shipcloud).to receive(:request).with(
71
- :get, "addresses/123", {}, api_key: nil, affiliate_id: nil).and_return("id" => "123")
72
+ :get, "addresses/123", {}, api_key: nil, affiliate_id: nil
73
+ ).and_return("id" => "123")
72
74
 
73
75
  Shipcloud::Address.find("123")
74
76
  end
@@ -82,8 +84,8 @@ describe Shipcloud::Address do
82
84
  end
83
85
  end
84
86
 
85
- describe '.update' do
86
- it 'makes a new PUT request using the correct API endpoint' do
87
+ describe ".update" do
88
+ it "makes a new PUT request using the correct API endpoint" do
87
89
  expect(Shipcloud).to receive(:request).with(
88
90
  :put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: nil
89
91
  ).and_return("data" => {})
@@ -100,15 +102,15 @@ describe Shipcloud::Address do
100
102
  end
101
103
  end
102
104
 
103
- describe '.all' do
104
- it 'makes a new Get request using the correct API endpoint' do
105
+ describe ".all" do
106
+ it "makes a new Get request using the correct API endpoint" do
105
107
  expect(Shipcloud).to receive(:request).
106
108
  with(:get, "addresses", {}, api_key: nil, affiliate_id: nil).and_return([])
107
109
 
108
110
  Shipcloud::Address.all
109
111
  end
110
112
 
111
- it 'returns a list of Address objects' do
113
+ it "returns a list of Address objects" do
112
114
  stub_addresses_request
113
115
 
114
116
  addresses = Shipcloud::Address.all
@@ -129,6 +131,28 @@ describe Shipcloud::Address do
129
131
  end
130
132
  end
131
133
 
134
+ describe "#update" do
135
+ it "makes a new PUT request using the correct API endpoint" do
136
+ expect(Shipcloud).to receive(:request).with(
137
+ :put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: nil
138
+ ).and_return("data" => {})
139
+
140
+ address = Shipcloud::Address.new(id: "123")
141
+
142
+ address.update(street: "Mittelweg")
143
+ end
144
+
145
+ it "uses the affiliate ID provided for the request" do
146
+ expect(Shipcloud).to receive(:request).with(
147
+ :put, "addresses/123", { street: "Mittelweg" }, api_key: nil, affiliate_id: "affiliate_id"
148
+ ).and_return("data" => {})
149
+
150
+ address = Shipcloud::Address.new(id: "123")
151
+
152
+ address.update({ street: "Mittelweg" }, affiliate_id: "affiliate_id")
153
+ end
154
+ end
155
+
132
156
  def stub_addresses_request(affiliate_id: nil)
133
157
  allow(Shipcloud).to receive(:request).
134
158
  with(:get, "addresses", {}, api_key: nil, affiliate_id: affiliate_id).
@@ -146,7 +170,7 @@ describe Shipcloud::Address do
146
170
  "city" => "Musterstadt",
147
171
  "state" => "",
148
172
  "country" => "DE",
149
- "phone" => ""
173
+ "phone" => "",
150
174
  },
151
175
  {
152
176
  "id" => "7ea2a290-b456-4ecf-9010-e82b3da298f0",
@@ -160,9 +184,9 @@ describe Shipcloud::Address do
160
184
  "city" => "Musterstadt",
161
185
  "state" => "",
162
186
  "country" => "DE",
163
- "phone" => ""
164
- }
165
- ]
187
+ "phone" => "",
188
+ },
189
+ ],
166
190
  )
167
191
  end
168
192