tww 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59c8c99e1eb3d3a0fc42449db0b84a8aa7d2aef2
4
- data.tar.gz: ea0314a02f6e28f1b824ef2a9293aaccea6214e8
3
+ metadata.gz: c229b656d63517736b191911f58672c329b6500c
4
+ data.tar.gz: a935eca2ba11c854232ae68ae6aa4e2a0c024c30
5
5
  SHA512:
6
- metadata.gz: 0d41e585ec0d1c5f812868d3c81c032bda2c4a5f4a4006054cddb77a2f049e1663cf6e49ebc00c5cd7c3a3f46784fe67d1cc70f6899ab1941d92d76ae1283f63
7
- data.tar.gz: b819ce7be98649e6b39e51aa4d133995db6225f2302ac184b7a987e21163d978ab5364435a287f280f9bee775bafc11ada8ef4f7ac5bf9edbd98acc9148aedba
6
+ metadata.gz: 1ab238c592a2ed3df9b526eff630dc289c5c1ec720bf04ae419e57c52401a8cdaeed91bf9fce495c8ccb3e9f6056e533fb052af1d472872f8e70022b9ad42af8
7
+ data.tar.gz: 7522d847b8caecf8d6cf23e03a59c126ba77353774878d33d2978859a9269ca8dfd91129618285269949b2f0737ca3b7c0a462307388e09c21648198b9c0aeee
data/.travis.yml CHANGED
@@ -1,8 +1,13 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.1.8
4
- - 2.2.4
5
- - 2.3.0
6
- before_install: gem install bundler -v 1.11.2
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
7
+
8
+ before_install:
9
+ - gem update --system
10
+ - gem update bundler
11
+
7
12
  notifications:
8
13
  email: false
data/README.md CHANGED
@@ -34,7 +34,15 @@ TWW.config do |config|
34
34
  end
35
35
 
36
36
  client = TWW.client
37
- resp = client.deliver('11987654321', 'Hello World from TWW Gem')
37
+
38
+ client.sms('11987654321', 'Hello World using old fashioned SMS')
39
+ client.call('11987654321', 'I just called to say I love you')
40
+ ```
41
+
42
+ You can inspect TWW response:
43
+ ```
44
+ # Previous setup
45
+ resp = client.sms('11987654321', 'Hello World using old fashioned SMS')
38
46
 
39
47
  case
40
48
  when resp.ok?
@@ -52,14 +60,14 @@ To fake SMS:
52
60
 
53
61
  ```ruby
54
62
  require 'rspec'
55
- require 'tww
63
+ require 'tww'
56
64
 
57
65
  TWW.enable_testing!
58
66
 
59
67
  RSpec.describe 'TWW Testing' do
60
68
  before
61
69
  client = TWW.client
62
- resp = client.deliver('11987654321', 'Hello World from TWW Gem')
70
+ resp = client.sms('11987654321', 'Hello World from TWW Gem')
63
71
  end
64
72
 
65
73
  it 'is not empty' do
@@ -73,6 +81,10 @@ RSpec.describe 'TWW Testing' do
73
81
  end
74
82
  ```
75
83
 
84
+ ## Support
85
+
86
+ It supports Ruby version 2.1.x, 2.2.x and 2.3.x.
87
+
76
88
  ## Development
77
89
 
78
90
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/tww/client.rb CHANGED
@@ -8,7 +8,19 @@ module TWW
8
8
  @config, @sent = TWW.config, []
9
9
  end
10
10
 
11
- def deliver(phone, message)
11
+ def clear!
12
+ sent.clear
13
+ end
14
+
15
+ def size
16
+ sent.size
17
+ end
18
+
19
+ def sms(phone, message, extras = {})
20
+ raise 'Need to be implemented'
21
+ end
22
+
23
+ def call(phone, message, extras = {})
12
24
  raise 'Need to be implemented'
13
25
  end
14
26
  end
data/lib/tww/config.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class TWW::Config
2
- attr_accessor :username, :password, :from
2
+ attr_accessor :username, :password, :from, :layout
3
3
  end
data/lib/tww/rest.rb CHANGED
@@ -3,28 +3,55 @@ require 'tww/client'
3
3
 
4
4
  module TWW
5
5
  class REST < Client
