onlinebrief24 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/rmoriz/onlinebrief24.png)](https://travis-ci.org/rmoriz/onlinebrief24)
4
4
 
5
- This gem is only interesting for users that use the German letter outbound service Onlinebrief24.de. This gem wraps the required workflow to upload a PDF to Onlinebrief24's servers. Onlinebrief24 then prints and mails the letters via snail mail. As this service is only available to German customers, the following documentation is available in German language only.
5
+ This gem is only interesting for users that use the German letter outbound service <a href="http://www.onlinebrief24.de/">Onlinebrief24.de</a>. This gem wraps the required workflow to upload a PDF to Onlinebrief24's servers. Onlinebrief24 then prints and mails the letters via snail mail. As this service is only available to German customers, the following documentation is available in German language only.
6
6
 
7
7
  ## Voraussetzung
8
8
 
@@ -30,7 +30,7 @@ $ gem install onlinebrief24
30
30
 
31
31
  ## Beispiele
32
32
 
33
- #### Kurzform
33
+ ### Kurzform
34
34
  ```ruby
35
35
  require 'onlinebrief24'
36
36
 
@@ -43,6 +43,139 @@ c.upload! '/tmp/filename3.pdf', :registered => :standard, :distribution => :int
43
43
  c.disconnect
44
44
  ```
45
45
 
46
+ ### Block
47
+
48
+ ```ruby
49
+ require 'onlinebrief24'
50
+
51
+ Onlinebrief24::Client.new(:login => 'email@example.com', :password => '123456') do |client|
52
+ client.upload! '/tmp/filename1.pdf', :duplex => true, :color => false
53
+ client.upload! '/tmp/filename2.pdf', :registered => :insertion, :envelope => :c4
54
+ client.upload! '/tmp/filename3.pdf', :registered => :standard, :distribution => :international
55
+ end
56
+ ```
57
+
58
+ ### Optionen für Brief
59
+
60
+ <table width="100%">
61
+ <tr>
62
+ <th>Option</th>
63
+ <th>Werte</th>
64
+ <th>Vorbelegung</th>
65
+ <th>Beschreibung</th>
66
+ </tr>
67
+ <tr>
68
+ <td>
69
+ <strong>:color</strong>
70
+ </td>
71
+ <td>
72
+ <ul>
73
+ <li>true</li>
74
+ <li>false</li>
75
+ </ul>
76
+ </td>
77
+ <td>
78
+ false
79
+ </td>
80
+ <td>
81
+ Farbdruck ja/nein
82
+ </td>
83
+ </tr>
84
+
85
+ <tr>
86
+ <td>
87
+ <strong>:duplex</strong>
88
+ </td>
89
+ <td>
90
+ <ul>
91
+ <li>true</li>
92
+ <li>false</li>
93
+ </ul>
94
+ </td>
95
+ <td>
96
+ false
97
+ </td>
98
+ <td>
99
+ Duplexdruck ja/nein
100
+ </td>
101
+ </tr>
102
+
103
+ <tr>
104
+ <td>
105
+ <strong>:envelope</strong>
106
+ </td>
107
+ <td>
108
+ <ul>
109
+ <li>:din_lang</li>
110
+ <li>:c4</li>
111
+ </ul>
112
+ </td>
113
+ <td>
114
+ :din_lang
115
+ </td>
116
+ <td>
117
+ Umschlagformat. DIN lang oder C4.
118
+ </td>
119
+ </tr>
120
+
121
+ <tr>
122
+ <td>
123
+ <strong>:distribution</strong>
124
+ </td>
125
+ <td>
126
+ <ul>
127
+ <li>:auto</li>
128
+ <li>:national</li>
129
+ <li>:international</li>
130
+ </ul>
131
+ </td>
132
+ <td>
133
+ :auto
134
+ </td>
135
+ <td>
136
+ Versandzone. Automatisch, National, International
137
+ </td>
138
+ </tr>
139
+
140
+ <tr>
141
+ <td>
142
+ <strong>:registered</strong>
143
+ </td>
144
+ <td>
145
+ <ul>
146
+ <li>:none</li>
147
+ <li>:insertion</li>
148
+ <li>:standard</li>
149
+ <li>:personal</li>
150
+ </ul>
151
+ </td>
152
+ <td>
153
+ :none
154
+ </td>
155
+ <td>
156
+ Einschreiben: Nein, Einwurf-Einschreiben, Standard-Einschreiben, Einschreiben eigenhändig
157
+ </td>
158
+ </tr>
159
+
160
+
161
+ </table>
162
+
163
+
164
+ ### Hinweis
165
+
166
+ * PDF-Dateien müssen unter Beachtung der Vorgaben von Onlinebrief24 erstellt und formatiert werden:
167
+ http://www.onlinebrief24.de/software/infodokumente.htm
168
+ * Dieses gem benutzt die SFTP-Schnittstelle:
169
+ http://www.onlinebrief24.de/software/sftp-schnittstelle.htm
170
+
171
+ ### Ausprobieren / Keine Funktionsgarantie!
172
+
173
+ Onlinebrief24 räumt jedem Neukunden ein Guthaben von 5 EUR ein. Es wird empfohlen die Benutzung dieses rubygems damit zu testen. Die vorhandenen Tests (RSpec) im ```spec```-Verzeichnis können dies nicht ersetzen!
174
+
175
+
176
+ ### Fehler? Probleme? Patches?
177
+
178
+ Bitte Fehler, Probeme und Patches über Github Issues bzw Pull-Requests einreichen.
46
179
 
47
180
  ## Contributing
48
181
 
@@ -52,6 +185,9 @@ c.disconnect
52
185
  4. Push to the branch (`git push origin my-new-feature`)
53
186
  5. Create new Pull Request
54
187
 
188
+ ## Hinweis
189
+
190
+ Dies ist ein unabhängiges OpenSource-Projekt und kein offizielles Produkt von Onlinebrief24.de.
55
191
 
56
192
  ## Copyright
57
193
 
@@ -4,12 +4,20 @@ module Onlinebrief24
4
4
  class Client
5
5
  attr_accessor :login, :password, :server, :port, :upload_dir, :fingerprint
6
6
 
7
- def initialize(opts = {})
7
+ def initialize(opts = {}, &block)
8
8
  @login = opts[:login]
9
9
  @password = opts[:password]
10
10
  @server = opts[:server] || 'api.onlinebrief24.de'
11
11
  @port = opts[:port] || 22
12
12
  @upload_dir = opts[:upload_dir] || '/upload/api'
13
+
14
+ return unless block_given?
15
+
16
+ begin
17
+ yield self
18
+ ensure
19
+ disconnect
20
+ end
13
21
  end
14
22
 
15
23
  def upload!(letter_or_file_handle_or_filename, options = {})
@@ -37,6 +45,7 @@ module Onlinebrief24
37
45
  alias_method :connect, :connection
38
46
 
39
47
  def disconnect
48
+ puts "disconnecting"
40
49
  @connection.close if @connection and @connection.open?
41
50
  end
42
51
 
@@ -21,7 +21,7 @@ module Onlinebrief24
21
21
 
22
22
  def defaults
23
23
  {
24
- :color => true,
24
+ :color => false,
25
25
  :duplex => false,
26
26
  :envelope => :din_lang,
27
27
  :distribution => :auto,
@@ -1,3 +1,3 @@
1
1
  module Onlinebrief24
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ['roland@moriz.de']
11
11
  gem.description = %q{A gem to interact with onlinebrief24.de (send PDFs as physical letters/snail mail)}
12
12
  gem.summary = %q{A gem to interact with onlinebrief24.de (send PDFs as physical letters/snail mail)}
13
- gem.homepage = 'https://github.com/rmoriz'
13
+ gem.homepage = 'https://github.com/rmoriz/onlinebrief24'
14
14
  gem.license = 'MIT'
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
@@ -55,30 +55,53 @@ describe Onlinebrief24::Client do
55
55
 
56
56
  it 'should upload the letter with the correct remote filename' do
57
57
  sftp = double('sftp')
58
- sftp.should_receive(:upload!).with(local_path, '/upload/api/1000000000000_example.pdf').once
58
+ sftp.should_receive(:upload!).with(local_path, '/upload/api/0000000000000_example.pdf').once
59
59
 
60
60
  Net::SFTP.should_receive(:start).with('api.onlinebrief24.de', params[:login], :password => params[:password]) { sftp }
61
61
 
62
- subject.upload!(filehandle).should eql('1000000000000_example.pdf')
62
+ subject.upload!(filehandle).should eql('0000000000000_example.pdf')
63
63
  end
64
64
  end
65
65
 
66
66
  describe 'with a filename' do
67
67
  it 'should upload the letter with the correct remote filename' do
68
68
  sftp = double('sftp')
69
- sftp.should_receive(:upload!).with(local_path, '/upload/api/1000000000000_example.pdf').once
69
+ sftp.should_receive(:upload!).with(local_path, '/upload/api/0000000000000_example.pdf').once
70
70
 
71
71
  Net::SFTP.should_receive(:start).with('api.onlinebrief24.de', params[:login], :password => params[:password]) { sftp }
72
72
 
73
- subject.upload!(local_path).should eql('1000000000000_example.pdf')
73
+ subject.upload!(local_path).should eql('0000000000000_example.pdf')
74
74
  end
75
75
  it 'should upload the letter with the correct remote filename with options' do
76
76
  sftp = double('sftp')
77
- sftp.should_receive(:upload!).with(local_path, '/upload/api/0100000000000_example.pdf').once
77
+ sftp.should_receive(:upload!).with(local_path, '/upload/api/1100000000000_example.pdf').once
78
78
 
79
79
  Net::SFTP.should_receive(:start).with('api.onlinebrief24.de', params[:login], :password => params[:password]) { sftp }
80
80
 
81
- subject.upload!(local_path, :duplex => true, :color => false).should eql('0100000000000_example.pdf')
81
+ subject.upload!(local_path, :duplex => true, :color => true).should eql('1100000000000_example.pdf')
82
+ end
83
+ end
84
+ end
85
+
86
+ describe 'block syntax' do
87
+ let(:local_path) { File.expand_path('../../example_files/example.pdf', __FILE__) }
88
+
89
+ it 'should maintain the connection state' do
90
+ # re-used connection
91
+ connection = double('connection')
92
+ connection.should_receive(:open?).twice { true }
93
+ connection.should_receive(:upload!).exactly(3).times
94
+
95
+ # connect on first demand
96
+ Net::SFTP.should_receive(:start).once { connection }
97
+
98
+ # disconnect when block closes
99
+ Onlinebrief24::Client.any_instance.should_receive(:disconnect).once
100
+
101
+ Onlinebrief24::Client.new(params) do |client|
102
+ client.upload!(local_path, :color => true)
103
+ client.upload!(local_path, :color => true)
104
+ client.upload!(local_path, :color => true)
82
105
  end
83
106
  end
84
107
  end
@@ -56,7 +56,7 @@ describe Onlinebrief24::Letter do
56
56
 
57
57
  describe '#color' do
58
58
  context 'default' do
59
- its(:color) { should be_true }
59
+ its(:color) { should be_false }
60
60
  end
61
61
  context 'disabled' do
62
62
  let(:options) { { :color => false } }
@@ -124,12 +124,12 @@ describe Onlinebrief24::Letter do
124
124
 
125
125
  describe 'remote_filename' do
126
126
  context 'default' do
127
- its(:remote_filename) { should eql('1000000000000_example.pdf') }
127
+ its(:remote_filename) { should eql('0000000000000_example.pdf') }
128
128
  end
129
129
 
130
130
  context 'default with cost center' do
131
131
  let(:options) { { :cost_center => 'trash_and_law' } }
132
- its(:remote_filename) { should eql('1000000000000_example#trash_and_law#.pdf') }
132
+ its(:remote_filename) { should eql('0000000000000_example#trash_and_law#.pdf') }
133
133
  end
134
134
 
135
135
  describe 'color duplex with c4 envelope' do
@@ -140,34 +140,34 @@ describe Onlinebrief24::Letter do
140
140
  context 'distribution' do
141
141
  describe 'auto' do
142
142
  let(:options) { { :distribution => :auto } }
143
- its(:remote_filename) { should eql('1000000000000_example.pdf') }
143
+ its(:remote_filename) { should eql('0000000000000_example.pdf') }
144
144
  end
145
145
  describe 'national' do
146
146
  let(:options) { { :distribution => :national } }
147
- its(:remote_filename) { should eql('1001000000000_example.pdf') }
147
+ its(:remote_filename) { should eql('0001000000000_example.pdf') }
148
148
  end
149
149
  describe 'international' do
150
150
  let(:options) { { :distribution => :international } }
151
- its(:remote_filename) { should eql('1003000000000_example.pdf') }
151
+ its(:remote_filename) { should eql('0003000000000_example.pdf') }
152
152
  end
153
153
  end
154
154
 
155
155
  context 'registered (Einschreiben)' do
156
156
  describe 'none' do
157
- let(:options) { { :registered => :none} }
158
- its(:remote_filename) { should eql('1000000000000_example.pdf') }
157
+ let(:options) { { :registered => :none } }
158
+ its(:remote_filename) { should eql('0000000000000_example.pdf') }
159
159
  end
160
160
  describe 'insertion (Einwurf)' do
161
161
  let(:options) { { :registered => :insertion } }
162
- its(:remote_filename) { should eql('1000100000000_example.pdf') }
162
+ its(:remote_filename) { should eql('0000100000000_example.pdf') }
163
163
  end
164
164
  describe 'standard' do
165
165
  let(:options) { { :registered => :standard } }
166
- its(:remote_filename) { should eql('1000200000000_example.pdf') }
166
+ its(:remote_filename) { should eql('0000200000000_example.pdf') }
167
167
  end
168
168
  describe 'personal (eigenhaendig)' do
169
169
  let(:options) { { :registered => :personal } }
170
- its(:remote_filename) { should eql('1000300000000_example.pdf') }
170
+ its(:remote_filename) { should eql('0000300000000_example.pdf') }
171
171
  end
172
172
  end
173
173
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlinebrief24
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
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: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-sftp
@@ -133,7 +133,7 @@ files:
133
133
  - spec/onlinebrief24/letter_spec.rb
134
134
  - spec/onlinebrief24_spec.rb
135
135
  - spec/spec_helper.rb
136
- homepage: https://github.com/rmoriz
136
+ homepage: https://github.com/rmoriz/onlinebrief24
137
137
  licenses:
138
138
  - MIT
139
139
  post_install_message:
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: 2410213596265831708
151
+ hash: -56571769826084525
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  version: '0'
158
158
  segments:
159
159
  - 0
160
- hash: 2410213596265831708
160
+ hash: -56571769826084525
161
161
  requirements: []
162
162
  rubyforge_project:
163
163
  rubygems_version: 1.8.23