tww 0.5.0 → 2.0.2

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
- SHA1:
3
- metadata.gz: 3f8d42f8c0f5cd4deee9843234dfca2b0814337f
4
- data.tar.gz: 945c7086ec1f0c48850e1bd4468229cc2e72122d
2
+ SHA256:
3
+ metadata.gz: 409f5d11b108ae845371fff98d5b45bf147f982f3fabd757bf20d95a15b4f39a
4
+ data.tar.gz: c8dab98c88d72179107135386bebea8b721c856c5078d5898f7d33342df08cdd
5
5
  SHA512:
6
- metadata.gz: 3d271d55d68ab90224469b027bd6e88a5bfe6ea605c7026059b65fa73fbf874f244caebe0130a3c7965f63d763c7c1d913e51a3ff529e8b006e41f98f4f8eb85
7
- data.tar.gz: e1edc2b1482976a31bdebadfc95b4d87f47a39451c01cdb81d2f00f6df528a8b8bf5b1c43bf02f3ce5ccedde2e77acc68b1a5f14d67ee57db409fcb812095377
6
+ metadata.gz: 0f9c950ba027965f9c68cf1114682865b41fe60b5cd7de8a955cd2997ff6a7cf353a314ee11528070f2333f0d95c86ad1eb5f7860e0229eb7753bfb276d2f03c
7
+ data.tar.gz: 59724bbb9ef70f108aad4c9128846c0f5607d258f35e4e0274a039afd24d289ec0bd23f543458c7ec66851e8ccc286dd9813fcc2ab17f7eefc0af2b943dc6cc1
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Style/HashEachMethods:
5
+ Enabled: true
6
+
7
+ Style/HashTransformKeys:
8
+ Enabled: true
9
+
10
+ Style/HashTransformValues:
11
+ Enabled: true
12
+
13
+ Lint/RaiseException:
14
+ Enabled: true
15
+
16
+ Lint/StructNewOverride:
17
+ Enabled: true
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.10
5
- - 2.2.5
6
- - 2.3.1
4
+ - 2.6
5
+ - 2.7
6
+ - 3.0
7
7
 
8
8
  before_install:
9
9
  - gem update --system
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # v2.0.1
2
+
3
+ ## Changes
4
+ - Update bundler version
5
+ - Update ruby version
6
+ - Update dependency version
7
+
8
+ # v2.0.0
9
+
10
+ ## Changes
11
+ - Remove rest-client dependency
12
+ - Optimize symbols as keys
13
+
14
+ # v1.2.0
15
+
16
+ ## Changes
17
+ - Add timeout to TWW gem request
data/README.md CHANGED
@@ -28,16 +28,16 @@ To send SMS:
28
28
 
29
29
  ```ruby
30
30
  TWW.config do |config|
31
- config.username = 'you username goes here'
32
- config.password= 'you password goes here'
33
- config.from = 'Your identification (OPTIONAL)'
34
- config.layout = 'Layout ID (JUST FOR VOICE MESSAGES)'
31
+ config[:username] = 'you username goes here'
32
+ config[:password]= 'you password goes here'
33
+ config[:from] = 'Your identification (OPTIONAL)'
34
+ config[:layout] = 'Layout ID (JUST FOR VOICE MESSAGES)'
35
+ config[:endpoint] = :secondary # :primary is default
35
36
  end
36
37
 
37
38
  client = TWW.client
38
39
 
39
40
  client.deliver('11987654321', 'Hello World using old fashioned SMS')
40
- client.call('11987654321', 'I just called to say I love you')
41
41
  ```
42
42
 
43
43
  You can inspect TWW response:
@@ -58,13 +58,6 @@ when resp.error?
58
58
  end
59
59
  ```
60
60
 
61
- You can use obscure parameters from TWW API.
62
-
63
- ```ruby
64
- # Previous setup
65
- client.call('11987654321', 'Var 1 value', var2: 'Var 2 value', retry: 3)
66
- ```
67
-
68
61
  To fake SMS:
69
62
 
70
63
  ```ruby
@@ -92,7 +85,7 @@ end
92
85
 
93
86
  ## Support
94
87
 
95
- It supports Ruby version 2.1.x, 2.2.x and 2.3.x.
88
+ It supports Ruby version 2.6 and later
96
89
 
97
90
  ## Development
98
91
 
data/lib/tww.rb CHANGED
@@ -1,34 +1,31 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tww/version'
2
- require 'tww/config'
3
4
  require 'tww/client'
4
5
  require 'tww/rest'
5
6
  require 'tww/testing'
6
7
 
7
8
  module TWW
