shipcloud 0.6.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.codeclimate.yml +1 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +713 -2
- data/.ruby-version +1 -0
- data/.travis.yml +18 -6
- data/CHANGELOG.md +70 -0
- data/README.md +76 -8
- data/bin/rubocop +29 -0
- data/install-cc-test-reporter.sh +4 -0
- data/lib/shipcloud.rb +28 -14
- data/lib/shipcloud/address.rb +2 -1
- data/lib/shipcloud/operations/all.rb +12 -2
- data/lib/shipcloud/operations/create.rb +10 -2
- data/lib/shipcloud/operations/delete.rb +10 -2
- data/lib/shipcloud/operations/find.rb +10 -2
- data/lib/shipcloud/operations/update.rb +12 -4
- data/lib/shipcloud/pickup_request.rb +12 -0
- data/lib/shipcloud/request/base.rb +14 -10
- data/lib/shipcloud/request/connection.rb +18 -12
- data/lib/shipcloud/request/info.rb +7 -5
- data/lib/shipcloud/shipcloud_error.rb +70 -0
- data/lib/shipcloud/shipment.rb +3 -2
- data/lib/shipcloud/tracker.rb +13 -0
- data/lib/shipcloud/version.rb +1 -1
- data/lib/shipcloud/webhook.rb +2 -1
- data/shipcloud.gemspec +9 -8
- data/spec/shipcloud/address_spec.rb +114 -43
- data/spec/shipcloud/carrier_spec.rb +12 -5
- data/spec/shipcloud/pickup_request_spec.rb +136 -0
- data/spec/shipcloud/request/base_spec.rb +51 -13
- data/spec/shipcloud/request/connection_spec.rb +3 -3
- data/spec/shipcloud/request/info_spec.rb +34 -0
- data/spec/shipcloud/shipcloud_error_spec.rb +125 -0
- data/spec/shipcloud/shipment_quote_spec.rb +14 -1
- data/spec/shipcloud/shipment_spec.rb +126 -11
- data/spec/shipcloud/tracker_spec.rb +141 -0
- data/spec/shipcloud/webhooks_spec.rb +70 -6
- data/spec/shipcloud_spec.rb +82 -20
- data/spec/spec_helper.rb +2 -2
- metadata +55 -43
- data/.ruby-style.yml +0 -240
- data/lib/shipcloud/request/validator.rb +0 -33
- 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
|