sipgate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +23 -0
  3. data/init.rb +3 -0
  4. data/lib/error.rb +10 -0
  5. data/lib/response.rb +44 -0
  6. data/lib/sipgate.rb +57 -0
  7. metadata +61 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Digineo GmbH, Germany
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 ADDED
@@ -0,0 +1,23 @@
1
+ Configuration
2
+ ================
3
+
4
+ Sipgate.user = "your-account"
5
+ Sipgate.password = "your-password"
6
+
7
+
8
+ Usage
9
+ ============
10
+
11
+
12
+ sip = Sipgate.new
13
+
14
+ # send a pdf
15
+ result = sip.fax(4912345678, File.read("document.pdf"))
16
+
17
+ # check sending status
18
+ status = sip.status(result.session_id)
19
+
20
+
21
+
22
+
23
+ Copyright (c) 2009 Digineo GmbH (http://www.digineo.de/), released under the MIT license
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'sipgate'
2
+ require 'response'
3
+ require 'error'
data/lib/error.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Sipgate::Exception < Exception
2
+
3
+ attr_reader :code
4
+
5
+ def initialize(message,code)
6
+ @code = code
7
+ super(message)
8
+ end
9
+
10
+ end
data/lib/response.rb ADDED
@@ -0,0 +1,44 @@
1
+ class Sipgate::Response
2
+
3
+ CODE_SUCCESS = 200
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def success?
10
+ status_code == CODE_SUCCESS
11
+ end
12
+
13
+ def session_id
14
+ @response[:session_id]
15
+ end
16
+
17
+ def session_status
18
+ @response[:session_status]
19
+ end
20
+
21
+ def status_code
22
+ @response[:status_code]
23
+ end
24
+
25
+ def status_string
26
+ @response[:status_string]
27
+ end
28
+
29
+ # gibt den Status eines Fax-Versandes zurück. Mögliche Antworten:
30
+ # :pending, :sent, :failed
31
+ def sending_status
32
+ case session_status
33
+ when "sending", "queued"
34
+ :pending
35
+ when "sent"
36
+ :sent
37
+ when "error during submit", "failed"
38
+ :failed
39
+ else
40
+ raise "Konnte keinen Status aus Antwort ermitteln: #{inspect}"
41
+ end
42
+ end
43
+
44
+ end
data/lib/sipgate.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'xmlrpc/client'
2
+
3
+ class Sipgate
4
+
5
+ cattr_accessor :user, :password
6
+
7
+ def initialize
8
+ @client = XMLRPC::Client.new2("https://#{self.class.user}:#{self.class.password}@samurai.sipgate.net/RPC2")
9
+ http = @client.instance_variable_get(:@http)
10
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
11
+ http.ca_path = '/etc/ssl/certs'
12
+ end
13
+
14
+ # versendet ein Fax
15
+ def fax(number, pdf_message)
16
+ number = number.gsub(/^(\+)/, "").gsub(/\s+/, "")
17
+
18
+ call "samurai.SessionInitiate",
19
+ 'RemoteUri' => "sip:#{number}@sipgate.net",
20
+ 'TOS' => 'fax',
21
+ 'Content' => Base64.encode64(pdf_message)
22
+ end
23
+
24
+ # fragt den Status eines Faxes ab
25
+ def status(session_id)
26
+ call "samurai.SessionStatusGet",
27
+ 'SessionID' => session_id
28
+ end
29
+
30
+ def call(*args)
31
+ response = Response.new(rubyized_hash(@client.call(*args)))
32
+
33
+ unless response.success?
34
+ raise Sipgate::Exception.new(response.status_string, response.status_code)
35
+ end
36
+
37
+ response
38
+ end
39
+
40
+ # make server responses look more Ruby like (underscored Symbol as Hash keys)
41
+ # source: http://github.com/martinrehfeld/telefon/blob/7133964255eefb4679d8759f467ec2f749459aaa/app/models/sipgate.rb
42
+ def rubyized_hash(h)
43
+ returning new_hash = {} do
44
+ h.each do |k,v|
45
+ new_val = if v.is_a?(Hash)
46
+ rubyized_hash(v)
47
+ elsif v.is_a?(Array)
48
+ v.map{|e| e.is_a?(Hash) ? rubyized_hash(e) : e}
49
+ else
50
+ v
51
+ end
52
+ new_hash[k.to_s.underscore.to_sym] = new_val
53
+ end
54
+ end
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sipgate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Corny
8
+ - Averell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-08-21 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: send fax through sipgate and check their sending status.
18
+ email: github@digineo.de
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - MIT-LICENSE
27
+ - README
28
+ - init.rb
29
+ - lib/sipgate.rb
30
+ - lib/response.rb
31
+ - lib/error.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/corny/sipgate
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: send fax through sipgate and check their sending status.
60
+ test_files: []
61
+