hangouts-chat 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +28 -6
- data/lib/hangouts_chat/version.rb +1 -1
- data/lib/hangouts_chat.rb +10 -0
- data/test/hangouts_chat_test.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8912faeb8ba44836f727d6808f70e52d5104b217a9f07c76c151b47cd15fd6c
|
4
|
+
data.tar.gz: bc62156c4dfd29a2f850ce00ca85b296a362f58d5bac8ee72cd66ae18b52851c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25bbbd87c104205605c1ff8a4e41a56e9103d30815b0e028b837a3bc4e6a63bb0851d23efdd54c47103fde804a406206c608e81cc6586e78e7ffd1d045573e87
|
7
|
+
data.tar.gz: c608f5466ad57ae5cb72f52c91dccadf225caa77d44ee05ad10885684329a78bdf44ba1c136625850c5861cb813edbe3993ee92e88c5964c79034977d03d6eb1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -13,11 +13,26 @@ require 'hangouts-chat'
|
|
13
13
|
```
|
14
14
|
|
15
15
|
## Usage
|
16
|
+
### Simple Text Message
|
17
|
+
Simple messages that appear inline as if typed by a user. Details and format: [Simple Text Messages](https://developers.google.com/hangouts/chat/reference/message-formats/basic)
|
16
18
|
```ruby
|
17
19
|
sender = HangoutsChat::Sender.new 'webhook_URL'
|
18
20
|
sender.simple 'text'
|
19
21
|
```
|
20
22
|
|
23
|
+
### Card Message
|
24
|
+
More complex messages that have UI elements with actions and HTML support. Details and format: [Card messages](https://developers.google.com/hangouts/chat/reference/message-formats/cards)
|
25
|
+
```ruby
|
26
|
+
sender = HangoutsChat::Sender.new 'webhook_URL'
|
27
|
+
header = { title: 'Pizza Bot Customer Support',
|
28
|
+
subtitle: 'pizzabot@example.com',
|
29
|
+
imageUrl: 'https://goo.gl/aeDtrS' }
|
30
|
+
sections = [{ keyValue: { topLabel: 'Order No.', content: '12345' } },
|
31
|
+
{ keyValue: { topLabel: 'Status', content: 'In Delivery' } }]
|
32
|
+
|
33
|
+
sender.card(header, sections)
|
34
|
+
```
|
35
|
+
|
21
36
|
### How to get Webhook URL
|
22
37
|
1. Open channel to which you want to send messages
|
23
38
|
2. Click on the channel name in top bar and select 'Configure webhooks'
|
@@ -26,11 +41,18 @@ sender.simple 'text'
|
|
26
41
|
|
27
42
|
Details: [Setting up an incoming webhook](https://developers.google.com/hangouts/chat/how-tos/webhooks)
|
28
43
|
|
44
|
+
## Contributing
|
45
|
+
Please feel free to contribute any changes, that you want too see in this gem.
|
46
|
+
Feature requests are also accepted.
|
47
|
+
|
48
|
+
Before Pull Request submitting please check
|
49
|
+
* Changed or added code has tests and YARD documentation
|
50
|
+
* All tests are pass
|
51
|
+
* `rubocop` doesn't report any offenses
|
29
52
|
|
30
|
-
##
|
31
|
-
|
53
|
+
## Tests
|
54
|
+
All tests are use usual Minitest `assert` syntax.
|
55
|
+
To run tests execute `rake tests`.
|
32
56
|
|
33
|
-
##
|
34
|
-
|
35
|
-
* Support [Card messages](https://developers.google.com/hangouts/chat/reference/message-formats/cards)
|
36
|
-
* README badges etc
|
57
|
+
## Changelog
|
58
|
+
Changelog is available [here](CHANGELOG.md).
|
data/lib/hangouts_chat.rb
CHANGED
@@ -24,6 +24,16 @@ module HangoutsChat
|
|
24
24
|
send_request(payload)
|
25
25
|
end
|
26
26
|
|
27
|
+
# Sends Card Message
|
28
|
+
# @since 0.0.4
|
29
|
+
# @param header [Hash] card header content
|
30
|
+
# @param sections [Array<Hash>] card widgets array
|
31
|
+
# @return [Net::HTTPResponse] response object
|
32
|
+
def card(header, sections)
|
33
|
+
payload = { cards: [header: header, sections: sections] }
|
34
|
+
send_request(payload)
|
35
|
+
end
|
36
|
+
|
27
37
|
private
|
28
38
|
|
29
39
|
# Sends payload and check response
|
data/test/hangouts_chat_test.rb
CHANGED
@@ -24,12 +24,26 @@ class HangoutsChatTest < Minitest::Test
|
|
24
24
|
{ text: message }.to_json
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_card_message_request
|
28
|
+
stub_request(:any, /chat\.googleapis\.com/).to_return(status: 200)
|
29
|
+
header = { title: 'Pizza Bot Customer Support',
|
30
|
+
subtitle: 'pizzabot@example.com',
|
31
|
+
imageUrl: 'https://goo.gl/aeDtrS' }
|
32
|
+
sections = [{ keyValue: { topLabel: 'Order No.', content: '12345' } },
|
33
|
+
{ keyValue: { topLabel: 'Status', content: 'In Delivery' } }]
|
34
|
+
|
35
|
+
@sender.card(header, sections)
|
36
|
+
|
37
|
+
assert_requested :post, @webhook_url, times: 1, body:
|
38
|
+
{ cards: [header: header, sections: sections] }.to_json
|
39
|
+
end
|
40
|
+
|
27
41
|
def test_api_error_exception_message
|
28
42
|
stub_request(:any, /chat\.googleapis\.com/)
|
29
43
|
.to_return(status: [403, 'Forbidden'], body: 'Response body')
|
30
44
|
|
31
45
|
exception = assert_raises HangoutsChat::Sender::APIError do
|
32
|
-
@sender.simple('
|
46
|
+
@sender.simple('Exception test')
|
33
47
|
end
|
34
48
|
assert_match(/^HTTP 403 Forbidden$/, exception.message)
|
35
49
|
assert_match(/^Body:\nResponse body$/, exception.message)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enzinia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|