interfax 0.2.1 → 1.0.0.beta.1

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.markdown DELETED
@@ -1,134 +0,0 @@
1
- # Interfax/Ruby
2
-
3
- This library is a wrapper for the interfax.net fax service. For now,
4
- you can do the following:
5
-
6
- * Send HTML faxes
7
- * Query the status of a sent fax
8
- * Retrieve a list of incoming faxes
9
- * Get the image for a sent fax
10
-
11
- If you're willing to help, just drop me a line.
12
-
13
- ## Installation
14
-
15
- gem install interfax
16
-
17
- ## Usage
18
-
19
- ### Outgoing Faxes
20
-
21
- Create a class, inherit from Interfax::Base and set authentication parameters:
22
-
23
- class OrderFax < Interfax::Base
24
- self.username = "my_interfax_username"
25
- self.password = "my_interfax_password"
26
- end
27
-
28
-
29
- #### Sending Faxes
30
-
31
- Creating a fax:
32
-
33
- fax = OrderFax.new(:html).contains("<h1>test</h1>").subject("test").to("+4923456123456")
34
-
35
- It is possible to specify more than one receipent:
36
-
37
- fax = OrderFax.new(:html).contains("<h1>test</h1>").subject("test").to(["+4923456123456","+4943254324312"])
38
-
39
- To get a summary before sending, just call summary on it which returns a hash:
40
-
41
- fax.summary
42
-
43
- Finally:
44
-
45
- result_id = fax.deliver
46
-
47
- #### Getting Sent Faxes
48
-
49
- To get all faxes:
50
-
51
- faxes = OrderFax.all
52
-
53
- You can limit the number of received items with an optional parameter:
54
-
55
- faxes = OrderFax.all(10)
56
-
57
- To find a specific fax:
58
-
59
- OrderFax.find(123456789)
60
-
61
- or get more than one at once:
62
-
63
- OrderFax.find(123456789,234567890)
64
-
65
-
66
- ### Incoming Faxes
67
-
68
-
69
- #### Getting Incoming Faxes
70
-
71
- To get a list of incoming faxes, you can either use the base class:
72
-
73
- Interfax::Incoming.username = 'my_interfax_username'
74
- Interfax::Incoming.password = 'my_interfax_password'
75
- Interfax::Incoming.limit = 15 # optional, default 100
76
- Interfax::Incoming.mark_as_read = false # optional, default false
77
-
78
- # fetch unread incoming faxes
79
- faxes = Interfax::Incoming.new
80
-
81
- If you want you can define your own subclass -- useful for keeping
82
- authentication info handy -- you can do so:
83
-
84
- class IncomingFaxes < Interfax::Incoming
85
- self.username = 'my_interfax_username'
86
- self.password = 'my_interfax_password'
87
- end
88
-
89
- # fetch all incoming faxes
90
- faxes = Interfax::Incoming.all
91
-
92
- There are four methods for fetching incoming faxes:
93
-
94
- #all - Fetch all incoming faxes
95
- #unread - Fetch unread incoming faxes
96
- #account_all - Fetch incoming faxes for all users on your account
97
- #account_unread - Fetch unread incoming faxes for all users on your account
98
-
99
- The account_ methods require that you have admin privileges. For more
100
- information, see the Interfax API documentation.
101
-
102
-
103
- #### Getting Incoming Fax Images
104
-
105
- The Interfax::Incoming methods described above return an array of
106
- instances of the class you called it on. If you're using the
107
- Interfax::Incoming class you'll get those. If you use a subclass,
108
- we'll instantiate that class and return an array of those.
109
-
110
- In either event, call the `#image` method to fetch the PDF/TIF of the
111
- fax as a string, suitable for writing to the filesystem in the normal fashion.
112
-
113
- # Assume you've defined a sublcass as above
114
- all_faxes = IncomingFaxes.all
115
- all_faxes[0].image # return the first fax's image
116
-
117
-
118
- ## Interfax API documentation
119
-
120
- http://www.interfax.net/en/dev/webservice/reference/methods
121
-
122
- ## Note on Patches/Pull Requests
123
-
124
- * Fork the project.
125
- * Make your feature addition or bug fix.
126
- * Add tests for it. This is important so I don't break it in a
127
- future version unintentionally.
128
- * Commit, do not mess with rakefile, version, or history.
129
- (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)
130
- * Send me a pull request. Bonus points for topic branches.
131
-
132
- ## Copyright
133
-
134
- Copyright (c) 2010 Sascha Brink. See LICENSE for details.
data/Rakefile DELETED
@@ -1,46 +0,0 @@
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 DELETED
@@ -1 +0,0 @@
1
- 0.2.1
data/lib/interfax/base.rb DELETED
@@ -1,120 +0,0 @@
1
-
2
- module Interfax
3
-
4
- class Base
5
-
6
- # Class methods
7
-
8
- class << self
9
- attr_accessor :username, :password
10
-
11
- def query(verb,verbdata,limit=-1)
12
- result = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver.FaxQuery(
13
- :Username => self.username,
14
- :Password => self.password,
15
- :Verb => verb,
16
- :VerbData => verbdata,
17
- :MaxItems => limit,
18
- :ResultCode => 0
19
- )
20
- return [] if result.nil? || !defined?(result.faxQueryResult)
21
- [*result.faxQueryResult.faxItemEx].map do |f|
22
- FaxItem.new(
23
- f.transactionID,
24
- Time.parse(f.submitTime),
25
- Time.parse(f.postponeTime),
26
- f.destinationFax,
27
- f.duration,
28
- f.remoteCSID,
29
- f.pagesSent,
30
- f.status,
31
- f.subject,
32
- f.pagesSubmitted)
33
- end
34
- end
35
-
36
- def find(*args)
37
- query("IN", args.join(','))
38
- end
39
-
40
- def last(limit=1)
41
- query("LE","999999999",limit)
42
- end
43
-
44
- def all()
45
- query("LE","999999999")
46
- end
47
-
48
- end
49
-
50
- # Instance methods
51
-
52
- def initialize(type="HTML",content=nil)
53
- @username = self.class.username
54
- @password = self.class.password
55
- @type = type.to_s.upcase
56
- @content = content
57
- @at = Time.now
58
- @recipients = nil
59
- @subject = "Change me"
60
- @retries = "0"
61
- end
62
-
63
- def contains(content)
64
- @content = content
65
- self
66
- end
67
-
68
- def to(recipients)
69
- @recipients = [*recipients].join(";")
70
- self
71
- end
72
-
73
- def subject(subject)
74
- @subject = subject
75
- self
76
- end
77
-
78
- def retries(count)
79
- @retries = count.to_s
80
- self
81
- end
82
-
83
- def at(time)
84
- @at = time
85
- self
86
- end
87
-
88
- def summary
89
- {
90
- :fax_numbers => @recipients,
91
- :content => @content,
92
- :at => @at,
93
- :retries => @retries,
94
- :subject => @subject,
95
- :username => @username
96
- }
97
- end
98
-
99
- def deliver
100
- result = SOAP::WSDLDriverFactory.new("https://ws.interfax.net/dfs.asmx?WSDL").create_rpc_driver.SendfaxEx_2(
101
- :Username => @username,
102
- :Password => @password,
103
- :FileTypes => @type,
104
- :Postpone => @at,
105
- :RetriesToPerform => @retries,
106
- :FaxNumbers=> @recipients,
107
- :FilesData => @content,
108
- :FileSizes => @content.size,
109
- :Subject => @subject,
110
- :PageSize => 'A4',
111
- :PageOrientation => 'Portrait',
112
- :IsHighResolution => 'true',
113
- :IsFineRendering => 'false'
114
- )
115
- result ? result.sendfaxEx_2Result : nil
116
- end
117
-
118
- end
119
-
120
- end
@@ -1,13 +0,0 @@
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
@@ -1,223 +0,0 @@
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