it_cloud_sms 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/it_cloud_sms.rb +93 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c5f375d9aed19221f56d16fc319448177b665d08
|
4
|
+
data.tar.gz: e5358268ed6afae1fc4bf51b9c69f579a3e279d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7996a169560aec7616487f63c774fd604c10935db584f53e15e822c5790b04c356770ff23a5c088f82c5b5c2efaf56a511daa9c0e1cd052cbd1a7ca3e25e9c3d
|
7
|
+
data.tar.gz: 502be17f4a7b5c17add4ec2f68f12c2c0fe7f2bcb26685cace6729267bc98b4bcfc0c81a329a7b92268e6437dcaddef1fc8acd8775ae12ff859de1dc727af6b7
|
data/lib/it_cloud_sms.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'phone'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module ItCloudSms
|
5
|
+
|
6
|
+
PhoneFormat = "%c%a%n"
|
7
|
+
APIUri = URI.parse("https://sistemasmasivos.com/itcloud/api/sendsms/send.php")
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
@@login = ""
|
12
|
+
@@password = ""
|
13
|
+
@@from = ""
|
14
|
+
|
15
|
+
def login=(username)
|
16
|
+
@@login = username
|
17
|
+
end
|
18
|
+
|
19
|
+
def password=(secret)
|
20
|
+
@@password = secret
|
21
|
+
end
|
22
|
+
|
23
|
+
# Send a petition to ItCloud SMS gateway
|
24
|
+
#
|
25
|
+
# Example:
|
26
|
+
# >> ItCloudSms.send_sms(:login => "login",
|
27
|
+
# :password => "password",
|
28
|
+
# :destination => "573102111111" || ["573102111111", "573102111112"], # Up to 500 numbers
|
29
|
+
# :message => "Message with 159 chars maximum")
|
30
|
+
def send_sms(options = {})
|
31
|
+
# Check for login
|
32
|
+
login = options[:login] || @@login
|
33
|
+
raise ArgumentError, "Login must be present" unless login and not login.blank?
|
34
|
+
|
35
|
+
# Check for password
|
36
|
+
password = options[:password] || @@password
|
37
|
+
raise ArgumentError, "Password must be present" unless password and not password.blank?
|
38
|
+
|
39
|
+
# Multiple destinations support
|
40
|
+
options[:destination] = [options[:destination]] unless options[:destination].kind_of?(Array)
|
41
|
+
|
42
|
+
# Check for max destinations
|
43
|
+
raise ArgumentError, "Max of 500 destinations exceeded" if (options[:destination].size > 500)
|
44
|
+
|
45
|
+
destinations = []
|
46
|
+
options[:destination].each do |phone|
|
47
|
+
raise ArgumentError, "Recipient must be a telephone number with international format: #{phone.to_s}" unless Phoner::Phone.valid?(phone.to_s)
|
48
|
+
destinations << Phoner::Phone.parse(phone.to_s).format(PhoneFormat)
|
49
|
+
end
|
50
|
+
|
51
|
+
message = options[:message].to_s
|
52
|
+
raise ArgumentError, "Message must be present" if message.blank?
|
53
|
+
raise ArgumentError, "Message is 159 chars maximum" if message.size > 159
|
54
|
+
|
55
|
+
http = Net::HTTP.new(APIUri.host, APIUri.port)
|
56
|
+
http.use_ssl = true
|
57
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
58
|
+
|
59
|
+
request = Net::HTTP::Post.new(APIUri.request_uri)
|
60
|
+
request.set_form_data({'user' => login,
|
61
|
+
'password' => password,
|
62
|
+
'GSM' => destinations.join(","),
|
63
|
+
'SMSText' => message})
|
64
|
+
|
65
|
+
response = http.request(request)
|
66
|
+
if response.code == "200"
|
67
|
+
case response.body
|
68
|
+
when "-1" then
|
69
|
+
raise StandardError, "Authentication failed"
|
70
|
+
when "-2" then
|
71
|
+
raise StandardError, "Out of hours"
|
72
|
+
when "-3" then
|
73
|
+
raise StandardError, "No credit"
|
74
|
+
when "-4" then
|
75
|
+
raise StandardError, "Wrong number"
|
76
|
+
when "-5" then
|
77
|
+
raise StandardError, "Wrong message"
|
78
|
+
when "-6" then
|
79
|
+
raise StandardError, "System under maintenance"
|
80
|
+
when "-7" then
|
81
|
+
raise StandardError, "Max cellphones reached"
|
82
|
+
when "0" then
|
83
|
+
raise StandardError, "Operator not found"
|
84
|
+
else
|
85
|
+
return response.body
|
86
|
+
end
|
87
|
+
else
|
88
|
+
raise RuntimeError, "Server responded with code #{response.code}: #{response.body}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: it_cloud_sms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Angel García Pérez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: phone
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.7
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>'
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.1
|
55
|
+
description: A gateway to send SMS using HTTP POST, through IT Cloud Services Colombia,
|
56
|
+
written in ruby
|
57
|
+
email: wage83@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/it_cloud_sms.rb
|
63
|
+
homepage: http://www.itcloudcolombia.com/?page_id=23
|
64
|
+
licenses: []
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: IT Cloud Services Colombia send SMS HTTP gateway
|
86
|
+
test_files: []
|