intelipost 0.0.6 → 0.0.7

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.
data/README.md CHANGED
@@ -9,28 +9,41 @@ Gem for the Intelipost API
9
9
 
10
10
  ### Usage:
11
11
 
12
+ #### Address Complete (CEP)
13
+
12
14
  ````ruby
13
15
  # GET /cep_address/complete
14
16
  require 'intelipost'
15
17
 
16
18
  client = Intelipost::Client.new api_key: <your api key>
17
- address = client.cep.address_complete '05307000'
19
+ address = client.cep.address_complete.get '05307000'
18
20
  # => #<Hashie::Mash content=#<Hashie::Mash bairro="Vila Ribeiro de Barros" city="São Paulo" ibge="3550308" neighborhood="Vila Ribeiro de Barros" state="São Paulo" state_short="SP" street="R Maj Paladino"> messages=[] status="OK" time="0.6 ms">
19
21
  address.content.street
20
22
  # => "R Maj Paladino"
21
23
  ````
22
24
 
25
+ #### Quote (Cotação)
26
+
23
27
  ````ruby
24
28
  # POST /quote
25
29
  require 'intelipost'
26
30
 
27
31
  client = Intelipost::Client.new api_key: <your api key>
28
- quote = client.quote.create({hash_of :intelipost, required: :args})
32
+ quote = client.quote.create({hash_of: :intelipost, args: :values})
29
33
  # => #<Hashie::Mash content=#<Hashie::Mash additional_information=#<Hashie::Mash client_type="gold" delivery_method_ids=[4, 3, 2] extra_cost_absolute=0.0 extra_cost_percentage=0.0 free_shipping=false lead_time_business_days=0 sales_channel="hotsite" tax_id=nil> client_id=1783 created=1433872646799 created_iso="2015-06-09T14:57:26.799-03:00" delivery_options=[#<Hashie::Mash delivery_estimate_business_days=1 delivery_method_id=4 delivery_method_name="Total Express" delivery_method_type="EXPRESS" delivery_note=nil description="Total Express" final_shipping_cost=5.05 logistic_provider_name="Total" provider_shipping_cost=5.05>, #<Hashie::Mash delivery_estimate_business_days=1 delivery_method_id=3 delivery_method_name="Correios eSedex" delivery_method_type="EXPRESS" delivery_note=nil description="Correios eSedex" final_shipping_cost=7.83 logistic_provider_name="Correios" provider_shipping_cost=7.83>, #<Hashie::Mash delivery_estimate_business_days=1 delivery_method_id=2 delivery_method_name="Correios Sedex" delivery_method_type="EXPRESS" delivery_note=nil description="Correios Sedex" final_shipping_cost=13.83 logistic_provider_name="Correios" provider_shipping_cost=13.83>] destination_zip_code="06396-200" id=4347667 origin_zip_code="04037-003" platform=nil volumes=[#<Hashie::Mash cost_of_goods=100.0 description=nil height=10.0 length=10.0 volume_type="BOX" weight=0.1 width=10.0>]> messages=[] status="OK" time="34.0 ms">
30
34
  quote.content.id
31
35
  # => 4347667
32
36
  ````
33
37
 
38
+ ````ruby
39
+ # GET /quote/{id}
40
+ require 'intelipost'
41
+ client = Intelipost::Client.new api_key: <your api key>
42
+ quote = client.quote.get(124560)
43
+ ````
44
+
45
+ #### Shipment Order (Pedido de Envio)
46
+
34
47
  ````ruby
35
48
  # POST /shipment_order
36
49
  require 'intelipost'
@@ -39,6 +52,30 @@ client = Intelipost::Client.new api_key: <your api key>
39
52
  client.shipment_order.create({hash_of: :intelipost, args: :values})
40
53
  ````
41
54
 
55
+ ````ruby
56
+ # POST /shipment_order/set_invoice
57
+ require 'intelipost'
58
+
59
+ client = Intelipost::Client.new api_key: <your api key>
60
+ client.shipment_order.set_invoice.update({hash_of: :intelipost, args: :values})
61
+ ````
62
+
63
+ ````ruby
64
+ # POST /shipment_order/set_tracking_data
65
+ require 'intelipost'
66
+
67
+ client = Intelipost::Client.new api_key: <your api key>
68
+ client.shipment_order.set_tracking_data.update({hash_of: :intelipost, args: :values})
69
+ ````
70
+
71
+ ````ruby
72
+ # GET /shipment_order/read_status/{order_number}
73
+ require 'intelipost'
74
+
75
+ client = Intelipost::Client.new api_key: <your api key>
76
+ client.shipment_order.read_status.get(124560)
77
+ ````
78
+
42
79
  ### Development:
43
80
 
44
81
  For testing, create a `.env` file with the following content:
@@ -1,5 +1,32 @@
1
1
  module Intelipost
2
2
  module FluentInterface
3
+
4
+ def self.included(cls)
5
+ cls.extend(ClassMethods)
6
+ end
7
+
8
+ def create(post_values)
9
+ connection.post(@fluent_interfaces.join('/'), post_values)
10
+ end
11
+
12
+ def update(post_values)
13
+ create(post_values)
14
+ end
15
+
16
+ def get(value)
17
+ connection.get([@fluent_interfaces, value].join('/'))
18
+ end
19
+
20
+ def method_missing(method, *args, &block)
21
+ add_fluent_interface_path(method)
22
+ self
23
+ end
24
+
25
+ private
26
+ def add_fluent_interface_path(method)
27
+ @fluent_interfaces << method
28
+ end
29
+
3
30
  module ClassMethods
4
31
  def set_endpoint endpoint
