whatsapp 0.1.5 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/whats/actions/login.rb +8 -14
- data/lib/whats/actions/send_hsm_message.rb +11 -6
- data/lib/whats/api.rb +2 -1
- data/lib/whats/client.rb +20 -6
- data/lib/whats/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d7b19b343c0738110ddeec50ca5ff20f686aa47241ee7504614f3a3153a193
|
4
|
+
data.tar.gz: f389727beacbbabf4c145cf59da2ab5bd1bb18245800e157e12b383bed7629ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6f4ccb7064627069f645b0c9415cb219c56c51b38d26a4f75d4922c465931ad5b95ab8daab39b65598004d26cb1b5ae5d3f6e637396b87d0bc0f68072d57993
|
7
|
+
data.tar.gz: 6469522f916c4a95c3747d452d4993018681392a6a3aaa6ee0adbaa22d759f42ae870a011775a7d20d02a84330ae425dbc175bb1f7a411496d66fe06f53c3285
|
data/lib/whats/actions/login.rb
CHANGED
@@ -10,32 +10,26 @@ module Whats
|
|
10
10
|
def initialize
|
11
11
|
@user = Whats.configuration.user
|
12
12
|
@password = Whats.configuration.password
|
13
|
+
@client = Whats::Client.new(encoded_auth, :basic)
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
client.request(PATH)
|
13
18
|
end
|
14
19
|
|
15
20
|
def token
|
16
21
|
return @token if valid?
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
response = Typhoeus.post(
|
21
|
-
full_path,
|
22
|
-
headers: { "Authorization" => "Basic #{encoded_auth}" },
|
23
|
-
body: {}
|
24
|
-
)
|
25
|
-
update_atributes response
|
23
|
+
extract_atributes call
|
26
24
|
|
27
25
|
@token
|
28
26
|
end
|
29
27
|
|
30
28
|
private
|
31
29
|
|
32
|
-
|
33
|
-
if response.failure?
|
34
|
-
raise Whats::Errors::RequestError.new("API request error.", response)
|
35
|
-
end
|
36
|
-
|
37
|
-
response = JSON.parse response.body
|
30
|
+
attr_reader :client
|
38
31
|
|
32
|
+
def extract_atributes(response)
|
39
33
|
@token = response["users"].first["token"]
|
40
34
|
@expires_after = response["users"].first["expires_after"]
|
41
35
|
end
|
@@ -5,11 +5,12 @@ module Whats
|
|
5
5
|
class SendHsmMessage
|
6
6
|
PATH = "/v1/messages"
|
7
7
|
|
8
|
-
def initialize(client, wa_id, namespace, element_name, params)
|
8
|
+
def initialize(client, wa_id, namespace, element_name, language, params)
|
9
9
|
@client = client
|
10
10
|
@wa_id = wa_id
|
11
11
|
@namespace = namespace
|
12
12
|
@element_name = element_name
|
13
|
+
@language = language
|
13
14
|
@params = params
|
14
15
|
end
|
15
16
|
|
@@ -19,16 +20,13 @@ module Whats
|
|
19
20
|
|
20
21
|
private
|
21
22
|
|
22
|
-
attr_reader :client, :wa_id, :namespace, :element_name, :params
|
23
|
+
attr_reader :client, :wa_id, :namespace, :element_name, :language, :params
|
23
24
|
|
24
25
|
def payload
|
25
26
|
{
|
26
27
|
hsm: {
|
27
28
|
element_name: element_name,
|
28
|
-
language:
|
29
|
-
code: :pt_BR,
|
30
|
-
policy: :deterministic
|
31
|
-
},
|
29
|
+
language: language.is_a?(Hash) ? language : language_options(language),
|
32
30
|
localizable_params: params,
|
33
31
|
namespace: namespace
|
34
32
|
},
|
@@ -37,6 +35,13 @@ module Whats
|
|
37
35
|
type: :hsm
|
38
36
|
}
|
39
37
|
end
|
38
|
+
|
39
|
+
def language_options(language)
|
40
|
+
{
|
41
|
+
code: language,
|
42
|
+
policy: :deterministic
|
43
|
+
}
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
data/lib/whats/api.rb
CHANGED
@@ -33,12 +33,13 @@ module Whats
|
|
33
33
|
Actions::SendMessage.new(client, username, body).call
|
34
34
|
end
|
35
35
|
|
36
|
-
def send_hsm_message(username, namespace, element_name, params)
|
36
|
+
def send_hsm_message(username, namespace, element_name, language, params)
|
37
37
|
Actions::SendHsmMessage.new(
|
38
38
|
client,
|
39
39
|
username,
|
40
40
|
namespace,
|
41
41
|
element_name,
|
42
|
+
language,
|
42
43
|
params
|
43
44
|
).call
|
44
45
|
end
|
data/lib/whats/client.rb
CHANGED
@@ -4,21 +4,22 @@ require "whats/actions/login"
|
|
4
4
|
|
5
5
|
module Whats
|
6
6
|
class Client
|
7
|
-
def initialize(
|
7
|
+
def initialize(token = nil, token_type = :bearer)
|
8
8
|
@base_path = Whats.configuration.base_path
|
9
|
-
@
|
9
|
+
@token = token || login.token
|
10
|
+
@token_type = token_type
|
10
11
|
end
|
11
12
|
|
12
|
-
def request(path, payload)
|
13
|
+
def request(path, payload = nil)
|
13
14
|
full_path = "#{base_path}#{path}"
|
14
15
|
|
15
16
|
response = Typhoeus.post(
|
16
17
|
full_path,
|
17
18
|
headers: {
|
18
|
-
"Authorization" => "
|
19
|
+
"Authorization" => "#{token_name} #{token}",
|
19
20
|
"Content-Type" => "application/json"
|
20
21
|
},
|
21
|
-
body: payload.to_json
|
22
|
+
body: payload && payload.to_json
|
22
23
|
)
|
23
24
|
|
24
25
|
raise Whats::Errors::RequestError.new("API request error.", response) if response.failure?
|
@@ -28,6 +29,19 @@ module Whats
|
|
28
29
|
|
29
30
|
private
|
30
31
|
|
31
|
-
attr_reader :base_path, :
|
32
|
+
attr_reader :base_path, :token, :token_type
|
33
|
+
|
34
|
+
def token_name
|
35
|
+
case token_type
|
36
|
+
when :basic
|
37
|
+
"Basic"
|
38
|
+
when :bearer
|
39
|
+
"Bearer"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def login
|
44
|
+
Whats::Actions::Login.new
|
45
|
+
end
|
32
46
|
end
|
33
47
|
end
|
data/lib/whats/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whatsapp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bruno Soares
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -216,8 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
216
|
- !ruby/object:Gem::Version
|
217
217
|
version: '0'
|
218
218
|
requirements: []
|
219
|
-
|
220
|
-
rubygems_version: 2.7.7
|
219
|
+
rubygems_version: 3.0.4
|
221
220
|
signing_key:
|
222
221
|
specification_version: 4
|
223
222
|
summary: WhatsApp Enterprise API interface.
|