9
+ @config = {}
10
+ @factory = TWW::REST
11
+
8
12
  class << self
13
+ attr_accessor :factory
14
+
9
15
  def config
10
- @config ||= Config.new
11
- @config.tap { |config| yield(config) if block_given? }
16
+ @config.tap { |config| yield(config) if block_given? }
12
17
  end
13
18
 
14
- def client
15
- @client ||= @factory.new
19
+ def client(options = {})
20
+ @factory.new(@config.merge(options))
16
21
  end
17
22
 
18
23
  def enable_testing!
19
- reset_client
20
24
  @factory = TWW::Testing
21
25
  end
22
26
 
23
27
  def disable_testing!
24
- reset_client
25
28
  @factory = TWW::REST
26
29
  end
27
-
28
- def reset_client
29
- @client = nil
30
- end
31
30
  end
32
-
33
- disable_testing!
34
31
  end
data/lib/tww/client.rb CHANGED
@@ -1,26 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tww/response'
2
4
 
3
5
  module TWW
4
6
  class Client
5
- attr_reader :config, :sent
6
-
7
- def initialize
8
- @config, @sent = TWW.config, []
9
- end
10
-
11
- def clear!
12
- sent.clear
13
- end
14
-
15
- def size
16
- sent.size
17
- end
7
+ attr_reader :config
18
8
 
19
- def deliver(phone, message, extras = {})
20
- raise 'Need to be implemented'
9
+ def initialize(config)
10
+ @config = config
21
11
  end
22
12
 
23
- def call(phone, message, extras = {})
13
+ def deliver(_phone, _message, _extras = {})
24
14
  raise 'Need to be implemented'
25
15
  end
26
16
  end
data/lib/tww/response.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rexml/document'
2
4
 
3
5
  module TWW
data/lib/tww/rest.rb CHANGED
@@ -1,57 +1,48 @@
1
- require 'restclient'
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
2
4
  require 'tww/client'
3
5
 
4
6
  module TWW
5
7
  class REST < Client
6
- SMS = 'https://webservices.twwwireless.com.br' +
7
- '/reluzcap/wsreluzcap.asmx/EnviaSMS'
8
-
9
- CALL = 'http://webservices.fonadas.tww.com.br' +
10
- '/ws/Fonadas.asmx/EnviaFonada'
8
+ ENDPOINTS = {
9
+ primary: 'https://webservices.twwwireless.com.br' \
10
+ '/reluzcap/wsreluzcap.asmx/EnviaSMS',
11
+ secondary: 'https://webservices2.twwwireless.com.br' \
12
+ '/reluzcap/wsreluzcap.asmx/EnviaSMS'
13
+ }.freeze
11
14
 
12
15
  def deliver(phone, message, extras = {})
13
- request(SMS, deliver_params(phone, message, extras))
14
- end
15
-
16
- def call(phone, message, extras = {})
17
- request(CALL, call_params(phone, message, extras))
16
+ request(endpoint, deliver_params(phone, message, extras))
18
17
  end
19
18
 
20
19
  private
21
- def call_params(phone, message, extras)
22
- now = Time.now.strftime('%Y-%m-%d %H:%M:%S')
23
20
 
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)
21
+ def endpoint
22
+ ENDPOINTS[config.fetch(:endpoint, :primary)]
40
23
  end
41
24
 
42
25
  def deliver_params(phone, message, extras)
43
26
  {
44
- NumUsu: config.username,
45
- Senha: config.password,
46
- SeuNum: config.from,
27
+ NumUsu: config[:username],
28
+ Senha: config[:password],
29
+ SeuNum: config[:from],
47
30
  Celular: phone,
48
31
  Mensagem: message
49
32
  }.merge(extras)
50
33
  end
51
34
 
52
35
  def request(url, params)
53
- xml = RestClient.post(url, params)
54
- Response.parse(xml)
36
+ uri = URI(url)
37
+ use_ssl = uri.scheme == 'https'
38
+
39
+ Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
40
+ post = Net::HTTP::Post.new(uri)
41
+ post.set_form_data(params)
42
+ res = http.request(post)
43
+
44
+ Response.parse(res.body)
45
+ end
55
46
  end
56
47
  end
57
48
  end
data/lib/tww/testing.rb CHANGED
@@ -1,7 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tww/client'
2
4
 
3
5
  module TWW
4
6
  class Testing < Client
7
+ attr_reader :sent
8
+
9
+ def initialize(config)
10
+ super
11
+ @sent = []
12
+ end
13
+
14
+ def clear!
15
+ sent.clear
16
+ end
17
+
18
+ def size
19
+ sent.size
20
+ end
21
+
5
22
  def deliver(phone, message, extras = {})
