interfax19 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c01aded8273e212cd25982da117f0a9d17d99d37
4
+ data.tar.gz: 97405e9cb13e356e30f22b1c20a96fafad4f299a
5
+ SHA512:
6
+ metadata.gz: dd2e70da83634fa188350e0bbc4bbc294754c2f8861f4607dcda64c218100325aa5b34e6c848bb952c2a98e962e228888128437d40611525f74becdcf8fc6c80
7
+ data.tar.gz: c99e7a8df60ffe01b049e212c8852807135ba07dbf0ab215ff85dd2ca8bd83517c1ca36ed537d978c0561dddd5f570e658420ae8fa0d64ae5511aa8fe8953b4b
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Sascha Brink
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,150 @@
1
+ # Interfax: Now with Ruby 1.9 compatibility
2
+
3
+ This gem is a drop-in replacement for the [Interfax
4
+ gem](http://rubygems.org/gems/interfax), with the exception that this one runs
5
+ on Ruby 1.9.
6
+
7
+ Below is the original Interfax README.
8
+
9
+ ---
10
+
11
+ # Interfax/Ruby
12
+
13
+ This library is a wrapper for the interfax.net fax service. For now,
14
+ you can do the following:
15
+
16
+ * Send HTML/PDF faxes
17
+ * Query the status of a sent fax
18
+ * Retrieve a list of incoming faxes
19
+ * Get the image for a sent fax
20
+
21
+ If you're willing to help, just drop me a line.
22
+
23
+ ## Installation
24
+
25
+ gem install interfax
26
+
27
+ ## Usage
28
+
29
+ ### Outgoing Faxes
30
+
31
+ Create a class, inherit from Interfax::Base and set authentication parameters:
32
+
33
+ class OrderFax < Interfax::Base
34
+ self.username = "my_interfax_username"
35
+ self.password = "my_interfax_password"
36
+ end
37
+
38
+
39
+ #### Sending Faxes
40
+
41
+ Creating a fax is simple regardless of if you're sending PDF or HTML content:
42
+
43
+ Creating an HTML fax:
44
+
45
+ fax = OrderFax.new(:html).contains("<h1>test</h1>").subject("test").to("+4923456123456")
46
+
47
+ Creating a PDF fax:
48
+
49
+ fax = OrderFax.new(:pdf).contains(File.read('/files/document.pdf').subject("test").to("+4923456123456")
50
+
51
+ It is possible to specify more than one receipent:
52
+
53
+ fax = OrderFax.new(:html).contains("<h1>test</h1>").subject("test").to(["+4923456123456","+4943254324312"])
54
+
55
+ To get a summary before sending, just call summary on it which returns a hash:
56
+
57
+ fax.summary
58
+
59
+ Finally:
60
+
61
+ result_id = fax.deliver
62
+
63
+ #### Getting Sent Faxes
64
+
65
+ To get all faxes:
66
+
67
+ faxes = OrderFax.all
68
+
69
+ You can limit the number of received items with an optional parameter:
70
+
71
+ faxes = OrderFax.all(10)
72
+
73
+ To find a specific fax:
74
+
75
+ OrderFax.find(123456789)
76
+
77
+ or get more than one at once:
78
+
79
+ OrderFax.find(123456789,234567890)
80
+
81
+
82
+ ### Incoming Faxes
83
+
84
+
85
+ #### Getting Incoming Faxes
86
+
87
+ To get a list of incoming faxes, you can either use the base class:
88
+
89
+ Interfax::Incoming.username = 'my_interfax_username'
90
+ Interfax::Incoming.password = 'my_interfax_password'
91
+ Interfax::Incoming.limit = 15 # optional, default 100
92
+ Interfax::Incoming.mark_as_read = false # optional, default false
93
+
94
+ # fetch unread incoming faxes
95
+ faxes = Interfax::Incoming.new
96
+
97
+ If you want you can define your own subclass -- useful for keeping
98
+ authentication info handy -- you can do so:
99
+
100
+ class IncomingFaxes < Interfax::Incoming
101
+ self.username = 'my_interfax_username'
102
+ self.password = 'my_interfax_password'
103
+ end
104
+
105
+ # fetch all incoming faxes
106
+ faxes = Interfax::Incoming.all
107
+
108
+ There are four methods for fetching incoming faxes:
109
+
110
+ #all - Fetch all incoming faxes
111
+ #unread - Fetch unread incoming faxes
112
+ #account_all - Fetch incoming faxes for all users on your account
113
+ #account_unread - Fetch unread incoming faxes for all users on your account
114
+
115
+ The account_ methods require that you have admin privileges. For more
116
+ information, see the Interfax API documentation.
117
+
118
+
119
+ #### Getting Incoming Fax Images
120
+
121
+ The Interfax::Incoming methods described above return an array of
122
+ instances of the class you called it on. If you're using the
123
+ Interfax::Incoming class you'll get those. If you use a subclass,
124
+ we'll instantiate that class and return an array of those.
125
+
126
+ In either event, call the `#image` method to fetch the PDF/TIF of the
127
+ fax as a string, suitable for writing to the filesystem in the normal fashion.
128
+
129
+ # Assume you've defined a sublcass as above
130
+ all_faxes = IncomingFaxes.all
131
+ all_faxes[0].image # return the first fax's image
132
+
133
+
134
+ ## Interfax API documentation
135
+
136
+ http://www.interfax.net/en/dev/webservice/reference/methods
137
+
138
+ ## Note on Patches/Pull Requests
139
+
140
+ * Fork the project.
141
+ * Make your feature addition or bug fix.
142
+ * Add tests for it. This is important so I don't break it in a
143
+ future version unintentionally.
144
+ * Commit, do not mess with rakefile, version, or history.
145
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
146
+ * Send me a pull request. Bonus points for topic branches.
147
+
148
+ ## Copyright
149
+
150
+ Copyright (c) 2010 Sascha Brink. See LICENSE for details.
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "interfax"
8
+ gem.summary = %Q{A ruby wrapper for the interfax webservice (SOAP)}
9
+ gem.description = %Q{A ruby wrapper for the interfax webservice (SOAP)}
10
+ gem.email = "sascha.brink@gmail.com"
11
+ gem.homepage = "http://github.com/sbrink/interfax"
12
+ gem.authors = ["Sascha Brink"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.files = FileList["[A-Z]*", "{lib,spec}/**/*"] - FileList["**/*.log"]
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ #require 'spec/rake/spectask'
23
+ #Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ # spec.libs << 'lib' << 'spec'
25
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ #end
27
+
28
+ #Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ # spec.libs << 'lib' << 'spec'
30
+ # spec.pattern = 'spec/**/*_spec.rb'
31
+ # spec.rcov = true
32
+ #end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "interfax #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.3
@@ -0,0 +1,9 @@
1
+ require 'time'
2
+ require "soap/wsdlDriver"
3
+
4
+ $:.unshift(File.dirname(__FILE__)) unless
5
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ require 'interfax/fax_item'
8
+ require 'interfax/base'
9
+ require 'interfax/incoming'
@@ -0,0 +1,151 @@
1
+
2
+ module Interfax
3
+
4
+ class Base
5
+
6
+ # Class methods
7
+
8
+ class << self
9
+ attr_accessor :username, :password
10
+ attr_accessor :orientation, :page_size, :high_res, :fine_rendering
11
+
12
+ def query(verb,verbdata,limit=-1)
13
+ result = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver.FaxQuery(
14
+ :Username => self.username,
15
+ :Password => self.password,
16
+ :Verb => verb,
17
+ :VerbData => verbdata,
18
+ :MaxItems => limit,
19
+ :ResultCode => 0
20
+ )
21
+ return [] if result.nil? || !defined?(result.faxQueryResult)
22
+ [*result.faxQueryResult.faxItemEx].map do |f|
23
+ FaxItem.new(
24
+ f.transactionID,
25
+ Time.parse(f.submitTime),
26
+ Time.parse(f.postponeTime),
27
+ f.destinationFax,
28
+ f.duration,
29
+ f.remoteCSID,
30
+ f.pagesSent,
31
+ f.status,
32
+ f.subject,
33
+ f.pagesSubmitted)
34
+ end
35
+ end
36
+
37
+ def find(*args)
38
+ query("IN", args.join(','))
39
+ end
40
+
41
+ def last(limit=1)
42
+ query("LE","999999999",limit)
43
+ end
44
+
45
+ def all()
46
+ query("LE","999999999")
47
+ end
48
+
49
+ end
50
+
51
+ # Instance methods
52
+
53
+ def initialize(type="HTML",content=nil)
54
+ @username = self.class.username
55
+ @password = self.class.password
56
+ @type = type.to_s.upcase
57
+ @content = content
58
+ @at = Time.now
59
+ @recipients = nil
60
+ @subject = "Change me"
61
+ @retries = "0"
62
+
63
+ @orientation = self.class.orientation || 'Portrait'
64
+ @high_res = self.class.high_res || 'false'
65
+ @fine_rendering = self.class.fine_rendering || 'true'
66
+ @page_size = self.class.page_size || 'Letter'
67
+ end
68
+
69
+ def contains(content)
70
+ @content = content
71
+ self
72
+ end
73
+
74
+ def to(recipients)
75
+ @recipients = [*recipients].join(";")
76
+ self
77
+ end
78
+
79
+ def subject(subject)
80
+ @subject = subject
81
+ self
82
+ end
83
+
84
+ def retries(count)
85
+ @retries = count.to_s
86
+ self
87
+ end
88
+
89
+ def at(time)
90
+ @at = time
91
+ self
92
+ end
93
+
94
+ def fine_rendering(boolstring)
95
+ @fine_rendering = boolstring
96
+ self
97
+ end
98
+
99
+ def orientation(orientation)
100
+ @orientation = orientation
101
+ self
102
+ end
103
+
104
+ def high_res(boolstring)
105
+ @high_res = boolstring
106
+ self
107
+ end
108
+
109
+ def page_size(size)
110
+ @page_size = size
111
+ self
112
+ end
113
+
114
+
115
+ def summary
116
+ {
117
+ :fax_numbers => @recipients,
118
+ :content => @content,
119
+ :at => @at,
120
+ :retries => @retries,
121
+ :subject => @subject,
122
+ :username => @username,
123
+ :orientation => @orientation,
124
+ :page_size => @page_size
125
+ }
126
+ end
127
+
128
+ def deliver
129
+ driver = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver
130
+
131
+ result = driver.SendfaxEx_2(
132
+ :Username => @username,
133
+ :Password => @password,
134
+ :FileTypes => @type,
135
+ :Postpone => @at,
136
+ :RetriesToPerform => @retries,
137
+ :FaxNumbers=> @recipients,
138
+ :FileSizes => @content.bytesize,
139
+ :FilesData => @content,
140
+ :Subject => @subject,
141
+ :PageSize => @page_size,
142
+ :PageOrientation => @orientation,
143
+ :IsHighResolution => @high_res,
144
+ :IsFineRendering => @fine_rendering
145
+ )
146
+ result ? result.sendfaxEx_2Result : nil
147
+ end
148
+
149
+ end
150
+
151
+ end
@@ -0,0 +1,13 @@
1
+ module Interfax
2
+
3
+ class FaxItem < Struct.new(:id, :submit_time, :postpone_time, :receiver_number, :duration, :remote_csid, :sent_pages, :status, :subject, :submitted_pages)
4
+ def pages
5
+ "#{sent_pages}/#{submitted_pages}"
6
+ end
7
+
8
+ def ok
9
+ (status.to_i >= 0) ? true : false
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,223 @@
1
+ require 'soap/wsdlDriver'
2
+ require 'base64'
3
+
4
+ module Interfax
5
+
6
+ # = Interfax::Incoming
7
+ #
8
+ # Allows interaction with the Interfax Inbound API, documented at:
9
+ # http://www.interfax.net/en/dev/webservice/reference_in
10
+ #
11
+ # == Retrieving incoming faxes
12
+ #
13
+ # Set the +username+ and +password+ variables appropriately, and
14
+ # then call one of the query methods, which are described in further
15
+ # detail below.
16
+ #
17
+ # Interfax::Incoming.username = 'my_interfax_username'
18
+ # Interfax::Incoming.password = 'my_interfax_password'
19
+ # faxes = Interfax::Incoming.unread
20
+ #
21
+ # You can extend Interfax::Incoming, and the query methdos will
22
+ # return instances of your subclass. This is useful for extending
23
+ # functionality, or consolidating your configuration in one place.
24
+ #
25
+ # class InboundFax < Interfax::Incoming
26
+ # self.username = 'my_interfax_username'
27
+ # self.password = 'my_interfax_password'
28
+ #
29
+ # def write_image_to_file
30
+ # File.open("/path/to/file", 'w') { |f| f.write(image)
31
+ # end
32
+ # end
33
+ #
34
+ # faxes = InboundFax.all # this is an array of InboundFax objects
35
+ # faxes.map(&:write_image_to_file)
36
+ #
37
+ # == Methods
38
+ #
39
+ # The methods available for fetching or querying inbound faxes are:
40
+ #
41
+ # * +#all+ - Retrieves all inbound faxes, up to +limit+.
42
+ # * +#unread+ - Retrieves any unread faxes, up to +limit+.
43
+ # * +#account_all+ - Retrieves inbound faxes for all users on your
44
+ # account, up to +limit+. Requires an administrator account.
45
+ # * +#account_unread+ - Same as above, but fetches only unread
46
+ # faxes. Also requires an administrator account.
47
+ #
48
+ # As seen above, these methods return instances of the class they're
49
+ # called on, which makes it easy to extend your objects for custom
50
+ # functionality.
51
+ #
52
+ # == Configuration
53
+ #
54
+ # We require that the following two configuration variables be set
55
+ # at the class level, as seen in the examples above.
56
+ #
57
+ # * +username+ - [required] Your interfax username.
58
+ # * +password+ - [requierd] Your interfax password.
59
+ #
60
+ # We also support a few other configuration methods, which are
61
+ # explained further in Interfax's API documentation.
62
+ #
63
+ # * +limit+ - [1..100, default 100] The maximum number of faxes to return.
64
+ # * +mark_as_read+ - [boolean, default false] Whether or not to mark
65
+ # retrieved faxes as sent.
66
+ #
67
+ # These options are also accepted as options when requesting faxes:
68
+ #
69
+ # # Assume username/password already set
70
+ # Interfax::Incoming.all(:limit => 10, :mark_as_read => true)
71
+ #
72
+ # Options supplied this way will temporarily override any options
73
+ # set on the class.
74
+
75
+ class Incoming
76
+
77
+ class << self
78
+ attr_accessor :username, :password, :mark_as_read, :limit #:nodoc:
79
+
80
+ def soap_client #:nodoc:
81
+ SOAP::WSDLDriverFactory.
82
+ new("https://ws.interfax.net/inbound.asmx?WSDL").
83
+ create_rpc_driver
84
+ end
85
+
86
+ def query(type, opts = {}) #:nodoc:
87
+ result = self.soap_client.GetList(:Username => self.username,
88
+ :Password => self.password,
89
+ :MaxItems => opts[:limit] || self.limit || 100,
90
+ :MarkAsRead => opts[:mark_as_read] || self.mark_as_read || false,
91
+ :LType => type
92
+ )
93
+
94
+ return [] if result.nil? || !defined?(result.objMessageItem)
95
+ [*result.objMessageItem.messageItem].map do |fax|
96
+ self.new(fax)
97
+ end
98
+ end
99
+
100
+ # Returns all inbound messages for your user up to the +limit+
101
+ # option. Optionally marks the faxes as read.
102
+ #
103
+ # ==== Options (as hash)
104
+ #
105
+ # Both of these will default to whatever values you've set for
106
+ # the class, or 100 (limit) or false (mark_as_read) if you haven't.
107
+ # * +:limit+ - Maximum number of faxes to return.
108
+ # * +:mark_as_read+: Mark fetched faxes as read.
109
+
110
+ def all(opts = {})
111
+ query('AllMessages', opts)
112
+ end
113
+
114
+ # Returns any unread messages for your user up to the +limit+
115
+ # option. Optionally marks the faxes as read.
116
+ #
117
+ # ==== Options (as hash)
118
+ #
119
+ # Both of these will default to whatever values you've set for
120
+ # the class, or 100 (limit) or false (mark_as_read) if you haven't.
121
+ # * +:limit+ - Maximum number of faxes to return.
122
+ # * +:mark_as_read+: Mark fetched faxes as read.
123
+
124
+ def unread(opts = {})
125
+ query('NewMessages', opts)
126
+ end
127
+
128
+ # Returns all messages for all users on your account, up
129
+ # to the +limit+ option. Optionally marks the faxes as
130
+ # read. Requires your user be an administrator for your account.
131
+ #
132
+ # ==== Options (as hash)
133
+ #
134
+ # Both of these will default to whatever values you've set for
135
+ # the class, or 100 (limit) or false (mark_as_read) if you haven't.
136
+ # * +:limit+ - Maximum number of faxes to return.
137
+ # * +:mark_as_read+: Mark fetched faxes as read.
138
+
139
+ def account_all(opts = {})
140
+ query('AccountAllMessages', opts)
141
+ end
142
+
143
+ # Returns any unread messages for all users on your account, up
144
+ # to the +limit+ option. Optionally marks the faxes as
145
+ # read. Requires your user be an administrator for your account.
146
+ #
147
+ # ==== Options (as hash)
148
+ #
149
+ # Both of these will default to whatever values you've set for
150
+ # the class, or 100 (limit) or false (mark_as_read) if you haven't.
151
+ # * +:limit+ - Maximum number of faxes to return.
152
+ # * +:mark_as_read+: Mark fetched faxes as read.
153
+
154
+ def account_unread(opts = {})
155
+ query('AccountNewMessages', opts)
156
+ end
157
+
158
+ end
159
+
160
+ # class methods
161
+
162
+ attr_accessor :username, :password, :mark_as_read, :chunk_size, :message_id, :message_size, :image,
163
+ :interfax_number, :remote_csid, :message_status, :pages, :message_type, :receive_time, :caller_id,
164
+ :duration
165
+
166
+ # Normally this is instantied for you as a result of calling one of the
167
+ # querying class methods. If you want to instantiate an object yourself,
168
+ # you can pass it the results of the GetList API call, or any object that
169
+ # looks like it.
170
+ # See: http://www.interfax.net/en/dev/webservice/reference/getlist
171
+ def initialize(params = nil)
172
+ @username = self.class.username
173
+ @password = self.class.password
174
+ @mark_as_read = self.class.mark_as_read || false
175
+ @chunk_size = 100000
176
+
177
+ unless params.nil?
178
+ @message_id = params.messageID
179
+ @message_size = params.messageSize.to_i
180
+ @interfax_number = params.phoneNumber
181
+ @remote_csid = params.remoteCSID
182
+ @message_status = params.messageStatus
183
+ @pages = params.pages
184
+ @message_type = params.messageType
185
+ @receive_time = params.receiveTime
186
+ @caller_id = params.callerID
187
+ @duration = params.messageRecordingDuration
188
+ end
189
+
190
+ @image = nil
191
+ end
192
+
193
+ # Retrieves the image from the Interfax Inbound API, as a
194
+ # string. Suitable for writing to a file or streaming to a client.
195
+ def image
196
+ @image || fetch_image
197
+ end
198
+
199
+ def fetch_image #:nodoc:
200
+ @image = ""
201
+ downloaded_size = 0
202
+ while downloaded_size < @message_size
203
+ result = self.class.soap_client.GetImageChunk(:Username => @username,
204
+ :Password => @password,
205
+ :MessageID => @message_id,
206
+ :MarkAsRead => @mark_as_read,
207
+ :ChunkSize => @chunk_size,
208
+ :From => downloaded_size)
209
+
210
+ # TODO: Make this throw a nicer exception on failure
211
+ if defined?(result.image)
212
+ @image << Base64.decode64(result.image)
213
+ end
214
+ downloaded_size += @chunk_size
215
+
216
+ end
217
+
218
+ @image
219
+ end
220
+
221
+ end
222
+
223
+ end
@@ -0,0 +1,23 @@
1
+ module IncomingHelper
2
+
3
+ INTERFAX_RESPONSE = {:messageID => '2011',
4
+ :phoneNumber => '6145551212',
5
+ :remoteCSID => '923459129349',
6
+ :messageStatus => "0",
7
+ :pages => '1',
8
+ :messageSize => '58800',
9
+ :messageType => "1",
10
+ :receiveTime => "2011-01-01T09:08:11",
11
+ :callerID => '8005556666',
12
+ :messageRecordingDuration => "60"}
13
+
14
+
15
+
16
+ class MockInterfaxResponse < Struct.new(:objMessageItem); end
17
+ class ObjMessageItem < Struct.new(:messageItem); end
18
+ class MessageItem < Struct.new(*INTERFAX_RESPONSE.keys); end
19
+
20
+ def mock_getlist_response(count = 1)
21
+ MockInterfaxResponse.new(ObjMessageItem.new([MessageItem.new(*INTERFAX_RESPONSE.values)]* count))
22
+ end
23
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+ include IncomingHelper
3
+
4
+ describe Interfax::Incoming do
5
+
6
+ before(:each) do
7
+ @client_mock = mock("SoapClient",
8
+ :GetList => true,
9
+ :GetImageChunk => true)
10
+
11
+ Interfax::Incoming.stub!(:soap_client).and_return(@client_mock)
12
+ end
13
+
14
+ context "querying for incoming faxes" do
15
+
16
+ it "should query for all messages" do
17
+ Interfax::Incoming.should_receive(:query).with('AllMessages', anything())
18
+ Interfax::Incoming.all
19
+ end
20
+
21
+ it "should query for unread messages" do
22
+ Interfax::Incoming.should_receive(:query).with('NewMessages', anything())
23
+ Interfax::Incoming.unread
24
+ end
25
+
26
+ it "should query for all users' unread messages" do
27
+ Interfax::Incoming.should_receive(:query).with('AccountNewMessages', anything())
28
+ Interfax::Incoming.account_unread
29
+ end
30
+
31
+ it "should query for all users' messages" do
32
+ Interfax::Incoming.should_receive(:query).with('AccountAllMessages', anything())
33
+ Interfax::Incoming.account_all
34
+ end
35
+
36
+ it "should respect the :limit argument over a class-defined limit" do
37
+ @client_mock.should_receive(:GetList).with(hash_including(:MaxItems => 24))
38
+ Interfax::Incoming.limit = 50
39
+ Interfax::Incoming.all(:limit => 24)
40
+ end
41
+
42
+ it "should use the class-specified limit over the default" do
43
+ @client_mock.should_receive(:GetList).with(hash_including(:MaxItems => 50))
44
+ Interfax::Incoming.limit = 50
45
+ Interfax::Incoming.all
46
+ end
47
+
48
+ it "should respect the :mark_as_read argument over the class-defined value" do
49
+ @client_mock.should_receive(:GetList).with(hash_including(:MarkAsRead => true))
50
+ Interfax::Incoming.mark_as_read = false
51
+ Interfax::Incoming.all(:mark_as_read => true)
52
+ end
53
+
54
+ it "should use the class-specified mark_as_read over the default" do
55
+ @client_mock.should_receive(:GetList).with(hash_including(:MarkAsRead => true))
56
+ Interfax::Incoming.mark_as_read = true
57
+ Interfax::Incoming.all
58
+ end
59
+
60
+
61
+ it "should return instances of the base class when called on the base class" do
62
+ @client_mock.stub!(:GetList).and_return(mock_getlist_response)
63
+ Interfax::Incoming.all[0].class.should == Interfax::Incoming
64
+ end
65
+
66
+ it "should return instances of the subclass when called on a subclass" do
67
+ class TestFax < Interfax::Incoming; end
68
+
69
+ @client_mock.
70
+ stub!(:GetList).
71
+ and_return(mock_getlist_response)
72
+ TestFax.stub!(:soap_client).and_return(@client_mock)
73
+
74
+ TestFax.all[0].class.should == TestFax
75
+ end
76
+
77
+ end
78
+
79
+ context "fetching images" do
80
+
81
+ before(:each) do
82
+ details = mock_getlist_response.objMessageItem.messageItem[0]
83
+ @fax = Interfax::Incoming.new(details)
84
+ end
85
+
86
+ it "should fetch the image when asked" do
87
+ @client_mock.should_receive(:GetImageChunk).at_least(:once)
88
+ @fax.image
89
+ end
90
+
91
+ it "should cache the image once received" do
92
+ @client_mock.should_receive(:GetImageChunk).at_least(:once)
93
+ @fax.image
94
+ @client_mock.should_not_receive(:GetImageChunk)
95
+ @fax.image
96
+ end
97
+
98
+ it "should respect the class-defined mark_as_read option" do
99
+ Interfax::Incoming.mark_as_read = true
100
+ @client_mock.should_receive(:GetImageChunk).with(hash_including(:MarkAsRead => true))
101
+ @fax.image
102
+ end
103
+
104
+
105
+ end
106
+
107
+ end
108
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Interfax" do
4
+ it "fails" do
5
+ pending "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'interfax'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'incoming_helper'
7
+
8
+ Spec::Runner.configure do |config|
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interfax19
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Jon Canady
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mumboe-soap4r
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.9
41
+ description: A ruby wrapper for the interfax webservice (SOAP). Just like the Interfax
42
+ gem, except this one is 1.9-compatible.
43
+ email: jcanady@innova-partners.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files:
47
+ - LICENSE
48
+ - README.markdown
49
+ files:
50
+ - LICENSE
51
+ - README.markdown
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/interfax.rb
55
+ - lib/interfax/base.rb
56
+ - lib/interfax/fax_item.rb
57
+ - lib/interfax/incoming.rb
58
+ - spec/incoming_helper.rb
59
+ - spec/incoming_spec.rb
60
+ - spec/interfax_spec.rb
61
+ - spec/spec.opts
62
+ - spec/spec_helper.rb
63
+ homepage: http://github.com/innovapartners/interfax
64
+ licenses: []
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.2
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A ruby wrapper for the interfax webservice (SOAP)
86
+ test_files: []