tww 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -1
- data/lib/tww/client.rb +5 -22
- data/lib/tww/rest.rb +30 -0
- data/lib/tww/testing.rb +9 -10
- data/lib/tww/version.rb +1 -1
- data/lib/tww.rb +19 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8622b73ff31b0ee85a6d40fbb8f7b8a19983fc2e
|
4
|
+
data.tar.gz: e0cbbb0b9bcc6e9f94eb6d1d61f7d803490c9c7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecb99ea6eb58aca60f2f8edceff6cd2458dc991a9e6200fe2255d1f67c07bd656e31b66c453742ca7573bbcc83e0c5868c91154c6929af0e7404798370b7f928
|
7
|
+
data.tar.gz: a4eeecc3693ad70213f9c611395e20661960854ce4eb982eb183eb148cdf58515236da4b5313958fb615248e182c5d0275cf3500cd2c34463cef78df3e5144db
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
|
27
|
+
To send SMS:
|
28
28
|
|
29
29
|
```ruby
|
30
30
|
TWW.config do |config|
|
@@ -48,6 +48,31 @@ when resp.error?
|
|
48
48
|
end
|
49
49
|
```
|
50
50
|
|
51
|
+
To fake SMS:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require 'rspec'
|
55
|
+
require 'tww
|
56
|
+
|
57
|
+
TWW.enable_testing!
|
58
|
+
|
59
|
+
RSpec.describe 'TWW Testing' do
|
60
|
+
before
|
61
|
+
client = TWW.client
|
62
|
+
resp = client.deliver('11987654321', 'Hello World from TWW Gem')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'is not empty' do
|
66
|
+
expect(client.sent).to_not be_empty
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'is empty after clear'
|
70
|
+
client.clear
|
71
|
+
expect(client.sent).to be_empty
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
51
76
|
## Development
|
52
77
|
|
53
78
|
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
@@ -1,32 +1,15 @@
|
|
1
|
-
require 'restclient'
|
2
1
|
require 'tww/response'
|
3
2
|
|
4
3
|
module TWW
|
5
4
|
class Client
|
6
|
-
attr_accessor :config
|
5
|
+
attr_accessor :config, :sent
|
7
6
|
|
8
|
-
def
|
9
|
-
|
10
|
-
NumUsu: config.username,
|
11
|
-
Senha: config.password,
|
12
|
-
SeuNum: config.from,
|
13
|
-
Celular: phone,
|
14
|
-
Mensagem: message
|
15
|
-
|
16
|
-
Response.parse(xml)
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
def host
|
21
|
-
'https://webservices.twwwireless.com.br'
|
7
|
+
def initialize
|
8
|
+
@sent = []
|
22
9
|
end
|
23
10
|
|
24
|
-
def
|
25
|
-
'
|
26
|
-
end
|
27
|
-
|
28
|
-
def endpoint
|
29
|
-
host + action
|
11
|
+
def deliver(phone, message)
|
12
|
+
raise 'Need to be implemented'
|
30
13
|
end
|
31
14
|
end
|
32
15
|
end
|
data/lib/tww/rest.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'restclient'
|
2
|
+
require 'tww/client'
|
3
|
+
|
4
|
+
module TWW
|
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
|
13
|
+
|
14
|
+
Response.parse(xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def host
|
19
|
+
'https://webservices.twwwireless.com.br'
|
20
|
+
end
|
21
|
+
|
22
|
+
def action
|
23
|
+
'/reluzcap/wsreluzcap.asmx/EnviaSMS'
|
24
|
+
end
|
25
|
+
|
26
|
+
def endpoint
|
27
|
+
host + action
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/tww/testing.rb
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
require 'tww/client'
|
2
|
-
require 'tww/response'
|
3
2
|
|
4
3
|
module TWW
|
5
|
-
class Client
|
6
|
-
attr_accessor :sent
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@sent = []
|
10
|
-
end
|
11
|
-
|
4
|
+
class Testing < Client
|
12
5
|
def deliver(phone, message)
|
13
|
-
|
14
|
-
|
6
|
+
Response.parse("<string>#{ status(phone) }</string>").tap do |response|
|
7
|
+
sent.push(phone: phone, message: message, response: response)
|
8
|
+
end
|
15
9
|
end
|
16
10
|
|
17
11
|
def clear
|
18
12
|
sent.clear
|
19
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def status(phone)
|
17
|
+
phone =~ /^\d{10,}$/ ? 'OK' : 'NOK'
|
18
|
+
end
|
20
19
|
end
|
21
20
|
end
|
data/lib/tww/version.rb
CHANGED
data/lib/tww.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
1
|
require 'tww/version'
|
2
2
|
require 'tww/config'
|
3
3
|
require 'tww/client'
|
4
|
+
require 'tww/rest'
|
5
|
+
require 'tww/testing'
|
4
6
|
|
5
7
|
module TWW
|
6
|
-
|
8
|
+
class << self
|
9
|
+
def config
|
10
|
+
@config ||= Config.new
|
11
|
+
@config.tap { |config| yield(config) if block_given? }
|
12
|
+
end
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
def client
|
15
|
+
@factory.new.tap { |client| client.config = config }
|
16
|
+
end
|
17
|
+
|
18
|
+
def enable_testing!
|
19
|
+
@factory = TWW::Testing
|
20
|
+
end
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
def disable_testing!
|
23
|
+
@factory = TWW::REST
|
24
|
+
end
|
15
25
|
end
|
26
|
+
|
27
|
+
disable_testing!
|
16
28
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/tww/client.rb
|
171
171
|
- lib/tww/config.rb
|
172
172
|
- lib/tww/response.rb
|
173
|
+
- lib/tww/rest.rb
|
173
174
|
- lib/tww/testing.rb
|
174
175
|
- lib/tww/version.rb
|
175
176
|
- tww.gemspec
|