locasms 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f33aa42b1dc5d11101c5ffa1a2e7bc33a1237d6
4
- data.tar.gz: b99d06a8c076000c42981c084cf99ed3859ffa44
3
+ metadata.gz: 12853fa646f333fceb3ced3a9fa7c357bb51495d
4
+ data.tar.gz: 65f14f3bd5ec19d1a7a2b6da9d1cac23c72296d0
5
5
  SHA512:
6
- metadata.gz: 7ce62a3e053a3a9c73a9c4cf0181192a41ee93fc194397759e06f6dc95c1f93a2e83ba7815c39b9194443eee3a66fddeb34cd1a2d9d1182457e1e0f6d899044a
7
- data.tar.gz: 8f49e257d858686dfe3c40144599dbdf3a697fe81601c6d6a3bb56892a8b0a1af7b1229216b43190d5f99e75dc1104b55df365647f22d9af3b9b59e25f5cbd85
6
+ metadata.gz: 117a31d340940d5c206576cf81f1571e1b6025811624a6b6ac1b1c074b5b0b8fd29e398c04e0890778132f82b381e50a110b32cb028ba823a7a0f233d10f527b
7
+ data.tar.gz: 44be44b781e6969014462c42cfe2e4e584eab62cd82ad04316b2afd8cbf0f654cb52221a7836ae920da59b879d4c790b08dfbdb712aa4fadc4dc0087c971e196
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9
4
+ - 2.0
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --title LocaSMS Documentation
2
+ --private
3
+ --protected
4
+
5
+ lib/**/*.rb
6
+ README.md
7
+ LICENSE.txt
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb})
3
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Locasms
1
+ # locasms [![Build Status](https://travis-ci.org/mcorp/locasms.png?branch=master)](https://travis-ci.org/mcorp/locasms) [![Dependency Status](https://gemnasium.com/mcorp/locasms.png)](https://gemnasium.com/mcorp/locasms)
2
2
 