6
23
  request(phone, message, extras)
7
24
  end
@@ -11,8 +28,9 @@ module TWW
11
28
  end
12
29
 
13
30
  private
14
- def request(phone, message, extras)
15
- Response.parse("<string>#{ status(phone) }</string>").tap do |response|
31
+
32
+ def request(phone, message, _extras)
33
+ Response.parse("<string>#{status(phone)}</string>").tap do |response|
16
34
  sent.push(phone: phone, message: message, response: response)
17
35
  end
18
36
  end
data/lib/tww/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TWW
2
- VERSION = '0.5.0'
4
+ VERSION = '2.0.2'
3
5
  end
data/tww.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'tww/version'
@@ -7,10 +6,10 @@ Gem::Specification.new do |spec|
7
6
  spec.name = 'tww'
8
7
  spec.version = TWW::VERSION
9
8
  spec.authors = ['Daniel Libanori']
10
- spec.email = ['daniellibanori@gmail.com']
9
+ spec.email = ['daniel.libanori@clicksign.com']
11
10
 
12
11
  spec.summary = 'Send SMS from TWW provider'
13
- spec.homepage = 'https://github.com/dlibanori/tww'
12
+ spec.homepage = 'https://github.com/clicksign/tww'
14
13
  spec.license = 'MIT'
15
14
 
16
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -18,13 +17,14 @@ Gem::Specification.new do |spec|
18
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
18
  spec.require_paths = ['lib']
20
19
 
21
- spec.required_ruby_version = '>= 2.1.0'
22
- spec.add_dependency 'rest-client', '~> 1.0'
20
+ spec.required_ruby_version = '>= 2.6.0'
23
21
 
24
- spec.add_development_dependency 'bundler', '~> 1.11'
25
- spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.0'
27
- spec.add_development_dependency 'cucumber', '~> 2.0'
28
- spec.add_development_dependency 'coveralls', '~> 0.8.0'
29
- spec.add_development_dependency 'webmock', '~> 1.0'
22
+ spec.add_runtime_dependency 'rexml', '~> 3.2'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 2.2'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.10'
27
+ spec.add_development_dependency 'cucumber', '~> 6.1'
28
+ spec.add_development_dependency 'coveralls', '~> 0.8'
29
+ spec.add_development_dependency 'webmock', '~> 3.13'
30
30
  end
metadata CHANGED
@@ -1,123 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tww
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Libanori
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-09 00:00:00.000000000 Z
11
+ date: 2021-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: rexml
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '3.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '3.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.11'
33
+ version: '2.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.11'
40
+ version: '2.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '3.10'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '3.10'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '2.0'
75
+ version: '6.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '2.0'
82
+ version: '6.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.0
89
+ version: '0.8'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.0
96
+ version: '0.8'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '3.13'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.0'
111
- description:
110
+ version: '3.13'
111
+ description:
112
112
  email:
113
- - daniellibanori@gmail.com
113
+ - daniel.libanori@clicksign.com
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
+ - ".rubocop.yml"
120
121
  - ".travis.yml"
122
+ - CHANGELOG.md
121
123
  - Gemfile
122
124
  - LICENSE.txt
123
125
  - README.md
@@ -126,17 +128,16 @@ files:
126
128
  - bin/setup
127
129
  - lib/tww.rb
128
130
  - lib/tww/client.rb
129
- - lib/tww/config.rb
130
131
  - lib/tww/response.rb
131
132
  - lib/tww/rest.rb
132
133
  - lib/tww/testing.rb
133
134
  - lib/tww/version.rb
134
135
  - tww.gemspec
135
- homepage: https://github.com/dlibanori/tww
136
+ homepage: https://github.com/clicksign/tww
136
137
  licenses:
137
138
  - MIT
138
139
  metadata: {}
139
- post_install_message:
140
+ post_install_message:
140
141
  rdoc_options: []
141
142
  require_paths:
142
143
  - lib
@@ -144,16 +145,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
146
  - - ">="
146
147
  - !ruby/object:Gem::Version
147
- version: 2.1.0
148
+ version: 2.6.0
148
149
  required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  requirements:
150
151
  - - ">="
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.5.1
156
- signing_key:
155
+ rubygems_version: 3.0.3
156
+ signing_key:
157
157
  specification_version: 4
158
158
  summary: Send SMS from TWW provider
159
159
  test_files: []
data/lib/tww/config.rb DELETED
@@ -1,3 +0,0 @@
1
- class TWW::Config
2
- attr_accessor :username, :password, :from, :layout
3
- end