smsc-ar 0.0.1 → 1
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.
- checksums.yaml +4 -4
- data/README.md +76 -6
- data/lib/smsc.rb +93 -105
- data/smsc-ar.gemspec +2 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2533f62ee9b3bb68e1ebd28dc868e57a999ad69c
|
4
|
+
data.tar.gz: 71859f691402a3090c214b818d0c2dac241e0184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff11b8b99efc7992f9a867659d889b02beb841712480a9b05a4c29adb3220a3e204a03dafe1fb912303a362c5815d062bedc6ab25104a0c50e83d5ae49bc0220
|
7
|
+
data.tar.gz: e55a2fabed3132dcb2eea93307ccdc8c759898280884bace7570a2036336ed97f1df2211e5970b29684ee7271a9bc47bec35a40fe4870c855c1decaf39d3428b
|
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
# Smsc
|
1
|
+
# Smsc-ar
|
2
2
|
|
3
|
-
Welcome to
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Welcome to smc-ar the gem to send sms via (www.smsc.com.ar).
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem 'smsc-ar'
|
10
|
+
gem 'smsc-ar', '~> 0.0.1'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -22,7 +20,79 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Create a instance
|
24
|
+
```ruby
|
25
|
+
sms = Smsc.new("your_alias", "your_apikey")
|
26
|
+
```
|
27
|
+
And then..
|
28
|
+
Check if the service is active
|
29
|
+
```ruby
|
30
|
+
sms.active?
|
31
|
+
|
32
|
+
# => true
|
33
|
+
```
|
34
|
+
Check the service status
|
35
|
+
```ruby
|
36
|
+
sms.status
|
37
|
+
|
38
|
+
# => {:code=>200, :message=>""}
|
39
|
+
```
|
40
|
+
Check your account balance
|
41
|
+
```ruby
|
42
|
+
sms.balance
|
43
|
+
|
44
|
+
# => 557
|
45
|
+
```
|
46
|
+
Check the messages received
|
47
|
+
```ruby
|
48
|
+
sms.received
|
49
|
+
|
50
|
+
# => {:id=>"8324966", :date=>"2017-07-19T02:01:02Z", :message=>"#14691 message test", :from=>"0", :phone=>"0"}
|
51
|
+
```
|
52
|
+
Check the messages sent
|
53
|
+
```ruby
|
54
|
+
sms.sent
|
55
|
+
|
56
|
+
# => {:id=>"8889563", :date=>"2017-08-09T00:51:52Z", :message=>"#14691 message test", :recipients=>[{:code_area=>"3584", :phone=>"316256", :status=>"Entregado"}]}
|
57
|
+
```
|
58
|
+
Send a SMS
|
59
|
+
```ruby
|
60
|
+
sms.send("your_phone_number", "your_message") # Example sms.send("0358-154316256","Hey, Casper, Are you there?")
|
61
|
+
|
62
|
+
# => true
|
63
|
+
```
|
64
|
+
See the messages enqueued to send later
|
65
|
+
```ruby
|
66
|
+
# priority 0:all 1:low 2:mid 3:hight
|
67
|
+
|
68
|
+
sms.enqueued(0)
|
69
|
+
|
70
|
+
# => 7234
|
71
|
+
```
|
72
|
+
Check if the number is valid to send a sms
|
73
|
+
```ruby
|
74
|
+
sms.valid_phone?('0358-154316256')
|
75
|
+
|
76
|
+
# => true
|
77
|
+
```
|
78
|
+
Cancel all messages enqueued
|
79
|
+
```ruby
|
80
|
+
sms.cancel_queue
|
81
|
+
|
82
|
+
# => true
|
83
|
+
```
|
84
|
+
Check if the last action have errors
|
85
|
+
```ruby
|
86
|
+
sms.errors?
|
87
|
+
|
88
|
+
# => false
|
89
|
+
```
|
90
|
+
Retrieve the errors of the last action
|
91
|
+
```ruby
|
92
|
+
sms.errors
|
93
|
+
|
94
|
+
# => "Unauthorized access"
|
95
|
+
```
|
26
96
|
|
27
97
|
## Development
|
28
98
|
|
data/lib/smsc.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'open-uri'
|
2
2
|
|
3
3
|
class Smsc
|
4
|
-
|
4
|
+
include ActiveModel::Model
|
5
5
|
|
6
6
|
def initialize(account, apiKey)
|
7
7
|
@alias = account
|
8
8
|
@apiKey = apiKey
|
9
|
-
@errors = []
|
10
9
|
end
|
11
10
|
|
12
11
|
##
|
@@ -14,8 +13,8 @@ class Smsc
|
|
14
13
|
# Return true if is a valid phone number
|
15
14
|
##
|
16
15
|
def valid_phone?(number)
|
16
|
+
response = run('evalnumero', nil, number)
|
17
17
|
begin
|
18
|
-
response = run('evalnumero', nil, number)
|
19
18
|
response["data"]["estado"]
|
20
19
|
rescue => e
|
21
20
|
error(response["code"])
|
@@ -27,13 +26,13 @@ class Smsc
|
|
27
26
|
# Check the server status, return true if it's active, false in other case
|
28
27
|
##
|
29
28
|
def active?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
response = run('estado')
|
30
|
+
success = response["code"] == 200
|
31
|
+
raise 'NoSuccessCode' if !success
|
32
|
+
success
|
33
|
+
rescue => e
|
34
|
+
error(response["code"])
|
35
|
+
false
|
37
36
|
end
|
38
37
|
|
39
38
|
##
|
@@ -43,13 +42,11 @@ class Smsc
|
|
43
42
|
# message: is the message if the query to the serve has problems
|
44
43
|
##
|
45
44
|
def status
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
false
|
52
|
-
end
|
45
|
+
response = run('estado')
|
46
|
+
{ code: response["code"], message: response["message"] }
|
47
|
+
rescue => e
|
48
|
+
error(response["code"])
|
49
|
+
false
|
53
50
|
end
|
54
51
|
|
55
52
|
##
|
@@ -57,26 +54,24 @@ class Smsc
|
|
57
54
|
# return the value balance or false in case of error
|
58
55
|
##
|
59
56
|
def balance
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
false
|
66
|
-
end
|
57
|
+
response = run('saldo')
|
58
|
+
response["data"]["mensajes"]
|
59
|
+
rescue => e
|
60
|
+
error(response["code"])
|
61
|
+
false
|
67
62
|
end
|
68
63
|
|
69
64
|
##
|
70
65
|
# Cancel all messages enqueued
|
71
66
|
##
|
72
67
|
def cancel_queue
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
68
|
+
response = run('cancelqueue')
|
69
|
+
success = response["code"] == 200
|
70
|
+
raise 'NoSuccessCode' if !success
|
71
|
+
success
|
72
|
+
rescue => e
|
73
|
+
error(response["code"])
|
74
|
+
false
|
80
75
|
end
|
81
76
|
|
82
77
|
##
|
@@ -86,13 +81,11 @@ class Smsc
|
|
86
81
|
# return an array with all messages enqueued with te priority specified
|
87
82
|
##
|
88
83
|
def enqueued(priority=0)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
false
|
95
|
-
end
|
84
|
+
response = run('encolados', nil, nil, nil, nil, priority)
|
85
|
+
response["data"]["mensajes"]
|
86
|
+
rescue => e
|
87
|
+
error(response["code"])
|
88
|
+
false
|
96
89
|
end
|
97
90
|
|
98
91
|
##
|
@@ -103,7 +96,7 @@ class Smsc
|
|
103
96
|
##
|
104
97
|
# take 3 params, num, msj time
|
105
98
|
# num: is the phone number with code area included by the fault the api of Sms
|
106
|
-
# require the phone number on format xxxx-xxxxxxxxx, but, if you have other
|
99
|
+
# require the phone number on format xxxx-xxxxxxxxx, but, if you have other
|
107
100
|
# format, you can check it with the method valid_phone?(phone_number)
|
108
101
|
# msj: is a string with the message to send, a message has "180(CHECK)"
|
109
102
|
# characters, if you include more characters, so you're sending two messages
|
@@ -113,13 +106,13 @@ class Smsc
|
|
113
106
|
# Return true if the message was sended, false in other case
|
114
107
|
##
|
115
108
|
def send(num, msj, time=nil)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
109
|
+
response = run('enviar', nil, num, msj, time)
|
110
|
+
success = response["code"] == 200
|
111
|
+
raise 'NoSuccessCode' if !success
|
112
|
+
success
|
113
|
+
rescue => e
|
114
|
+
error(response["code"])
|
115
|
+
false
|
123
116
|
end
|
124
117
|
|
125
118
|
##
|
@@ -129,63 +122,59 @@ class Smsc
|
|
129
122
|
#
|
130
123
|
##
|
131
124
|
# Return the lastest 30 messages received
|
132
|
-
#
|
125
|
+
#
|
133
126
|
# You can specified an URL on https://www.smsc.com.ar/usuario/api/ then the
|
134
|
-
# App will make a get to the url specified, that means you receive a new
|
135
|
-
# message
|
136
|
-
#
|
127
|
+
# App will make a get to the url specified, that means you receive a new
|
128
|
+
# message
|
129
|
+
#
|
137
130
|
# you can add a paramater 'lastId' by default none, and you can check all
|
138
131
|
# messages recevided from the id specified.
|
139
132
|
##
|
140
133
|
def received(lastId=nil)
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
false
|
155
|
-
end
|
134
|
+
response = run('recibidos', lastId)
|
135
|
+
response["data"].map do |message|
|
136
|
+
{
|
137
|
+
id: message["id"],
|
138
|
+
date: message["fechahora"],
|
139
|
+
message: message["mensaje"],
|
140
|
+
from: message["de"],
|
141
|
+
phone: message["linea"]
|
142
|
+
}
|
143
|
+
end
|
144
|
+
rescue => e
|
145
|
+
error(response["code"])
|
146
|
+
false
|
156
147
|
end
|
157
148
|
|
158
149
|
##
|
159
150
|
# Return the lastest 30 smsc messages sent
|
160
|
-
#
|
151
|
+
#
|
161
152
|
# you can add a paramater 'lastId' by default none, and you can check all
|
162
153
|
# messages sent from the id specified.
|
163
154
|
##
|
164
155
|
def sent(lastId=nil)
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
false
|
184
|
-
end
|
156
|
+
response = run('enviados', lastId)
|
157
|
+
response["data"].map do |message|
|
158
|
+
{
|
159
|
+
id: message["id"],
|
160
|
+
date: message["fechahora"],
|
161
|
+
message: message["mensaje"],
|
162
|
+
recipients: message["destinatarios"].map do |recipient|
|
163
|
+
{
|
164
|
+
code_area: recipient["prefijo"],
|
165
|
+
phone: recipient["fijo"],
|
166
|
+
status: recipient["enviado"]["estado_desc"]
|
167
|
+
}
|
168
|
+
end
|
169
|
+
}
|
170
|
+
end
|
171
|
+
rescue => e
|
172
|
+
error(response["code"])
|
173
|
+
false
|
185
174
|
end
|
186
175
|
|
187
176
|
def errors?
|
188
|
-
|
177
|
+
errors.any?
|
189
178
|
end
|
190
179
|
|
191
180
|
private
|
@@ -222,26 +211,25 @@ class Smsc
|
|
222
211
|
end
|
223
212
|
|
224
213
|
def error(code)
|
225
|
-
@errors = []
|
226
214
|
case code.to_i
|
227
|
-
when 400
|
228
|
-
|
229
|
-
when 401
|
230
|
-
|
231
|
-
when 402
|
232
|
-
|
233
|
-
when 403
|
234
|
-
|
235
|
-
when 404
|
236
|
-
|
237
|
-
when 405
|
238
|
-
|
239
|
-
when 406
|
240
|
-
|
241
|
-
when 499
|
242
|
-
|
215
|
+
when 400
|
216
|
+
errors.add(:base, "Parameter not specified")
|
217
|
+
when 401
|
218
|
+
errors.add(:base, "Unauthorized access")
|
219
|
+
when 402
|
220
|
+
errors.add(:base, "Unrecognized command")
|
221
|
+
when 403
|
222
|
+
errors.add(:base, "Wrong number")
|
223
|
+
when 404
|
224
|
+
errors.add(:base, "You must specify at least one valid number")
|
225
|
+
when 405
|
226
|
+
errors.add(:base, "You don't have balance in your account")
|
227
|
+
when 406
|
228
|
+
errors.add(:base, "You have exceeded the daily sms limit")
|
229
|
+
when 499
|
230
|
+
errors.add(:base, "Unknown error")
|
243
231
|
else
|
244
|
-
|
232
|
+
errors.add(:base, "Server error")
|
245
233
|
end
|
246
234
|
end
|
247
235
|
end
|
data/smsc-ar.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "smsc-ar"
|
7
|
-
spec.version = "
|
7
|
+
spec.version = "1"
|
8
8
|
spec.authors = ["Ezequiel Depetris"]
|
9
9
|
spec.email = ["ezedepetris@gmail.com"]
|
10
10
|
|
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "ruby", "~> 2.1"
|
25
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smsc-ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezequiel Depetris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
55
69
|
description: A library to send/receive sms Argentina using the app smsc (www.smsc.com.ar)
|
56
70
|
email:
|
57
71
|
- ezedepetris@gmail.com
|
@@ -91,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
105
|
version: '0'
|
92
106
|
requirements: []
|
93
107
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.5.1
|
95
109
|
signing_key:
|
96
110
|
specification_version: 4
|
97
111
|
summary: A library to send/receive sms on Argentina.
|