smspromote 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.rdoc +24 -0
- data/lib/smspromote.rb +13 -0
- data/lib/smspromote/gateway.rb +76 -0
- data/lib/smspromote/message.rb +49 -0
- metadata +89 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2010 Vincent Landgraf
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= SMS Promote Ruby Bindings
|
2
|
+
|
3
|
+
This is a ruby gem that helps you sending sms using the http://smspromote.de
|
4
|
+
service. To start follow the instructions:
|
5
|
+
|
6
|
+
Save your api key in a keystore:
|
7
|
+
|
8
|
+
echo "SECRETKEYJHKSJH123123LKJ" > ~/.smspromote.key
|
9
|
+
|
10
|
+
Create a new ruby source file with the following script
|
11
|
+
|
12
|
+
require "rubygems"
|
13
|
+
require "smspromote"
|
14
|
+
|
15
|
+
API_KEY = SmsPromote::Gateway.read_api_key_from_file
|
16
|
+
GATEWAY = SmsPromote::Gateway.new(API_KEY, :secure => true,
|
17
|
+
:originator => "MY SERVICE OR NUMBER")
|
18
|
+
|
19
|
+
msg = SmsPromote::Message.new('001231231231', 'Hello World')
|
20
|
+
|
21
|
+
GATEWAY.send_messsage(msg)
|
22
|
+
|
23
|
+
p msg.delivered?
|
24
|
+
p msg.cost
|
data/lib/smspromote.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module SmsPromote
|
2
|
+
class Gateway
|
3
|
+
SECURE = "https://gateway.smspromote.de/"
|
4
|
+
INSECURE = "http://gateway.smspromote.de/"
|
5
|
+
|
6
|
+
# returns the api key as string. The api key will be read
|
7
|
+
# from the ".smspromote.key" file from the home directroy of
|
8
|
+
# the current user
|
9
|
+
def self.read_api_key_from_file
|
10
|
+
File.read("#{ENV['HOME']}/.smspromote.key").chomp
|
11
|
+
end
|
12
|
+
|
13
|
+
# create a new gateway using the passed api_key and options
|
14
|
+
# api_key:: [String] yourt api key (e.g. "KAJSHkjhlskfl32jh24")
|
15
|
+
# options:: a hash of options
|
16
|
+
# :secure (true/false) # use ssl or not
|
17
|
+
# :originator (string) # sender address
|
18
|
+
# :debug (true/false) # use the dummy service
|
19
|
+
def initialize(api_key, options = {})
|
20
|
+
@api_key = api_key
|
21
|
+
@options = {
|
22
|
+
:secure => false
|
23
|
+
}.merge(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
# send message using the gateway defaults
|
27
|
+
def send_message(message)
|
28
|
+
options = {
|
29
|
+
:key => @api_key,
|
30
|
+
:to => message.recipient,
|
31
|
+
:message => message.body,
|
32
|
+
:route => route,
|
33
|
+
:concat => message.multipart? ? 1 : 0,
|
34
|
+
:debug => debug? ? 1 : 0,
|
35
|
+
:message_id => 1,
|
36
|
+
:cost => 1,
|
37
|
+
:count => 1
|
38
|
+
}
|
39
|
+
|
40
|
+
# use oroginator if gold route was used
|
41
|
+
if route == :gold
|
42
|
+
options[:from] = @options[:originator]
|
43
|
+
end
|
44
|
+
|
45
|
+
data = parse_response(RestClient.post(service_url, options).body)
|
46
|
+
message.after_send(data[:code], data[:message_id], data[:cost], data[:count])
|
47
|
+
message
|
48
|
+
end
|
49
|
+
|
50
|
+
# returns the response message hash based on the body data
|
51
|
+
def parse_response(body)
|
52
|
+
lines = body.split(/\n/)
|
53
|
+
{
|
54
|
+
:code => lines[0].to_i,
|
55
|
+
:message_id => lines[1],
|
56
|
+
:cost => (lines[2] || "0").to_f,
|
57
|
+
:count => (lines[3] || "0").to_i
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# returns true if the message sending is a dummy operation
|
62
|
+
def debug?
|
63
|
+
!!@options[:debug]
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns either basic or gold
|
67
|
+
def route
|
68
|
+
@options[:originator] ? :gold : :basic
|
69
|
+
end
|
70
|
+
|
71
|
+
# returns the service url based on the security options
|
72
|
+
def service_url
|
73
|
+
@options[:secure] ? SECURE : INSECURE
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SmsPromote
|
2
|
+
class Message
|
3
|
+
attr_reader :type, :reference, :recipient, :body,
|
4
|
+
:code, :message_id, :cost, :count, :send_time
|
5
|
+
|
6
|
+
# creates a new message object with an recipient and a message body
|
7
|
+
# recipient:: [String] the number to send this message
|
8
|
+
# body:: [String] the body of the message
|
9
|
+
def initialize(recipient, body)
|
10
|
+
@recipient = recipient
|
11
|
+
@body = body
|
12
|
+
@type = :default
|
13
|
+
end
|
14
|
+
|
15
|
+
# returns true if the message is valid, false otherwise
|
16
|
+
def valid?
|
17
|
+
!@body.nil? && !@recipient.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
# returns true if the sms has to be send in multiple parts
|
21
|
+
def multipart?
|
22
|
+
@body.length > 160
|
23
|
+
end
|
24
|
+
|
25
|
+
# returns true if the message was send
|
26
|
+
def send?
|
27
|
+
@send
|
28
|
+
end
|
29
|
+
|
30
|
+
# returns true if the message was delivered, false otherwise
|
31
|
+
def delivered?
|
32
|
+
@code == 100
|
33
|
+
end
|
34
|
+
|
35
|
+
# sets the message information after the message has been send
|
36
|
+
# code:: [Fixnum] the message code (e.g. 100)
|
37
|
+
# message_id:: [String] the message id string
|
38
|
+
# cost:: [Float] the cost for sending the message
|
39
|
+
# count:: [Fixnum] the count of smsparts that have been sended
|
40
|
+
def after_send(code, message_id, cost, count)
|
41
|
+
@send_time = Time.now
|
42
|
+
@send = true
|
43
|
+
@code = code
|
44
|
+
@message_id = message_id
|
45
|
+
@cost = cost
|
46
|
+
@count = count
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smspromote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincent Landgraf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-07-11 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.6.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: ""
|
46
|
+
email:
|
47
|
+
- vilandgr@googlemail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files: []
|
53
|
+
|
54
|
+
files:
|
55
|
+
- lib/smspromote/gateway.rb
|
56
|
+
- lib/smspromote/message.rb
|
57
|
+
- lib/smspromote.rb
|
58
|
+
- LICENSE
|
59
|
+
- README.rdoc
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/threez/smspromote
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.5
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: this gem helps sending sms using the smspromote.de sms gateway
|
88
|
+
test_files: []
|
89
|
+
|