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
@@ -1,33 +0,0 @@
1
- module Shipcloud
2
- module Request
3
- class Validator
4
- attr_reader :info
5
- attr_accessor :response
6
-
7
- def initialize(info)
8
- @info = info
9
- end
10
-
11
- def validated_data_for(incoming_response)
12
- self.response = incoming_response
13
- verify_response_code
14
- if response.body
15
- info.data = JSON.parse(response.body)
16
- validate_response_data
17
- end
18
- info.data
19
- end
20
-
21
- protected
22
-
23
- def verify_response_code
24
- raise AuthenticationError if response.code.to_i == 401
25
- raise APIError if response.code.to_i >= 500
26
- end
27
-
28
- def validate_response_data
29
- raise APIError.new(info.data["errors"]) if info.data.is_a?(Hash) && info.data["errors"]
30
- end
31
- end
32
- end
33
- end
@@ -1,24 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Shipcloud::Request::Validator do
4
- describe "#validated_data_for" do
5
- it "validates the data" do
6
- info = Shipcloud::Request::Info.new(:get, "random", OpenStruct.new(id: 1))
7
- validator = Shipcloud::Request::Validator.new info
8
- response = OpenStruct.new(body: '{"response":"ok"}', code: 200)
9
-
10
- validator.validated_data_for(response).should eq "response" => "ok"
11
- end
12
-
13
- it 'raises an APIError if the response contains errors' do
14
- info = Shipcloud::Request::Info.new(:get, 'random', {})
15
- validator = Shipcloud::Request::Validator.new info
16
- response = OpenStruct.new(body: '{"errors":["some error"]}', code: 200)
17
-
18
- expect { validator.validated_data_for(response) }.to raise_error(
19
- Shipcloud::APIError,
20
- ['some error'].to_s
21
- )
22
- end
23
- end
24
- end