smsc-ar 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2b10b8a052dd82bbc9170a55c50eddc17ff1f4a
4
+ data.tar.gz: 0e4d92b3043a23fe69dc6448ba036a664045d246
5
+ SHA512:
6
+ metadata.gz: 2dd468c1b1827476e6c47f4aaf68ca51b2fe3f436d81945a23b03979f305d5329c87ee866ce33200e7420e35d7d8c6e6eedce16819f6ac381d5e5f0e3a937678
7
+ data.tar.gz: d8b6dc2366cb787bb447cada6399d4382ef2e24d27e186de9e45787303d6204c0282c78174833f2d3b071c658d55484eb20a5d0b337d8d628b5bde0991b561c5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ezedepetris@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smsc-ar.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ezequiel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Smsc::Rails
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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'smsc-ar'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install smsc-ar
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ezedepetris/smsc-ar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "smsc/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,247 @@
1
+ require 'open-uri'
2
+
3
+ class Smsc
4
+ attr_reader :errors
5
+
6
+ def initialize(account, apiKey)
7
+ @alias = account
8
+ @apiKey = apiKey
9
+ @errors = []
10
+ end
11
+
12
+ ##
13
+ # Valid the phone number
14
+ # Return true if is a valid phone number
15
+ ##
16
+ def valid_phone?(number)
17
+ begin
18
+ response = run('evalnumero', nil, number)
19
+ response["data"]["estado"]
20
+ rescue => e
21
+ error(response["code"])
22
+ false
23
+ end
24
+ end
25
+
26
+ ##
27
+ # Check the server status, return true if it's active, false in other case
28
+ ##
29
+ def active?
30
+ begin
31
+ response = run('estado')
32
+ response["code"] == 200
33
+ rescue => e
34
+ error(response["code"])
35
+ false
36
+ end
37
+ end
38
+
39
+ ##
40
+ # Check the server status
41
+ # Return hash with the keys :code, :message
42
+ # code: is the status of the server response, 200 its oky!
43
+ # message: is the message if the query to the serve has problems
44
+ ##
45
+ 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
53
+ end
54
+
55
+ ##
56
+ # Check the balanca on Smsc
57
+ # return the value balance or false in case of error
58
+ ##
59
+ def balance
60
+ begin
61
+ response = run('saldo')
62
+ response["data"]["mensajes"]
63
+ rescue => e
64
+ error(response["code"])
65
+ false
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Cancel all messages enqueued
71
+ ##
72
+ def cancel_queue
73
+ begin
74
+ response = run('cancelqueue')
75
+ response["code"] == 200
76
+ rescue => e
77
+ error(response["code"])
78
+ false
79
+ end
80
+ end
81
+
82
+ ##
83
+ # Chek the messages enqueued to send later
84
+ # by default the parameter is 0
85
+ # param priority 0:all 1:low 2:middle 3:high
86
+ # return an array with all messages enqueued with te priority specified
87
+ ##
88
+ 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
96
+ end
97
+
98
+ ##
99
+ # ###########################################
100
+ # ######## Method to send a SMS #########
101
+ # ###########################################
102
+ #
103
+ ##
104
+ # take 3 params, num, msj time
105
+ # 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
107
+ # format, you can check it with the method valid_phone?(phone_number)
108
+ # msj: is a string with the message to send, a message has "180(CHECK)"
109
+ # characters, if you include more characters, so you're sending two messages
110
+ # time: this by default is nil, in case you specified this parameter
111
+ # the message will be enqueue at the datetime specified
112
+ # with the format "YYYY-MM-DD HH:MM:SS"
113
+ # Return true if the message was sended, false in other case
114
+ ##
115
+ 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
123
+ end
124
+
125
+ ##
126
+ # ###############################################
127
+ # ######## Methods for making queries ########
128
+ # ###############################################
129
+ #
130
+ ##
131
+ # Return the lastest 30 messages received
132
+ #
133
+ # 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
+ #
137
+ # you can add a paramater 'lastId' by default none, and you can check all
138
+ # messages recevided from the id specified.
139
+ ##
140
+ 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
156
+ end
157
+
158
+ ##
159
+ # Return the lastest 30 smsc messages sent
160
+ #
161
+ # you can add a paramater 'lastId' by default none, and you can check all
162
+ # messages sent from the id specified.
163
+ ##
164
+ 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
185
+ end
186
+
187
+ def errors?
188
+ @errors.any?
189
+ end
190
+
191
+ private
192
+
193
+ def run(cmd=nil, lastId=nil, num=nil, msj=nil, time=nil, priority=nil)
194
+ query = "https://www.smsc.com.ar/api/0.3/?alias=#{@alias}&apikey=#{@apiKey}&cmd=#{cmd}"
195
+ options = []
196
+ if msj.present?
197
+ options << "msj=#{msj}"
198
+ end
199
+
200
+ if num.present?
201
+ options << "num=#{num}"
202
+ end
203
+
204
+ if lastId.present?
205
+ options << "ultimoid=#{lastId}"
206
+ end
207
+
208
+ if priority.present?
209
+ options << "prioridad=#{priority}"
210
+ end
211
+
212
+ if time.present?
213
+ options << "time=#{time}"
214
+ end
215
+ query += "&#{options.join('&')}" if options.present?
216
+
217
+ begin
218
+ JSON.parse open(query).read
219
+ rescue => e
220
+ { code: 500 }
221
+ end
222
+ end
223
+
224
+ def error(code)
225
+ @errors = []
226
+ 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"
243
+ else
244
+ @errors << "Server error"
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "smsc-ar"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Ezequiel Depetris"]
9
+ spec.email = ["ezedepetris@gmail.com"]
10
+
11
+ spec.homepage = "https://github.com/ezedepetris/smsc-ar"
12
+ spec.summary = "A library to send/receive sms on Argentina."
13
+ spec.description = "A library to send/receive sms Argentina using the app smsc (www.smsc.com.ar)"
14
+ spec.license = "MIT"
15
+
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smsc-ar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ezequiel Depetris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A library to send/receive sms Argentina using the app smsc (www.smsc.com.ar)
56
+ email:
57
+ - ezedepetris@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/smsc.rb
73
+ - smsc-ar.gemspec
74
+ homepage: https://github.com/ezedepetris/smsc-ar
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.4.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: A library to send/receive sms on Argentina.
98
+ test_files: []