5
32
  define_method :endpoint do
@@ -7,29 +34,15 @@ module Intelipost
7
34
  end
8
35
  end
9
36
  end
10
-
11
- module InstanceMethods
12
- def create(post_values)
13
- connection.post(endpoint, post_values)
14
- end
15
-
16
- def method_missing(method, *args, &block)
17
- connection.get [endpoint, method, args].join '/'
18
- end
19
- end
20
37
  end
21
38
 
22
39
  class FluentInterfaceBase
23
- extend Intelipost::FluentInterface::ClassMethods
24
- include Intelipost::FluentInterface::InstanceMethods
40
+ include Intelipost::FluentInterface
25
41
  attr_accessor :connection
26
42
 
27
43
  def initialize(connection)
28
44
  @connection = connection
29
- end
30
-
31
- def spawn
32
- clone
45
+ @fluent_interfaces = [endpoint]
33
46
  end
34
47
  end
35
48
  end
@@ -1,3 +1,3 @@
1
1
  module Intelipost
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
@@ -4,7 +4,7 @@ describe Intelipost::Cep do
4
4
  describe '#address_complete' do
5
5
  it 'correctly queries the cep' do
6
6
  expect(subject.connection).to receive(:get).with('cep_location/address_complete/00000000')
7
- subject.address_complete '00000000'
7
+ subject.address_complete.get '00000000'
8
8
  end
9
9
  end
10
10
  end
@@ -19,6 +19,12 @@ describe Intelipost::Client, :vcr do
19
19
  end
20
20
  end
21
21
 
22
+ context 'when call for an non existing defined class' do
23
+ it '.method_missing' do
24
+ expect { subject.foobar(1) }.to raise_error ArgumentError
25
+ end
26
+ end
27
+
22
28
  context 'initialized with credentials' do
23
29
  describe '#connection' do
24
30
  it 'is an instance of Faraday::Connection' do
@@ -39,11 +45,11 @@ describe Intelipost::Client, :vcr do
39
45
 
40
46
  context 'dealing with zipcode (cep)' do
41
47
  it 'returns a Hashie::Mash on successful query' do
42
- expect(subject.cep.address_complete('04661100').class).to be Hashie::Mash
48
+ expect(subject.cep.address_complete.get('04661100').class).to eq Hashie::Mash
43
49
  end
44
50
  end
45
51
 
46
- context 'request quotations' do
52
+ context 'dealing with Quotes' do
47
53
  let(:volumes) do
48
54
  {
49
55
  'origin_zip_code' => '04037-003',
@@ -77,5 +83,10 @@ describe Intelipost::Client, :vcr do
77
83
  it '.quote.create' do
78
84
  expect(subject.quote.create(volumes)).to have_key(:content)
79
85
  end
86
+
87
+ it '.quote.get(#)' do
88
+ quote_id = subject.quote.create(volumes).content.id
89
+ expect(subject.quote.get(quote_id)).to have_key(:content)
90
+ end
80
91
  end
81
92
  end
@@ -35,4 +35,10 @@ describe Intelipost::Quote do
35
35
  expect(subject.connection).to receive(:post).with('quote', volumes)
36
36
  subject.create(volumes)
37
37
  end
38
+
39
+ it 'will pull an existing quote by its id' do
40
+ id = 99
41
+ expect(subject.connection).to receive(:get).with("quote/#{id}")
42
+ subject.get(99)
43
+ end
38
44
  end
@@ -58,4 +58,54 @@ describe Intelipost::ShipmentOrder do
58
58
  expect(subject.connection).to receive(:post).with('shipment_order', order_to_ship)
59
59
  subject.create(order_to_ship)
60
60
  end
61
+
62
+ let(:order_invoice) do
63
+ {
64
+ 'order_number' => '12314324',
65
+ 'shipment_order_volume_invoice_array' => [
66
+ {
67
+ 'shipment_order_volume_number' => '1',
68
+ 'invoice_series' => '123123123',
69
+ 'invoice_number' => 'BR283248123',
70
+ 'invoice_key' => 'CDFx2342396078192310231982',
71
+ 'invoice_date' => '2014-02-28',
72
+ 'invoice_total_value' => '32,49',
73
+ 'invoice_products_value' => '28,99',
74
+ 'invoice_cfop' => '5120'
75
+ }
76
+ ]
77
+ }
78
+ end
79
+
80
+ it 'invoice update' do
81
+ expect(subject.connection).to receive(:post).with('shipment_order/set_invoice', order_invoice)
82
+ subject.set_invoice.update(order_invoice)
83
+ end
84
+
85
+ let(:order_tracking_code) do
86
+ {
87
+ 'order_number' => 'BR12345',
88
+ 'tracking_data_array' => [
89
+ {
90
+ 'shipment_order_volume_number' => 1,
91
+ 'tracking_code' => 'SW123456789BR'
92
+ },
93
+ {
94
+ 'shipment_order_volume_number' => 2,
95
+ 'tracking_code' => 'SW123456789BR'
96
+ }
97
+ ]
98
+ }
99
+ end
100
+
101
+ it 'tracking update' do
102
+ expect(subject.connection).to receive(:post).with('shipment_order/set_tracking_data', order_tracking_code)
103
+ subject.set_tracking_data.update(order_tracking_code)
104
+ end
105
+
106
+ it 'read status from API' do
107
+ order_id = 128492394
108
+ expect(subject.connection).to receive(:get).with("shipment_order/read_status/#{order_id}")
109
+ subject.read_status.get(order_id)
110
+ end
61
111
  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.6
4
+ version: 0.0.7
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-10 00:00:00.000000000 Z
12
+ date: 2015-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday