hangouts-chat 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -9
- data/README.md +20 -0
- data/lib/hangouts_chat.rb +10 -5
- data/lib/hangouts_chat/version.rb +1 -1
- data/test/hangouts_chat_test.rb +26 -0
- metadata +5 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ed8b47b674154e8659e4089f70fe8f74bc7b6721a4cd6d9b907c487ad014b0
|
4
|
+
data.tar.gz: d3f323a0c4d91517cbfc40c643038d580c251925c146007a1befe1759809494c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c4f191fa52600b96c73850515a2dc3f1c95839ec3d528ec46123845ab87f62ac235da1f77348ddbe2697c314dacd7ccf94916065008d9aa8dab80db58d58647
|
7
|
+
data.tar.gz: b0ea2b1d2ebaf6c1a1d6e4b3614b46a4a15bafff09033a7f82dbfdebf29b7efe5298188a43df17f40733a26f4d4f570fb92ba60283554b281c8baf77c5b78183
|
data/CHANGELOG.md
CHANGED
@@ -1,22 +1,32 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.0
|
4
|
+
|
5
|
+
- Added ability to specify a thread when send messages (thanks to @hazi)
|
6
|
+
|
3
7
|
## 0.0.6
|
4
|
-
|
8
|
+
|
9
|
+
- Fixed proxy ENV support for ruby versions < 2.5.0
|
5
10
|
|
6
11
|
## 0.0.5
|
7
|
-
|
12
|
+
|
13
|
+
- Resolved missing dependencies for development and testing
|
8
14
|
|
9
15
|
## 0.0.4
|
10
|
-
|
16
|
+
|
17
|
+
- Added Card Messages support
|
11
18
|
|
12
19
|
## 0.0.3
|
13
|
-
|
14
|
-
|
20
|
+
|
21
|
+
- Added YARD documentation
|
22
|
+
- Added HangoutsChat::Sender::APIError exception for unsuccessful responses
|
15
23
|
|
16
24
|
## 0.0.2
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
|
26
|
+
- Added tests
|
27
|
+
- Improved appearance
|
28
|
+
- Added and performed rubocop code analyze
|
20
29
|
|
21
30
|
## 0.0.1
|
22
|
-
|
31
|
+
|
32
|
+
- Initial version with Hangouts Chat simple text messages support
|
data/README.md
CHANGED
@@ -41,6 +41,26 @@ sections = [{ widgets: [{ keyValue: { topLabel: 'Order No.', content: '12345' }
|
|
41
41
|
sender.card(header, sections)
|
42
42
|
```
|
43
43
|
|
44
|
+
### Message to thread
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# Create new thread
|
48
|
+
sender = HangoutsChat::Sender.new 'webhook_URL'
|
49
|
+
res = sender.simple 'text'
|
50
|
+
|
51
|
+
# Response parse
|
52
|
+
res_json = JSON.parse(res.body)
|
53
|
+
thread_name = res_json.dig("thread", "name") #=> "spaces/SPACES_ID/threads/THREADS_ID"
|
54
|
+
|
55
|
+
# Send to thread (simple)
|
56
|
+
sender.simple('res message', thread: thread_name)
|
57
|
+
|
58
|
+
# Send to thread (card)
|
59
|
+
header = {...}
|
60
|
+
sections = {...}
|
61
|
+
sender.card(header, sections, thread: thread_name)
|
62
|
+
```
|
63
|
+
|
44
64
|
### How to get Webhook URL
|
45
65
|
1. Open channel to which you want to send messages
|
46
66
|
2. Click on the channel name in top bar and select 'Configure webhooks'
|
data/lib/hangouts_chat.rb
CHANGED
@@ -18,29 +18,34 @@ module HangoutsChat
|
|
18
18
|
|
19
19
|
# Sends Simple Text Message
|
20
20
|
# @param text [String] text to send to room
|
21
|
+
# @param thread [String] it will be sent as a reply (`nil` is a new thread will be created)
|
21
22
|
# @return [Net::HTTPResponse] response object
|
22
|
-
def simple(text)
|
23
|
+
def simple(text, thread: nil)
|
23
24
|
payload = { text: text }
|
24
|
-
send_request(payload)
|
25
|
+
send_request(payload, thread: thread)
|
25
26
|
end
|
26
27
|
|
27
28
|
# Sends Card Message
|
28
29
|
# @since 0.0.4
|
29
30
|
# @param header [Hash] card header content
|
30
31
|
# @param sections [Array<Hash>] card widgets array
|
32
|
+
# @param thread [String] it will be sent as a reply (`nil` is a new thread will be created)
|
31
33
|
# @return [Net::HTTPResponse] response object
|
32
|
-
def card(header, sections)
|
34
|
+
def card(header, sections, thread: nil)
|
33
35
|
payload = { cards: [header: header, sections: sections] }
|
34
|
-
send_request(payload)
|
36
|
+
send_request(payload, thread: thread)
|
35
37
|
end
|
36
38
|
|
37
39
|
private
|
38
40
|
|
39
41
|
# Sends payload and check response
|
40
42
|
# @param payload [Hash] data to send by POST
|
43
|
+
# @param thread [String] it will be sent as a reply (`nil` is a new thread will be created)
|
41
44
|
# @return [Net::HTTPResponse] response object
|
42
45
|
# @raise [APIError] if got unsuccessful response
|
43
|
-
def send_request(payload)
|
46
|
+
def send_request(payload, thread: nil)
|
47
|
+
payload[:thread] = { name: thread } if thread
|
48
|
+
|
44
49
|
response = @http.post payload
|
45
50
|
raise APIError, response unless response.is_a?(Net::HTTPSuccess)
|
46
51
|
response
|
data/test/hangouts_chat_test.rb
CHANGED
@@ -38,6 +38,32 @@ class HangoutsChatTest < Minitest::Test
|
|
38
38
|
{ cards: [header: header, sections: sections] }.to_json
|
39
39
|
end
|
40
40
|
|
41
|
+
def test_simple_message_threaded_request
|
42
|
+
stub_request(:any, /chat\.googleapis\.com/).to_return(status: 200)
|
43
|
+
message = 'Test simple message'
|
44
|
+
thread = 'spaces/space_id/threads/threads_id'
|
45
|
+
|
46
|
+
@sender.simple(message, thread: thread)
|
47
|
+
|
48
|
+
assert_requested :post, @webhook_url, times: 1, body:
|
49
|
+
{ text: message, thread: { name: thread} }.to_json
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_card_message_threaded_request
|
53
|
+
stub_request(:any, /chat\.googleapis\.com/).to_return(status: 200)
|
54
|
+
header = { title: 'Pizza Bot Customer Support',
|
55
|
+
subtitle: 'pizzabot@example.com',
|
56
|
+
imageUrl: 'https://goo.gl/aeDtrS' }
|
57
|
+
sections = [{ widgets: [{ keyValue: { topLabel: 'Order No.', content: '12345' } },
|
58
|
+
{ keyValue: { topLabel: 'Status', content: 'In Delivery' } }] }]
|
59
|
+
thread = 'spaces/space_id/threads/threads_id'
|
60
|
+
|
61
|
+
@sender.card(header, sections, thread: thread)
|
62
|
+
|
63
|
+
assert_requested :post, @webhook_url, times: 1, body:
|
64
|
+
{ cards: [header: header, sections: sections], thread: { name: thread} }.to_json
|
65
|
+
end
|
66
|
+
|
41
67
|
def test_api_error_exception_message
|
42
68
|
stub_request(:any, /chat\.googleapis\.com/)
|
43
69
|
.to_return(status: [403, 'Forbidden'], body: 'Response body')
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hangouts-chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enzinia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: minitest
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,12 +123,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
125
|
requirements: []
|
140
|
-
|
141
|
-
rubygems_version: 2.7.4
|
126
|
+
rubygems_version: 3.1.2
|
142
127
|
signing_key:
|
143
128
|
specification_version: 4
|
144
129
|
summary: Library for sending messages to Hangouts Chat rooms
|
145
130
|
test_files:
|
146
|
-
- test/hangouts_chat/http_test.rb
|
147
|
-
- test/hangouts_chat_test.rb
|
148
131
|
- test/test_helper.rb
|
132
|
+
- test/hangouts_chat_test.rb
|
133
|
+
- test/hangouts_chat/http_test.rb
|