3
- TODO: Write a gem description
3
+ Client to consume [LocaSMS api's][0].
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,43 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Simple example:
22
+
23
+ ```ruby
24
+ require 'locasms'
25
+
26
+ cli = LocaSMS::Client.new login: 'LOGIN', password: 'PASSWORD'
27
+
28
+ # delivering message to one mobile
29
+ cli.deliver 'my message', '1155559999'
30
+
31
+ # delivering the same message to multiple mobliles at once
32
+ cli.deliver 'my message', '1199998888,5500002222'
33
+ cli.deliver 'my message', '1199998888', '5500002222'
34
+ cli.deliver 'my message', ['1199998888', '5500002222']
35
+ cli.deliver 'my message', %w(1199998888 5500002222)
36
+
37
+ # scheluling the deliver of a message to one mobile
38
+ cli.deliver_at 'my message', '2013-10-12 20:33:00', '1155559999'
39
+
40
+ # scheluling the deliver of a message to multiple mobiles at once
41
+ cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888,5500002222'
42
+ cli.deliver_at 'my message', '2013-10-12 20:33:00', '1199998888', '5500002222'
43
+ cli.deliver_at 'my message', '2013-10-12 20:33:00', ['1199998888', '5500002222']
44
+ cli.deliver_at 'my message', '2013-10-12 20:33:00', %w(1199998888 5500002222)
45
+
46
+ # geting the remaining balance
47
+ cli.balance
48
+
49
+ # geting the status of a campaign
50
+ cli.campaign_status '0000'
51
+
52
+ # holding a campaign
53
+ cli.campaign_hold '0000'
54
+
55
+ # resuming a campaign
56
+ cli.campaign_release '0000'
57
+ ```
22
58
 
23
59
  ## Contributing
24
60
 
@@ -27,3 +63,5 @@ TODO: Write usage instructions here
27
63
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
64
  4. Push to the branch (`git push origin my-new-feature`)
29
65
  5. Create new Pull Request
66
+
67
+ [0]: http://locasms.com.br/#page_2/
data/Rakefile CHANGED
@@ -1 +1,17 @@
1
- require "bundler/gem_tasks"
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.setup
5
+ Bundler::GemHelper.install_tasks
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new do |spec|
9
+ spec.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ desc 'Open an irb session preloaded with this library'
13
+ task :console do
14
+ sh 'bundle exec irb -rubygems -I lib -r locasms.rb'
15
+ end
16
+
17
+ task :default => :console
@@ -0,0 +1,80 @@
1
+ module LocaSMS
2
+
3
+ # Client to interact with LocaSMS API
4
+ class Client
5
+ # Default API address
6
+ ENDPOINT = 'http://173.44.33.18/painel/api.ashx'
7
+
8
+ attr_reader :login, :password
9
+
10
+ # @param [String] login authorized user
11
+ # @param [String] password access password
12
+ # @param [Hash] opts
13
+ # @option opts :rest_client (RestClient) client to be used to handle http requests
14
+ def initialize(login, password, opts={})
15
+ @login = login
16
+ @password = password
17
+
18
+ @rest = opts[:rest_client]
19
+ end
20
+
21
+ # Sends a message to one or more mobiles
22
+ # @param [String] message message to be sent
23
+ # @param [String,Array<String>] mobiles number of the mobiles to address the message
24
+ # @return [String] campaign id on success
25
+ def deliver(message, *mobiles)
26
+ rest.get :sendsms, msg: message, numbers: mobiles.join(',')
27
+ end
28
+
29
+ # Schedule the send of a message to one or more mobiles
30
+ # @param [String] message message to be sent
31
+ # @param [Time,DateTime,Fixnum,String] datetime
32
+ # @param [String,Array<String>] mobiles number of the mobiles to address the message
33
+ # @return UNDEF
34
+ def deliver_at(message, datetime, *mobiles)
35
+ datetime = Time.at(datetime) if datetime.is_a? Fixnum
36
+ datetime = Time.parse(datetime) if datetime.is_a? String
37
+ datetime = datetime.to_time if datetime.respond_to? :to_time
38
+
39
+ date, time = datetime.strftime('%d/%m/%Y|%H:%M').split('|')
40
+ rest.get :sendsms, numbers: mobiles.join(','), jobdate: date, jobtime: time
41
+ end
42
+
43
+ # Get de current amount of sending credits
44
+ # @return [Fixnum] returns the balance on success
45
+ def balance
46
+ rest.get :getbalance
47
+ end
48
+
49
+ # Gets the current status of the given campaign
50
+ # @param [String] id campaign id
51
+ # @return UNDEF
52
+ def campaign_status(id)
53
+ rest.get :getstatus, id: id
54
+ end
55
+
56
+ # Holds the given campaign to fire
57
+ # @param [String] id campaign id
58
+ # @return [TrueClass,FalseClass] returns true on success
59
+ def campaign_hold(id)
60
+ rest.get :holdsms, id: id
61
+ end
62
+
63
+ # Restart firing the given campaign
64
+ # @param [String] id campaign id
65
+ # @return [TrueClass,FalseClass] returns true on success
66
+ def campaign_release(id)
67
+ rest.get :releasesms, id: id
68
+ end
69
+
70
+ private
71
+
72
+ # Gets the current RestClient to handle http requests
73
+ # @return [RestClient] you can set on class creation passing it on the options
74
+ # @private
75
+ def rest
76
+ @rest ||= RestClient.new ENDPOINT, lgn: login, pwd: password
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,57 @@
1
+ module LocaSMS
2
+
3
+ # Class that handle http calls to LocaSMS api
4
+ # @see https://github.com/mcorp/locasms/wiki/A-API-de-envio List of avaiable services
5
+ class RestClient
6
+ attr_accessor :base_url, :base_params
7
+
8
+ # Creates a new instance of the RestClient class
9
+ # @param [String] base_url a well formed url
10
+ # @param [Hash] base_params base params to send on every call
11
+ def initialize(base_url, base_params={})
12
+ @base_url = base_url
13
+ @base_params = base_params
14
+ end
15
+
16
+ # Performs a GET call for an action
17
+ # @param [String, Symbol] action the given action to perform
18
+ # @param [Hash] params given parameters to send
19
+ # @return [String]
20
+ #
21
+ # @example Calling with no extra parameters
22
+ #
23
+ # client = LocaSMS::RestClient('http://localhost:3000', lgn: 'LOGIN', pwd: 'PASSWORD')
24
+ # # => GET http://localhost:3000?lgn=LOGIN&pws=PASSWORD&action=getballance
25
+ # client.get :getballance
26
+ #
27
+ # @example Calling with extra parameters
28
+ #
29
+ # client = LocaSMS::RestClient('http://localhost:3000', lgn: 'LOGIN', pwd: 'PASSWORD')
30
+ # # => GET http://localhost:3000?lgn=LOGIN&pws=PASSWORD&action=holdsms&id=345678
31
+ # client.get :holdsms, id: 345678
32
+ #
33
+ # @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis List of avaiable actions
34
+ def get(action, params={})
35
+ params = params_for action, params
36
+ response = ::RestClient.get base_url, params: params
37
+ JSON.parse(response) rescue response
38
+ end
39
+
40
+ # Composes the parameters hash
41
+ # @param [String, Symbol] action the given action to perform
42
+ # @param [Hash] params given parameters to send
43
+ # @return [Hash]
44
+ #
45
+ # @example
46
+ #
47
+ # client = LocaSMS::RestClient('http://localhost:3000', lgn: 'LOGIN', pwd: 'PASSWORD')
48
+ # client.params_for :ACTION, a: 1, b: 2
49
+ # # => { action: :ACTION, lgn: 'LOGIN', pwd: 'PASSWORD', a: 1, b: 2 }
50
+ #
51
+ # @see https://github.com/mcorp/locasms/wiki/A-API-de-envio#lista-das-a%C3%A7%C3%B5es-dispon%C3%ADveis List of avaiable actions
52
+ def params_for(action, params={})
53
+ {action: action}.merge(base_params).merge(params)
54
+ end
55
+ end
56
+
57
+ end
@@ -1,3 +1,3 @@
1
- module Locasms
2
- VERSION = "0.1.0"
1
+ module LocaSMS
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/locasms.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "locasms/version"
2
2
 
3
- module Locasms
4
- class Sender
5
- end
3
+ autoload :JSON, 'json'
4
+ autoload :RestClient, 'rest_client'
5
+ autoload :Logger, 'logger'
6
+
7
+ module LocaSMS
8
+ autoload :Client, 'locasms/client'
9
+ autoload :RestClient, 'locasms/rest_client'
6
10
  end
data/locasms.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'locasms/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "locasms"
8
- spec.version = Locasms::VERSION
8
+ spec.version = LocaSMS::VERSION
9
9
  spec.authors = ["Adilson Carvalho"]
10
10
  spec.email = ["lc.adilson@gmail.com"]
11
11
  spec.description = %q{Cliente para o serviço de disparo de SMS da LocaSMS}
@@ -18,6 +18,24 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake', '~> 0.9.2'
23
+
24
+ # test stuff
25
+ spec.add_development_dependency 'rspec', '~> 2.5'
26
+ spec.add_development_dependency 'fuubar', '~> 1.1.0'
27
+
28
+ # run tests automatically
29
+ spec.add_development_dependency 'guard'
30
+ spec.add_development_dependency 'guard-rspec'
31
+ spec.add_development_dependency 'growl'
32
+
33
+ # for documentation
34
+ spec.add_development_dependency 'yard'
35
+ spec.add_development_dependency 'redcarpet'
36
+
37
+ # for code coverage
38
+ spec.add_development_dependency 'simplecov'
39
+
40
+ spec.add_dependency 'rest-client', '~> 1.6'
23
41
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe LocaSMS::Client do
4
+ let(:rest_client) { 'rest_client mock' }
5
+ subject { LocaSMS::Client.new :login, :password, rest_client: rest_client }
6
+
7
+ describe '.initialize' do
8
+ it { subject.login.should be(:login) }
9
+ it { subject.password.should be(:password) }
10
+ end
11
+
12
+ describe '#deliver' do
13
+ before(:each) do
14
+ rest_client.should_receive(:get)
15
+ .once
16
+ .with(:sendsms, msg: 'given message', numbers:'1188882222,5577770000')
17
+ end
18
+
19
+ it{ subject.deliver 'given message', '1188882222,5577770000' }
20
+ it{ subject.deliver 'given message', %w(1188882222 5577770000) }
21
+ it{ subject.deliver 'given message', '1188882222', '5577770000' }
22
+ it{ subject.deliver 'given message', ['1188882222', '5577770000'] }
23
+ end
24
+
25
+ it '#deliver_at'
26
+
27
+ describe '#balance' do
28
+ it 'Should check param assignment' do
29
+ rest_client.should_receive(:get)
30
+ .once
31
+ .with(:getbalance)
32
+
33
+ subject.balance
34
+ end
35
+ end
36
+
37
+ context 'Testing all campaign based methods' do
38
+ def check_for(method)
39
+ rest_method = {
40
+ campaign_status: :getstatus,
41
+ campaign_hold: :holdsms,
42
+ campaign_release: :releasesms
43
+ }[method]
44
+
45
+ rest_client.should_receive(:get)
46
+ .once
47
+ .with(rest_method, id: '12345')
48
+
49
+ subject.send method, '12345'
50
+ end
51
+
52
+ it{ check_for :campaign_status }
53
+ it{ check_for :campaign_hold }
54
+ it{ check_for :campaign_release }
55
+ end
56
+
57
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe LocaSMS::RestClient do
4
+
5
+ describe '.initialize' do
6
+ context 'When giving proper initialization parameters' do
7
+ subject { LocaSMS::RestClient.new :url, :params }
8
+ it { subject.base_url.should be(:url) }
9
+ it { subject.base_params.should be(:params) }
10
+ end
11
+ end
12
+
13
+ describe '#get' do
14
+ it 'Is missing tests for get'
15
+ end
16
+
17
+ describe '#params_for' do
18
+ subject { LocaSMS::RestClient.new :url, { b1: 'X' } }
19
+
20
+ it{ subject.params_for(:action).should == {action: :action, b1: 'X'} }
21
+ it{ subject.params_for(:action, p1: 10).should == {action: :action, b1: 'X', p1: 10} }
22
+ end
23
+
24
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format Fuubar
3
+ --backtrace
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+ # require 'coveralls'
7
+ # require 'simplecov'
8
+
9
+ # SimpleCov.start
10
+
11
+ require 'locasms'
12
+ require 'rspec'
13
+ require 'time'
14
+
15
+ RSpec.configure do |config|
16
+ # see spec.opts
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locasms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adilson Carvalho
@@ -26,6 +26,104 @@ dependencies:
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fuubar
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: redcarpet
29
127
  requirement: !ruby/object:Gem::Requirement
30
128
  requirements:
31
129
  - - '>='
@@ -38,6 +136,34 @@ dependencies:
38
136
  - - '>='
39
137
  - !ruby/object:Gem::Version
40
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rest-client
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: '1.6'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: '1.6'
41
167
  description: Cliente para o serviço de disparo de SMS da LocaSMS
42
168
  email:
43
169
  - lc.adilson@gmail.com
@@ -46,13 +172,22 @@ extensions: []
46
172
  extra_rdoc_files: []
47
173
  files:
48
174
  - .gitignore
175
+ - .travis.yml
176
+ - .yardopts
49
177
  - Gemfile
178
+ - Guardfile
50
179
  - LICENSE.txt
51
180
  - README.md
52
181
  - Rakefile
53
182
  - lib/locasms.rb
183
+ - lib/locasms/client.rb
184
+ - lib/locasms/rest_client.rb
54
185
  - lib/locasms/version.rb
55
186
  - locasms.gemspec
187
+ - spec/lib/locasms/client_spec.rb
188
+ - spec/lib/locasms/rest_client_spec.rb
189
+ - spec/spec.opts
190
+ - spec/spec_helper.rb
56
191
  homepage: https://github.com/mcorp/locasms
57
192
  licenses:
58
193
  - MIT
@@ -77,4 +212,9 @@ rubygems_version: 2.0.6
77
212
  signing_key:
78
213
  specification_version: 4
79
214
  summary: Cliente para o serviço de disparo de SMS da LocaSMS
80
- test_files: []
215
+ test_files:
216
+ - spec/lib/locasms/client_spec.rb
217
+ - spec/lib/locasms/rest_client_spec.rb
218
+ - spec/spec.opts
219
+ - spec/spec_helper.rb
220
+ has_rdoc: