netelip_sms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/netelip_sms.rb +69 -0
- metadata +113 -0
data/lib/netelip_sms.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'phone'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module NetelipSms
|
5
|
+
|
6
|
+
PhoneFormat = "00%c%a%n"
|
7
|
+
APIUri = URI.parse("http://sms.netelip.com/api.php")
|
8
|
+
|
9
|
+
@@login = ""
|
10
|
+
@@password = ""
|
11
|
+
@@from = ""
|
12
|
+
|
13
|
+
def login=(username)
|
14
|
+
@@login = username
|
15
|
+
end
|
16
|
+
|
17
|
+
def password=(secret)
|
18
|
+
@@password = secret
|
19
|
+
end
|
20
|
+
|
21
|
+
def from=(sender)
|
22
|
+
@@from = sender
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
|
27
|
+
# Send a petition to Netelip SMS gateway
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# >> NetelipSms.send_sms(:login => "netelip\_login",
|
31
|
+
# :password => "netelip\_password",
|
32
|
+
# :from => "Max 11chars",
|
33
|
+
# :destination => "0034999999999",
|
34
|
+
# :message => "Message with 140 chars maximum")
|
35
|
+
def send_sms(options = {})
|
36
|
+
# Check for login
|
37
|
+
login = options[:login] || @@login
|
38
|
+
raise ArgumentError, "Login must be present" unless login and not login.blank?
|
39
|
+
|
40
|
+
# Check for password
|
41
|
+
password = options[:password] || @@password
|
42
|
+
raise ArgumentError, "Password must be present" unless password and not password.blank?
|
43
|
+
|
44
|
+
from = options[:from].to_s || @@from
|
45
|
+
raise ArgumentError, "Sender must be present (from)" if from.blank?
|
46
|
+
raise ArgumentError, "Sender length 11 characters maximum" if (from.size > 11)
|
47
|
+
|
48
|
+
raise ArgumentError, "Recipient must be a telephone number with international format" unless Phoner::Phone.valid?(options[:destination].to_s)
|
49
|
+
destination = Phoner::Phone.parse(options[:destination].to_s).format(PhoneFormat)
|
50
|
+
|
51
|
+
message = options[:message].to_s
|
52
|
+
raise ArgumentError, "Message must be present" if message.blank?
|
53
|
+
raise ArgumentError, "Message is 140 chars maximum" if message.size > 140
|
54
|
+
|
55
|
+
res = Net::HTTP.post_form(APIUri, 'login' => login,
|
56
|
+
'password' => password,
|
57
|
+
'from' => from,
|
58
|
+
'destination' => destination,
|
59
|
+
'message' => message)
|
60
|
+
|
61
|
+
if res.code == "200"
|
62
|
+
return true
|
63
|
+
else
|
64
|
+
return res.code
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: netelip_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Angel Garc\xC3\xADa P\xC3\xA9rez"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-09-20 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: phone
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
version: "1.0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 49
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 8
|
48
|
+
- 7
|
49
|
+
version: 0.8.7
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: rspec
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 25
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 3
|
64
|
+
- 1
|
65
|
+
version: 1.3.1
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
description: A gateway to send SMS using HTTP POST, through Netelip service, written in ruby
|
69
|
+
email: wage83@gmail.com
|
70
|
+
executables: []
|
71
|
+
|
72
|
+
extensions: []
|
73
|
+
|
74
|
+
extra_rdoc_files: []
|
75
|
+
|
76
|
+
files:
|
77
|
+
- lib/netelip_sms.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://netelip.es/downloads/manuales/netelip_api_sms.pdf
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.4.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Netelip send SMS HTTP gateway
|
112
|
+
test_files: []
|
113
|
+
|