hangouts-chat 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28b2e028adbcf7dbe7ca389840a12c831d78b489dbc05ab5ffba189ffd735022
4
- data.tar.gz: ac1ad9b4d55696001f3eb3f19c5654218d6dd420c350b819245defaaa086fbc8
3
+ metadata.gz: d6ed28c19b0253bb33ebc13670e57e1343330bc30da8af2640d999e47de6a362
4
+ data.tar.gz: 220f23a56aff96c3071ad412c8af9d3fd3e78428b28d4369d633039454f70899
5
5
  SHA512:
6
- metadata.gz: 1fd3985550cfb69b9cc75e5c9d3b533eec64c7844823ffc5249f9ef0894a16cbb3522532780489394c13919c04424bbc690c68bf856d2d3d26f8559f1bd10bab
7
- data.tar.gz: c3757efe0a005448322390d6b8275485f6fbb4a87a06ec4499dbe782360f792d0561f4332bcca1bc27db2c12f01b2b28d6101ff1ae8c73667199f5ee327810df
6
+ metadata.gz: d4eda290a5d04e9a226c58ed144cb29804a9effe0047f3d31446561640b4502b405221e5b7456b5c16e309c269e4cd81eebb0cec02c84f4e8e8965a0874aa811
7
+ data.tar.gz: bb649deb7a85caf301d4aed009dcb3aac3cbd24b452172f22fafffacfaa7936b453c59fd71751835dad1cb182352415b4f1ac0a600b7eabd81017e43a92e0823
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.0.2
4
+ * Added tests
5
+ * Improved appearance
6
+ * Added and performed rubocop code analyze
7
+
8
+ ## 0.0.1
9
+ * Initial version with Hangouts Chat simple text messages support
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 enzinia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Hangouts Chat gem
2
+ Send messages to [Hangouts Chat](https://gsuite.google.com/products/chat/) rooms using incoming webhooks.
3
+
4
+ ## Installation
5
+ ```
6
+ $ gem install hangouts-chat
7
+ ```
8
+
9
+ or add to your Gemfile
10
+
11
+ ```ruby
12
+ require 'hangouts-chat'
13
+ ```
14
+
15
+ ## Usage
16
+ ```ruby
17
+ sender = HangoutsChat::Sender.new 'webhook_URL'
18
+ sender.simple 'text'
19
+ ```
20
+
21
+ ### How to get Webhook URL
22
+ 1. Open channel to which you want to send messages
23
+ 2. Click on the channel name in top bar and select 'Configure webhooks'
24
+ 3. Click on 'Add webhook' and fill name for bot, that will be display messages
25
+ 4. Click on 'Save' and copy 'Webhook URL'
26
+
27
+ Details: [Setting up an incoming webhook](https://developers.google.com/hangouts/chat/how-tos/webhooks)
28
+
29
+
30
+ ## Comments
31
+ For now supported only [Simple Text Messages](https://developers.google.com/hangouts/chat/reference/message-formats/basic)
32
+
33
+ ## TODO
34
+ * Errors reports
35
+ * Support [Card messages](https://developers.google.com/hangouts/chat/reference/message-formats/cards)
36
+ * README badges etc
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ t.test_files = FileList['test/**/*_test.rb']
6
+ end
7
+
8
+ desc 'Run tests'
9
+ task default: :test
data/lib/hangouts_chat.rb CHANGED
@@ -1,16 +1,39 @@
1
1
  require_relative 'hangouts_chat/version'
2
2
  require_relative 'hangouts_chat/http'
3
+ require_relative 'hangouts_chat/exceptions'
3
4
 
5
+ # Main namespace
4
6
  module HangoutsChat
7
+ # Provide methods to send messages to Hangouts Chat rooms using webhooks API
5
8
  class Sender
9
+ # @return [String] Webhook URL, given on initialization
10
+ attr_reader :url
11
+
12
+ # Creates Sender object
13
+ # @param webhook_url [String] URL for incoming webhook
6
14
  def initialize(webhook_url)
7
15
  @url = webhook_url
8
16
  @http = HTTP.new(@url)
9
17
  end
10
18
 
19
+ # Sends Simple Text Message
20
+ # @param text [String] text to send to room
21
+ # @return [Net::HTTPResponse] response object
11
22
  def simple(text)
12
23
  payload = { text: text }
13
- @http.post payload
24
+ send_request(payload)
25
+ end
26
+
27
+ private
28
+
29
+ # Sends payload and check response
30
+ # @param payload [Hash] data to send by POST
31
+ # @return [Net::HTTPResponse] response object
32
+ # @raise [APIError] if got unsuccessful response
33
+ def send_request(payload)
34
+ response = @http.post payload
35
+ raise APIError, response unless response.is_a?(Net::HTTPSuccess)
36
+ response
14
37
  end
15
38
  end
16
39
  end
@@ -0,0 +1,16 @@
1
+ require 'net/http/response'
2
+
3
+ module HangoutsChat
4
+ class Sender
5
+ # Unsuccessful API respond exception
6
+ class APIError < StandardError
7
+ # Creates exception object with generated message
8
+ # @param response [Net::HTTPResponse] API response
9
+ def initialize(response)
10
+ msg = "HTTP #{response.code} #{response.msg}\n"
11
+ msg += "Body:\n#{response.body}"
12
+ super(msg)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,13 +3,22 @@ require 'json'
3
3
 
4
4
  module HangoutsChat
5
5
  class Sender
6
+ # Unsuccessful respond exception
7
+ class APIError < StandardError; end
8
+
9
+ # Service class to send HTTP POST requests
6
10
  class HTTP
11
+ # Creates HTTP::Post object with JSON content type
12
+ # @param url [String] URL to send request
7
13
  def initialize(url)
8
14
  @uri = URI(url)
9
15
  @req = Net::HTTP::Post.new(@uri)
10
16
  @req['Content-Type'] = 'application/json'
11
17
  end
12
18
 
19
+ # Sends HTTP POST request
20
+ # @param payload [String] request body to send
21
+ # @return [Net::HTTPResponse] response object
13
22
  def post(payload)
14
23
  @req.body = payload.to_json
15
24
 
@@ -1,3 +1,4 @@
1
1
  module HangoutsChat
2
- VERSION = '0.0.2'.freeze
2
+ # Library version
3
+ VERSION = '0.0.3'.freeze
3
4
  end
File without changes
@@ -23,4 +23,15 @@ class HangoutsChatTest < Minitest::Test
23
23
  assert_requested :post, @webhook_url, times: 1, body:
24
24
  { text: message }.to_json
25
25
  end
26
+
27
+ def test_api_error_exception_message
28
+ stub_request(:any, /chat\.googleapis\.com/)
29
+ .to_return(status: [403, 'Forbidden'], body: 'Response body')
30
+
31
+ exception = assert_raises HangoutsChat::Sender::APIError do
32
+ @sender.simple('Test exception')
33
+ end
34
+ assert_match(/^HTTP 403 Forbidden$/, exception.message)
35
+ assert_match(/^Body:\nResponse body$/, exception.message)
36
+ end
26
37
  end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'minitest/autorun'
2
2
  require 'webmock/minitest'
3
- require 'hangouts-chat'
3
+ require 'hangouts_chat'
4
4
 
5
5
  WebMock.disable_net_connect!(net_http_connect_on_start: true)
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.2
4
+ version: 0.0.3
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-21 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -38,18 +38,42 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3'
41
- description: |-
42
- Send messages to G Suite Hangouts Chat rooms using
43
- incoming webhooks and Net::HTTP::Post
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ - - ">"
49
+ - !ruby/object:Gem::Version
50
+ version: 0.9.11
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.9'
58
+ - - ">"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.9.11
61
+ description: Send messages to G Suite Hangouts Chat rooms using incoming webhooks
62
+ and Net::HTTP::Post
44
63
  email: vkukovskij@gmail.com
45
64
  executables: []
46
65
  extensions: []
47
66
  extra_rdoc_files: []
48
67
  files:
68
+ - CHANGELOG.md
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
49
72
  - lib/hangouts_chat.rb
73
+ - lib/hangouts_chat/exceptions.rb
50
74
  - lib/hangouts_chat/http.rb
51
75
  - lib/hangouts_chat/version.rb
52
- - test/hangouts-chat/http_test.rb
76
+ - test/hangouts_chat/http_test.rb
53
77
  - test/hangouts_chat_test.rb
54
78
  - test/test_helper.rb
55
79
  homepage: https://github.com/enzinia/hangouts-chat
@@ -77,6 +101,6 @@ signing_key:
77
101
  specification_version: 4
78
102
  summary: Library for sending messages to Hangouts Chat rooms
79
103
  test_files:
80
- - test/hangouts-chat/http_test.rb
104
+ - test/hangouts_chat/http_test.rb
81
105
  - test/hangouts_chat_test.rb
82
106
  - test/test_helper.rb