posthorn 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c7cfb6a47a54db8e17f7b6439fb8eee498149f9
4
- data.tar.gz: 724d2a078e2c60de907cd197cdb1ed4187b18a1e
3
+ metadata.gz: 38cf28bbdedaa106511e7c87068e721bc0e97cba
4
+ data.tar.gz: 727a1a98221180447bb9ecf2d1cdde6cbb7d4eaf
5
5
  SHA512:
6
- metadata.gz: 1e6c71cbd4f1830666e353a0367a48114a756bb3de4f9e5e460b2d33acb4c184e4d3332214de6df4530bf3222b8db6da0fab85defc03ccd0665bdd551ab13d59
7
- data.tar.gz: d31e64dbce5574fe35f0b255f50e96d8674b8c125b4b9abcc57c9f5d2ded531205e72a4b85e5fbadfb936530f0c817ef0b70eb0341fd133b142c478497df209b
6
+ metadata.gz: c64cfd823e64dc75581d4ce64b84f44cbc773a6c0c18b16ec8149a41a00fbdeaa1e2cb4bd77d5b3e53631013e195f07a95bccb224854d8959b352bd17a66a11c
7
+ data.tar.gz: 635a5bec2b8dfe6bf2e2f9eb089f9a5a9ed6559c23bd97751cffa9ffce3212e9f5b31baa417aa5ebfbe08864de0cb84f371b8b6315d347df672b247ebaa0d880
@@ -5,10 +5,15 @@ module Posthorn
5
5
 
6
6
  def initialize
7
7
  @client = SoapClient.new
8
- @user = @client.authenticate
9
8
  @cart = []
10
9
  end
11
10
 
11
+ def user
12
+ @user ||= begin
13
+ @client.authenticate
14
+ end
15
+ end
16
+
12
17
  def page_formats
13
18
  response = @client.call(:retrieve_page_formats)
14
19
  response.body[:retrieve_page_formats_response][:page_format].map do |fmt|
@@ -16,21 +21,25 @@ module Posthorn
16
21
  end
17
22
  end
18
23
 
24
+ def balance
25
+ cents = 0
26
+ @cart.each { |label| cents += label.price }
27
+ cents
28
+ end
29
+
19
30
  def checkout!(args = {})
20
31
  page = 0
21
- price = 0
22
- @cart.each { |label| price += label.price }
23
32
 
24
33
  message = {
25
- userToken: @user.user_token,
34
+ userToken: user.user_token,
26
35
  pageFormatId: args[:page_format] || 25, # Brother 62mm
27
36
  positions: @cart.map.with_index { |label, ix| label.to_h(page: ix) },
28
- total: price
37
+ total: balance
29
38
  }
30
39
 
31
40
  response = @client.call(:checkout_shopping_cart_pdf, message)
32
41
  data = response.body[:checkout_shopping_cart_pdf_response]
33
- @user.wallet_balance = data[:wallet_ballance]
42
+ user.wallet_balance = data[:wallet_ballance]
34
43
 
35
44
  @cart.clear
36
45
 
@@ -40,5 +49,6 @@ module Posthorn
40
49
  request.read_timeout = 240
41
50
  HTTPI.get(request).body
42
51
  end
52
+
43
53
  end
44
54
  end
@@ -1,3 +1,3 @@
1
1
  module Posthorn
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.7'
3
3
  end
data/spec/office_spec.rb CHANGED
@@ -45,4 +45,32 @@ describe Office do
45
45
  expect(labels.length).to be >= 100
46
46
  end
47
47
 
48
+ it 'should return cart\' balance' do
49
+ office = Office.new
50
+
51
+ receiver = Address.new(
52
+ company: 'Hans Peter Wurst Inc.',
53
+ firstname: 'Hans Peter',
54
+ lastname: 'Wurst',
55
+ street: 'Schoolstraat',
56
+ no: '2',
57
+ city: 'Lemiers',
58
+ zip: '6295',
59
+ country: 'de')
60
+
61
+ sender = Address.new(
62
+ company: 'AISLER B.V.',
63
+ street: 'Schoolstraat',
64
+ no: '2',
65
+ city: 'Lemiers',
66
+ zip: '6295AV',
67
+ country: 'nl')
68
+
69
+ office.cart << Label.new(sender, receiver, product_id: 21, price: 145)
70
+ office.cart << Label.new(sender, receiver, product_id: 21, price: 145)
71
+ office.cart << Label.new(sender, receiver, product_id: 21, price: 145)
72
+
73
+ expect(office.balance).to eq(3 * 145)
74
+ end
75
+
48
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: posthorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Franken
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-06 00:00:00.000000000 Z
12
+ date: 2017-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon