smsc-ar 0.0.1 → 1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -6
  3. data/lib/smsc.rb +93 -105
  4. data/smsc-ar.gemspec +2 -1
  5. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2b10b8a052dd82bbc9170a55c50eddc17ff1f4a
4
- data.tar.gz: 0e4d92b3043a23fe69dc6448ba036a664045d246
3
+ metadata.gz: 2533f62ee9b3bb68e1ebd28dc868e57a999ad69c
4
+ data.tar.gz: 71859f691402a3090c214b818d0c2dac241e0184
5
5
  SHA512:
6
- metadata.gz: 2dd468c1b1827476e6c47f4aaf68ca51b2fe3f436d81945a23b03979f305d5329c87ee866ce33200e7420e35d7d8c6e6eedce16819f6ac381d5e5f0e3a937678
7
- data.tar.gz: d8b6dc2366cb787bb447cada6399d4382ef2e24d27e186de9e45787303d6204c0282c78174833f2d3b071c658d55484eb20a5d0b337d8d628b5bde0991b561c5
6
+ metadata.gz: ff11b8b99efc7992f9a867659d889b02beb841712480a9b05a4c29adb3220a3e204a03dafe1fb912303a362c5815d062bedc6ab25104a0c50e83d5ae49bc0220
7
+ data.tar.gz: e55a2fabed3132dcb2eea93307ccdc8c759898280884bace7570a2036336ed97f1df2211e5970b29684ee7271a9bc47bec35a40fe4870c855c1decaf39d3428b
data/README.md CHANGED
@@ -1,15 +1,13 @@
1
- # Smsc::Rails
1
+ # Smsc-ar
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/smsc/rails`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
 
@@ -1,12 +1,11 @@
1
1
  require 'open-uri'
2
2
 
3
3
  class Smsc
4
- attr_reader :errors
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
- begin
31
- response = run('estado')
32
- response["code"] == 200
33
- rescue => e
34
- error(response["code"])
35
- false
36
- end
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
- begin
47
- response = run('estado')
48
- { code: response["code"], message: response["message"] }
49
- rescue => e
50
- error(response["code"])
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
- begin
61
- response = run('saldo')
62
- response["data"]["mensajes"]
63
- rescue => e
64
- error(response["code"])
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
- begin
74
- response = run('cancelqueue')
75
- response["code"] == 200
76
- rescue => e
77
- error(response["code"])
78
- false
79
- end
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
- begin
90
- response = run('encolados', nil, nil, nil, nil, priority)
91
- response["data"]["mensajes"]
92
- rescue => e
93
- error(response["code"])
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
- begin
117
- response = run('enviar', nil, num, msj, time)
118
- response["code"] == 200
119
- rescue => e
120
- error(response["code"])
121
- false
122
- end
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
- begin
142
- response = run('recibidos', lastId)
143
- response["data"].map do |message|
144
- {
145
- id: message["id"],
146
- date: message["fechahora"],
147
- message: message["mensaje"],
148
- from: message["de"],
149
- phone: message["linea"]
150
- }
151
- end
152
- rescue => e
153
- error(response["code"])
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
- begin
166
- response = run('enviados', lastId)
167
- response["data"].map do |message|
168
- {
169
- id: message["id"],
170
- date: message["fechahora"],
171
- message: message["mensaje"],
172
- recipients: message["destinatarios"].map do |recipient|
173
- {
174
- code_area: recipient["prefijo"],
175
- phone: recipient["fijo"],
176
- status: recipient["enviado"]["estado_desc"]
177
- }
178
- end
179
- }
180
- end
181
- rescue => e
182
- error(response["code"])
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
- @errors.any?
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
- @errors << "Parameter not specified"
229
- when 401
230
- @errors << "Unauthorized access"
231
- when 402
232
- @errors << "Unrecognized command"
233
- when 403
234
- @errors << "Wrong number"
235
- when 404
236
- @errors << "You must specify at least one valid number"
237
- when 405
238
- @errors << "You don't have balance in your account"
239
- when 406
240
- @errors << "You have exceeded the daily sms limit"
241
- when 499
242
- @errors << "Unknown error"
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
- @errors << "Server error"
232
+ errors.add(:base, "Server error")
245
233
  end
246
234
  end
247
235
  end
@@ -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 = "0.0.1"
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: 0.0.1
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: 2017-08-21 00:00:00.000000000 Z
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.4.6
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.