6
- def deliver(phone, message)
7
- xml = RestClient.post endpoint,
8
- NumUsu: config.username,
9
- Senha: config.password,
10
- SeuNum: config.from,
11
- Celular: phone,
12
- Mensagem: message
6
+ SMS = 'https://webservices.twwwireless.com.br' +
7
+ '/reluzcap/wsreluzcap.asmx/EnviaSMS'
13
8
 
14
- Response.parse(xml)
9
+ CALL = 'http://webservices.fonadas.tww.com.br' +
10
+ '/ws/Fonadas.asmx/EnviaFonada'
11
+
12
+ def sms(phone, message, extras = {})
13
+ request(SMS, sms_params(phone, message, extras))
14
+ end
15
+
16
+ def call(phone, message, extras = {})
17
+ request(CALL, call_params(phone, message, extras))
15
18
  end
16
19
 
17
20
  private
18
- def host
19
- 'https://webservices.twwwireless.com.br'
21
+ def call_params(phone, message, extras)
22
+ now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
23
+
24
+ {
25
+ numusu: config.username,
26
+ senha: config.password,
27
+ seunum: config.from,
28
+ idlayout: config.layout,
29
+ telefone: phone,
30
+ dataagendamento: now,
31
+ retry: 0,
32
+ retrytime: 0,
33
+ var1: message,
34
+ var2: nil,
35
+ var3: nil,
36
+ var4: nil,
37
+ var5: nil,
38
+ var6: nil
39
+ }.merge(extras)
20
40
  end
21
41
 
22
- def action
23
- '/reluzcap/wsreluzcap.asmx/EnviaSMS'
42
+ def sms_params(phone, message, extras)
43
+ {
44
+ NumUsu: config.username,
45
+ Senha: config.password,
46
+ SeuNum: config.from,
47
+ Celular: phone,
48
+ Mensagem: message
49
+ }.merge(extras)
24
50
  end
25
51
 
26
- def endpoint
27
- host + action
52
+ def request(url, params)
53
+ xml = RestClient.post(url, params)
54
+ Response.parse(xml)
28
55
  end
29
56
  end
30
57
  end
data/lib/tww/testing.rb CHANGED
@@ -2,17 +2,21 @@ require 'tww/client'
2
2
 
3
3
  module TWW
4
4
  class Testing < Client
5
- def deliver(phone, message)
6
- Response.parse("<string>#{ status(phone) }</string>").tap do |response|
7
- sent.push(phone: phone, message: message, response: response)
8
- end
5
+ def sms(phone, message, extras = {})
6
+ request(phone, message, extras)
9
7
  end
10
8
 
11
- def clear
12
- sent.clear
9
+ def call(phone, message, extras = {})
10
+ request(phone, message, extras)
13
11
  end
14
12
 
15
13
  private
14
+ def request(phone, message, extras)
15
+ Response.parse("<string>#{ status(phone) }</string>").tap do |response|
16
+ sent.push(phone: phone, message: message, response: response)
17
+ end
18
+ end
19
+
16
20
  def status(phone)
17
21
  phone =~ /^\d{10,}$/ ? 'OK' : 'NOK'
18
22
  end
data/lib/tww/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TWW
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
data/tww.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.required_ruby_version = '>= 2.1.0'
21
22
  spec.add_dependency 'rest-client', '~> 1.0'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.11'
@@ -26,7 +27,4 @@ Gem::Specification.new do |spec|
26
27
  spec.add_development_dependency 'cucumber', '~> 2.0'
27
28
  spec.add_development_dependency 'coveralls', '~> 0.8.0'
28
29
  spec.add_development_dependency 'webmock', '~> 1.0'
29
- spec.add_development_dependency 'byebug', '~> 8.0'
30
- spec.add_development_dependency 'guard', '~> 2.0'
31
- spec.add_development_dependency 'guard-rake', '~> 1.0'
32
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tww
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Libanori
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -108,48 +108,6 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.0'
111
- - !ruby/object:Gem::Dependency
112
- name: byebug
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '8.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '8.0'
125
- - !ruby/object:Gem::Dependency
126
- name: guard
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '2.0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '2.0'
139
- - !ruby/object:Gem::Dependency
140
- name: guard-rake
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1.0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1.0'
153
111
  description:
154
112
  email:
155
113
  - daniellibanori@gmail.com
@@ -186,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
144
  requirements:
187
145
  - - ">="
188
146
  - !ruby/object:Gem::Version
189
- version: '0'
147
+ version: 2.1.0
190
148
  required_rubygems_version: !ruby/object:Gem::Requirement
191
149
  requirements:
192
150
  - - ">="