intelipost 0.0.7 → 0.0.8

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.
@@ -1,3 +1,5 @@
1
+ require 'intelipost/mash'
2
+
1
3
  module Intelipost
2
4
  class Client
3
5
  HOST = 'api.intelipost.com.br'
@@ -24,7 +26,7 @@ module Intelipost
24
26
  Faraday.new(url: @uri.to_s) do |conn|
25
27
  conn.request :json
26
28
 
27
- conn.response :mashify
29
+ conn.response :mashify, { mash_class: Intelipost::Mash }
28
30
  conn.response :json
29
31
 
30
32
  conn.headers['api_key'] = api_key
@@ -0,0 +1,16 @@
1
+ module Intelipost
2
+ class Mash < ::Hashie::Mash
3
+ def success?
4
+ self.has_key?('status') and self.status == 'OK'
5
+ end
6
+
7
+ def failure?
8
+ !success?
9
+ end
10
+
11
+ def all_messages
12
+ return unless self.has_key?('messages')
13
+ self.messages.map(&:text).join(';')
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Intelipost
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -44,8 +44,13 @@ describe Intelipost::Client, :vcr do
44
44
  end
45
45
 
46
46
  context 'dealing with zipcode (cep)' do
47
- it 'returns a Hashie::Mash on successful query' do
48
- expect(subject.cep.address_complete.get('04661100').class).to eq Hashie::Mash
47
+ it 'returns a Intelipost::Mash on successful query' do
48
+ response = subject.cep.address_complete.get('04661100')
49
+ expect(response.class).to eq Intelipost::Mash
50
+ expect(response.success?).to eq true
51
+ expect(response.failure?).to eq false
52
+ expect(response.all_messages).to eq ''
53
+ expect(response.messages).to be_empty
49
54
  end
50
55
  end
51
56
 
@@ -84,6 +89,14 @@ describe Intelipost::Client, :vcr do
84
89
  expect(subject.quote.create(volumes)).to have_key(:content)
85
90
  end
86
91
 
92
+ it '.quote.create.failure' do
93
+ response = subject.quote.create({'failure'=>'failure'})
94
+ expect(response.success?).to eq false
95
+ expect(response.failure?).to eq true
96
+ expect(response.all_messages).not_to eq ''
97
+ expect(response.messages).not_to be_empty
98
+ end
99
+
87
100
  it '.quote.get(#)' do
88
101
  quote_id = subject.quote.create(volumes).content.id
89
102
  expect(subject.quote.get(quote_id)).to have_key(:content)
@@ -0,0 +1,19 @@
1
+ describe Intelipost::Mash do
2
+ it 'will create a intelipost mash and check if it is a success response' do
3
+ mash = Intelipost::Mash.new({status: 'OK'})
4
+ expect(mash.success?).to eq true
5
+ expect(mash.failure?).to eq false
6
+ expect(mash.all_messages).to eq nil
7
+ end
8
+
9
+ it 'will create a intelipost mash and check if it is a failure response' do
10
+ mash = Intelipost::Mash.new({messages:[
11
+ {text: 'some error message'},
12
+ {text: 'some error message2'}
13
+ ]})
14
+ expect(mash.success?).to eq false
15
+ expect(mash.failure?).to eq true
16
+ expect(mash.all_messages).to eq 'some error message;some error message2'
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intelipost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-18 00:00:00.000000000 Z
12
+ date: 2015-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -206,12 +206,14 @@ files:
206
206
  - lib/intelipost/cep.rb
207
207
  - lib/intelipost/client.rb
208
208
  - lib/intelipost/fluent_interface.rb
209
+ - lib/intelipost/mash.rb
209
210
  - lib/intelipost/quote.rb
210
211
  - lib/intelipost/shipment_order.rb
211
212
  - lib/intelipost/version.rb
212
213
  - lib/middleware/gzip.rb
213
214
  - spec/lib/intelipost/cep_spec.rb
214
215
  - spec/lib/intelipost/client_spec.rb
216
+ - spec/lib/intelipost/mash_spec.rb
215
217
  - spec/lib/intelipost/quote_spec.rb
216
218
  - spec/lib/intelipost/shipment_order_spec.rb
217
219
  - spec/spec_helper.rb
@@ -243,6 +245,7 @@ summary: Gem to access the REST API of Intelipost
243
245
  test_files:
244
246
  - spec/lib/intelipost/cep_spec.rb
245
247
  - spec/lib/intelipost/client_spec.rb
248
+ - spec/lib/intelipost/mash_spec.rb
246
249
  - spec/lib/intelipost/quote_spec.rb
247
250
  - spec/lib/intelipost/shipment_order_spec.rb
248
251
  - spec/spec_helper.rb