rsipgate 0.2
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/MIT-LICENSE +20 -0
- data/README.md +40 -0
- data/lib/rsipgate.rb +11 -0
- data/lib/rsipgate/base.rb +53 -0
- data/lib/rsipgate/exception.rb +3 -0
- data/lib/rsipgate/fax.rb +14 -0
- data/lib/rsipgate/response.rb +33 -0
- metadata +54 -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.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# rsipgate
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
``` ruby
|
6
|
+
gem 'rsipgate'
|
7
|
+
```
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
Sipgate.user = "your-account"
|
13
|
+
Sipgate.password = "your-password"
|
14
|
+
```
|
15
|
+
If hostname of sipgate different from api.sipgate.net you can set it:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
Sipgate.api_host = "another.api.host.sipgate.net"
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### send a pdf
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
fax = Sipgate::Fax('4912345678', File.read("document.pdf"))
|
27
|
+
result = fax.send
|
28
|
+
```
|
29
|
+
|
30
|
+
### check sending status
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
status = fax.status(result.session_id)
|
34
|
+
```
|
35
|
+
|
36
|
+
## Copyrights
|
37
|
+
|
38
|
+
Copyright (c) 2012 Alexander Simonov (http://simonov.me/), released under the MIT license
|
39
|
+
|
40
|
+
Copyright (c) 2009 Digineo GmbH (http://www.digineo.de/), released under the MIT license
|
data/lib/rsipgate.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Sipgate
|
2
|
+
class Base
|
3
|
+
|
4
|
+
PATH = '/RPC2'
|
5
|
+
|
6
|
+
def my_api_host
|
7
|
+
Sipgate.api_host || 'api.sipgate.net'
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(user = nil, password = nil)
|
11
|
+
user ||= Sipgate.user
|
12
|
+
password ||= Sipgate.password
|
13
|
+
@client = XMLRPC::Client.new3({
|
14
|
+
:host => my_api_host,
|
15
|
+
:path => PATH,
|
16
|
+
:use_ssl => true,
|
17
|
+
:user => user,
|
18
|
+
:password => password,
|
19
|
+
:port => 443
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
# queries the status of a fax
|
24
|
+
def status(session_id)
|
25
|
+
call "samurai.SessionStatusGet",
|
26
|
+
'SessionID' => session_id
|
27
|
+
end
|
28
|
+
|
29
|
+
def call(*args)
|
30
|
+
response = Response.new(rubyized_hash(@client.call(*args)))
|
31
|
+
unless response.success?
|
32
|
+
raise ::Sipgate::Exception, "Response failed with #{response.status_string} with code #{response.status_code}"
|
33
|
+
end
|
34
|
+
response
|
35
|
+
end
|
36
|
+
|
37
|
+
# make server responses look more Ruby like (underscored Symbol as Hash keys)
|
38
|
+
def rubyized_hash(h)
|
39
|
+
h.inject({}) do |memo, (k, v)|
|
40
|
+
value = case v
|
41
|
+
when ::Hash
|
42
|
+
rubyized_hash(v)
|
43
|
+
when ::Array
|
44
|
+
v.map {|item| is_a?(::Hash) ? rubyized_hash(item) : item }
|
45
|
+
else
|
46
|
+
v
|
47
|
+
end
|
48
|
+
memo[k.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym] = value
|
49
|
+
memo
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/rsipgate/fax.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Sipgate
|
2
|
+
class Fax < Base
|
3
|
+
|
4
|
+
# send a fax
|
5
|
+
def send(number, pdf_message)
|
6
|
+
number.gsub!(/^(\+)/, "")
|
7
|
+
number.gsub!(/\s+/, "")
|
8
|
+
call "samurai.SessionInitiate",
|
9
|
+
'RemoteUri' => "sip:#{number}@sipgate.net",
|
10
|
+
'TOS' => 'fax',
|
11
|
+
'Content' => ::Base64.encode64(pdf_message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Sipgate
|
2
|
+
class Response
|
3
|
+
|
4
|
+
CODE_SUCCESS = 200
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
end
|
9
|
+
|
10
|
+
def success?
|
11
|
+
status_code == CODE_SUCCESS
|
12
|
+
end
|
13
|
+
|
14
|
+
%w(session_id session_status status_code status_string).each do |key|
|
15
|
+
define_method(key) { @response[key.to_sym] }
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns the status of a fax transmission. possible answers:
|
19
|
+
# :pending, :sent, :failed
|
20
|
+
def sending_status
|
21
|
+
case session_status
|
22
|
+
when "sending", "queued"
|
23
|
+
:pending
|
24
|
+
when "sent"
|
25
|
+
:sent
|
26
|
+
when "error during submit", "failed"
|
27
|
+
:failed
|
28
|
+
else
|
29
|
+
raise "Could not determine status of response: #{inspect}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsipgate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Simonov
|
9
|
+
- Corny
|
10
|
+
- Averell
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-02-21 00:00:00.000000000Z
|
15
|
+
dependencies: []
|
16
|
+
description:
|
17
|
+
email: alex@simonov.me
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/rsipgate/base.rb
|
23
|
+
- lib/rsipgate/exception.rb
|
24
|
+
- lib/rsipgate/fax.rb
|
25
|
+
- lib/rsipgate/response.rb
|
26
|
+
- lib/rsipgate.rb
|
27
|
+
- README.md
|
28
|
+
- MIT-LICENSE
|
29
|
+
homepage: http://github.com/simonoff/rsipgate
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.7
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.10
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: send fax through sipgate and check their sending status
|
53
|
+
test_files: []
|
54
|
+
has_rdoc:
|