interfax 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 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.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = interfax
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Sascha Brink. See LICENSE for details.
data/Rakefile ADDED
@@ -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.1.0
data/lib/interfax.rb ADDED
@@ -0,0 +1,8 @@
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'
@@ -0,0 +1,131 @@
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("http://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
+ SOAP::WSDLDriverFactory.new("http://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
+ end
116
+
117
+ end
118
+
119
+ end
120
+
121
+
122
+ #
123
+ # aa = OrderFax.new(:html).contains("<h1>test</h1>").subject("yes").to("+49236189013699")
124
+ # aa.summary
125
+ # aa.deliver
126
+ #
127
+ # OrderFax.all
128
+ # OrderFax.find(173581304)
129
+ #
130
+ #
131
+
@@ -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,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Interfax" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
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
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: interfax
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Sascha Brink
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-11 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A ruby wrapper for the interfax webservice (SOAP)
38
+ email: sascha.brink@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - lib/interfax.rb
52
+ - lib/interfax/base.rb
53
+ - lib/interfax/fax_item.rb
54
+ - spec/interfax_spec.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/sbrink/interfax
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A ruby wrapper for the interfax webservice (SOAP)
91
+ test_files:
92
+ - spec/interfax_spec.rb
93
+ - spec/spec_helper.rb