interfax-ruby 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,208 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Interfax" do
4
+ let(:session_id) { "D32EFA4297184BDF92A8393CB891F137B758A945F1D54E48869046799928C965" }
5
+ let(:file_name) { File.join('spec','fixtures','mickey01.jpg') }
6
+ before(:each) do
7
+ ENV['INTERFAX_USERNAME'] = 'defaultusername'
8
+ ENV['INTERFAX_PASSWORD'] = 'defaultpassword'
9
+ end
10
+ let(:interfax) { Interfax.new }
11
+ context "username and password is not passed" do
12
+ let(:interfax) { Interfax.new }
13
+ it "should store username and password from environment variables" do
14
+ interfax.instance_variable_get(:@username).should == 'defaultusername'
15
+ interfax.instance_variable_get(:@password).should == 'defaultpassword'
16
+ end
17
+ end
18
+ context "username and password is passed" do
19
+ let(:interfax) { Interfax.new(:username => 'myusername', :password => 'mypassword') }
20
+ it "should store username and password from values passed" do
21
+ interfax.instance_variable_get(:@username).should == 'myusername'
22
+ interfax.instance_variable_get(:@password).should == 'mypassword'
23
+ end
24
+ end
25
+ it "should have WSDL_URL" do
26
+ Interfax::WSDL_URL.should == "https://ws.interfax.net/dfs.asmx?WSDL"
27
+ end
28
+ describe "#client" do
29
+ it "should return savon client" do
30
+ interfax.client.should be_kind_of(Savon::Client)
31
+ end
32
+ it "should have correct document" do
33
+ interfax.client.wsdl.document.should == "https://ws.interfax.net/dfs.asmx?WSDL"
34
+ end
35
+ end
36
+ describe "#start_file_upload" do
37
+ context "authorized" do
38
+ let(:interfax) { Interfax.new(:username => 'rafael_lima', :password => ENV['INTERFAX_PASSWORD_FOR_RSPEC']) }
39
+ it "should assign last_session_id" do
40
+ VCR.use_cassette('start_file_upload_authorized') do
41
+ interfax.start_file_upload
42
+ interfax.instance_variable_get(:@last_session_id).should == session_id
43
+ end
44
+ end
45
+ it "should return session id" do
46
+ VCR.use_cassette('start_file_upload_authorized') do
47
+ interfax.start_file_upload.should == session_id
48
+ end
49
+ end
50
+ it "should not cache session id" do
51
+ interfax.client.should_receive(:request).twice.and_return(mock("Response", :success? => true, :to_hash => {:start_file_upload_response => {:start_file_upload_result => "1", :session_id => "2FE69E6C86DB4CB4926A94E63B68039AD83BCBB7F10C407F9641FEAEF5EA38EE"}}))
52
+ VCR.use_cassette('start_file_upload_authorized') do
53
+ 2.times { interfax.start_file_upload }
54
+ end
55
+ end
56
+ end
57
+ context "unauthorized" do
58
+ it "should return false" do
59
+ VCR.use_cassette('start_file_upload_unauthorized') do
60
+ interfax.start_file_upload.should be_nil
61
+ end
62
+ end
63
+ it "should not assign last_session_id" do
64
+ VCR.use_cassette('start_file_upload_unauthorized') do
65
+ interfax.start_file_upload
66
+ interfax.instance_variable_get(:@last_session_id).should be_nil
67
+ end
68
+ end
69
+ end
70
+ end
71
+ describe "#upload_file_chunk" do
72
+ context "start_file_upload was not called" do
73
+ context "session id is not passed" do
74
+ it "should call start_file_upload" do
75
+ interfax.should_receive(:start_file_upload)
76
+ interfax.stub(:request)
77
+ interfax.upload_file_chunk(file_name)
78
+ end
79
+ end
80
+ context "session id is passed" do
81
+ it "should not call start_file_upload" do
82
+ interfax.should_not_receive(:start_file_upload)
83
+ interfax.stub(:request)
84
+ interfax.upload_file_chunk(file_name, :session_id => session_id)
85
+ end
86
+ it "should call request with correct params" do
87
+ interfax.should_receive(:request).with(:upload_file_chunk, {
88
+ :chunk => anything(),
89
+ :SessionID => session_id,
90
+ :IsLast => 1
91
+ })
92
+ interfax.upload_file_chunk(file_name, :session_id => session_id)
93
+ end
94
+
95
+ end
96
+ end
97
+ context "start_file_upload was called before" do
98
+ before(:each) do
99
+ VCR.use_cassette('start_file_upload_authorized') do
100
+ interfax.start_file_upload
101
+ end
102
+ end
103
+ it "should not call start_file_upload" do
104
+ interfax.should_not_receive(:start_file_upload)
105
+ interfax.stub(:request)
106
+ interfax.upload_file_chunk(file_name)
107
+ end
108
+ context "authorized" do
109
+ let(:interfax) { Interfax.new(:username => 'rafael_lima', :password => ENV['INTERFAX_PASSWORD_FOR_RSPEC']) }
110
+ it "should return true" do
111
+ VCR.use_cassette('upload_file_chunk_authorized') do
112
+ interfax.upload_file_chunk(file_name, :chunk_size => 40960).should be_true
113
+ end
114
+ end
115
+ it "should request twice" do
116
+ interfax.client.should_receive(:request).twice.and_return(mock("Response", :success? => true, :to_hash => {:upload_file_chunk_response => {:upload_file_chunk_result => "68702"}}))
117
+ interfax.upload_file_chunk(file_name, :chunk_size => 40960).should be_true
118
+ end
119
+ end
120
+ end
121
+ end
122
+ describe "#cancel_file_upload" do
123
+ context "start_file_upload was not successfully called" do
124
+ context "session id is not passed" do
125
+ it "should return nil" do
126
+ interfax.cancel_file_upload.should be_nil
127
+ end
128
+ end
129
+ context "session id is passed" do
130
+ it "should return true" do
131
+ VCR.use_cassette('cancel_file_upload_with_session') do
132
+ interfax.cancel_file_upload(:session_id => session_id).should == 0
133
+ end
134
+ end
135
+ end
136
+ end
137
+ context "start_file_upload was successfully called" do
138
+ before(:each) do
139
+ VCR.use_cassette('start_file_upload_authorized') do
140
+ interfax.start_file_upload
141
+ end
142
+ end
143
+ it "should return true" do
144
+ VCR.use_cassette('cancel_file_upload') do
145
+ interfax.cancel_file_upload.should == 0
146
+ end
147
+ end
148
+ end
149
+ end
150
+ describe "#sendfax_ex_2" do
151
+ context "authorized" do
152
+ let(:interfax) { Interfax.new(:username => 'rafael_lima', :password => ENV['INTERFAX_PASSWORD_FOR_RSPEC']) }
153
+ context "with file uploaded" do
154
+ before(:each) do
155
+ VCR.use_cassette('start_file_upload_authorized') do
156
+ interfax.start_file_upload
157
+ end
158
+ VCR.use_cassette('upload_file_chunk_authorized') do
159
+ interfax.upload_file_chunk(file_name, :chunk_size => 40960).should be_true
160
+ end
161
+ end
162
+ it "should set default values" do
163
+ interfax.should_receive(:request).with(:sendfax_ex_2, {
164
+ :file_types => 'JPG',
165
+ :file_sizes => "68702/sessionID=#{session_id}",
166
+ :retries_to_perform => 1,
167
+ :page_size => 'A4',
168
+ :page_orientation => 'Portrait',
169
+ :is_high_resolution => 0,
170
+ :is_fine_rendering => 1,
171
+ })
172
+ interfax.sendfax_ex_2
173
+ end
174
+ end
175
+ context "without file uploaded" do
176
+ it "should set default values" do
177
+ interfax.should_receive(:request).with(:sendfax_ex_2, {
178
+ :retries_to_perform => 1,
179
+ :page_size => 'A4',
180
+ :page_orientation => 'Portrait',
181
+ :is_high_resolution => 0,
182
+ :is_fine_rendering => 1,
183
+ })
184
+ interfax.sendfax_ex_2
185
+ end
186
+ end
187
+ context "with default values" do
188
+ it "should return error code" do
189
+ VCR.use_cassette('sendfax_ex_2_authorized_default_values') do
190
+ interfax.sendfax_ex_2.should == -1007
191
+ end
192
+ end
193
+ end
194
+ context "with required values" do
195
+ it "should return error code" do
196
+ VCR.use_cassette('sendfax_ex_2_authorized_required_values') do
197
+ interfax.sendfax_ex_2({
198
+ :fax_numbers => '+55-21-35531898',
199
+ :files_data => Base64.encode64(File.read(file_name)),
200
+ :file_types => 'JPG',
201
+ :file_sizes => File.size(file_name),
202
+ }).should == 257489542
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'interfax'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ Savon.configure do |config|
2
+ config.log = false # disable logging
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'vcr'
2
+
3
+ VCR.config do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.stub_with :fakeweb
6
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interfax-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rafael Lima
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: savon
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.9
30
+ - !ruby/object:Gem::Dependency
31
+ name: ruby-debug19
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.11.6
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.11.6
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.8.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.8.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: '3.12'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: '3.12'
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.0.22
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.22
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.3
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.3
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.5.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - '='
124
+ - !ruby/object:Gem::Version
125
+ version: 0.5.3
126
+ - !ruby/object:Gem::Dependency
127
+ name: fakeweb
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - '='
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - '='
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: vcr
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - '='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.11.3
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - '='
156
+ - !ruby/object:Gem::Version
157
+ version: 1.11.3
158
+ description: Ruby wrapper based on savon for Interfax SOAP API
159
+ email: contato@rafael.adm.br
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files:
163
+ - LICENSE.txt
164
+ - README.md
165
+ files:
166
+ - .document
167
+ - .rspec
168
+ - .rvmrc
169
+ - Gemfile
170
+ - Gemfile.lock
171
+ - LICENSE.txt
172
+ - README.md
173
+ - Rakefile
174
+ - VERSION
175
+ - interfax-ruby.gemspec
176
+ - lib/interfax.rb
177
+ - spec/fixtures/mickey01.jpg
178
+ - spec/fixtures/vcr_cassettes/cancel_file_upload.yml
179
+ - spec/fixtures/vcr_cassettes/cancel_file_upload_with_session.yml
180
+ - spec/fixtures/vcr_cassettes/sendfax_ex_2_authorized_default_values.yml
181
+ - spec/fixtures/vcr_cassettes/sendfax_ex_2_authorized_required_values.yml
182
+ - spec/fixtures/vcr_cassettes/start_file_upload_authorized.yml
183
+ - spec/fixtures/vcr_cassettes/start_file_upload_unauthorized.yml
184
+ - spec/fixtures/vcr_cassettes/upload_file_chunk_authorized.yml
185
+ - spec/interfax_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/support/savon.rb
188
+ - spec/support/vcr.rb
189
+ homepage: http://github.com/rafaelp/interfax-ruby
190
+ licenses:
191
+ - MIT
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: -1231871281370402405
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ none: false
207
+ requirements:
208
+ - - ! '>='
209
+ - !ruby/object:Gem::Version
210
+ version: '0'
211
+ requirements: []
212
+ rubyforge_project:
213
+ rubygems_version: 1.8.24
214
+ signing_key:
215
+ specification_version: 3
216
+ summary: Ruby wrapper based on savon for Interfax SOAP API
217
+ test_files: []