hangouts-chat 0.0.3 → 0.0.4

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
2
  SHA256:
3
- metadata.gz: d6ed28c19b0253bb33ebc13670e57e1343330bc30da8af2640d999e47de6a362
4
- data.tar.gz: 220f23a56aff96c3071ad412c8af9d3fd3e78428b28d4369d633039454f70899
3
+ metadata.gz: a8912faeb8ba44836f727d6808f70e52d5104b217a9f07c76c151b47cd15fd6c
4
+ data.tar.gz: bc62156c4dfd29a2f850ce00ca85b296a362f58d5bac8ee72cd66ae18b52851c
5
5
  SHA512:
6
- metadata.gz: d4eda290a5d04e9a226c58ed144cb29804a9effe0047f3d31446561640b4502b405221e5b7456b5c16e309c269e4cd81eebb0cec02c84f4e8e8965a0874aa811
7
- data.tar.gz: bb649deb7a85caf301d4aed009dcb3aac3cbd24b452172f22fafffacfaa7936b453c59fd71751835dad1cb182352415b4f1ac0a600b7eabd81017e43a92e0823
6
+ metadata.gz: 25bbbd87c104205605c1ff8a4e41a56e9103d30815b0e028b837a3bc4e6a63bb0851d23efdd54c47103fde804a406206c608e81cc6586e78e7ffd1d045573e87
7
+ data.tar.gz: c608f5466ad57ae5cb72f52c91dccadf225caa77d44ee05ad10885684329a78bdf44ba1c136625850c5861cb813edbe3993ee92e88c5964c79034977d03d6eb1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.4
4
+ * Added Card Messages support
5
+
6
+ ## 0.0.3
7
+ * Added YARD documentation
8
+ * Added HangoutsChat::Sender::APIError exception for unsuccessful responses
9
+
3
10
  ## 0.0.2
4
11
  * Added tests
5
12
  * Improved appearance
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
- ## Comments
31
- For now supported only [Simple Text Messages](https://developers.google.com/hangouts/chat/reference/message-formats/basic)
53
+ ## Tests
54
+ All tests are use usual Minitest `assert` syntax.
55
+ To run tests execute `rake tests`.
32
56
 
33
- ## TODO
34
- * Errors reports
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).
@@ -1,4 +1,4 @@
1
1
  module HangoutsChat
2
2
  # Library version
3
- VERSION = '0.0.3'.freeze
3
+ VERSION = '0.0.4'.freeze
4
4
  end
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
@@ -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('Test exception')
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.3
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-25 00:00:00.000000000 Z
11
+ date: 2018-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop