google-hangout-webhook 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 85342443ed01bd0c54548359048667e8c1d8145e60e97cb41f204e80cae95043
4
+ data.tar.gz: 2c9a0360b9d6c118506481f09d785181abec2905f5a7556b0822a80695faa297
5
+ SHA512:
6
+ metadata.gz: 2cce7864122a598a2243b1319c724ab5d79351d42f96ced7d24328fe57477772494134c570d79668884639d99d7dee47b75717a667643a8ac8330d3193f527cb
7
+ data.tar.gz: 98bec277e4d9b21db70d5842ce2053da145d563b8abbcfd54ca5366f51cfcaaaf267630146f471b58ff12e2f0a1f4d10cbca9de50740539442c4d7508290f7b6
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ /.idea
14
+ /google-hangout-webhook-*
15
+ /Gemfile.lock
16
+ /hangout.yml
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ### Version - 0.0.1
4
+
5
+ * Specify yml configure file
6
+ * Setup pre message (if needed)
7
+ * Send message to google hangout
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in google-hangout-webhook.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Saimon Lovell
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,101 @@
1
+ # Google Hangout Webhook
2
+
3
+ This gem allows you to use google webhook to send messages.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'google-hangout-webhook'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install google-hangout-webhook
20
+
21
+ ## Configuration
22
+
23
+ You will have to create a webhook first.
24
+ To learn how to create a webhook please visit here
25
+ [Incoming webhooks](https://www.youtube.com/watch?time_continue=1&v=ThKvlgnLyDk).
26
+ Once you have created a webhook take the **name** of the webhook and use it as
27
+ **channel** name.
28
+
29
+ If you are using Rails then run the rake task
30
+ `bundle exec rake google_hangout:setup` with will create all the necessary files
31
+ below.
32
+
33
+ Create a yml configuration file (if you have not used the rake task above) that
34
+ will have all the necessary data which you should put in your **.gitignore** file.
35
+ Lets assume you create a file called **google-hangout.yml** in **config** folder.
36
+ Now the file should look similar to this below:
37
+
38
+ ```yml
39
+ ---
40
+ channels:
41
+ sync:
42
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
43
+
44
+ import:
45
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
46
+
47
+ export:
48
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
49
+ ```
50
+
51
+ The channels are just a label for your convenience. They can be anything and
52
+ does not have to match the webhook name at all. All channel names must be lower
53
+ case (if possible) and should not have any spaces or special characters in them.
54
+ Think of it as you are declaring a variable. You can use any webhook at any
55
+ time using the channels.
56
+
57
+ ## Rails
58
+
59
+ For Rails create a file in the **initializers** folder and put the following.
60
+
61
+ ```ruby
62
+ GoogleHangout = Google::Hangout::Webhook::Message.new('config/google-hangout.yml')
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ First create an instance of the class and pass the location where you have your
68
+ hangout Configuration (as mentioned above). Then just broadcast your message
69
+ using a channel name.
70
+
71
+ ```ruby
72
+ # Skip first line if you are using Rails
73
+ GoogleHangout = Google::Hangout::Webhook::Message.new('config/google-hangout.yml')
74
+
75
+ GoogleHangout.broadcast(:sync, 'Something went wrong with sync ID....')
76
+ GoogleHangout.broadcast(:import, 'Failed to import file...')
77
+ GoogleHangout.broadcast(:export, 'Export timed out for report ID...')
78
+ ```
79
+
80
+ The method **broadcast** takes two parameters.
81
+ First is the channel and second is the text message.
82
+ ```ruby
83
+ GoogleHangout.broadcast(<channel>, <message>)
84
+ ```
85
+
86
+ For more information regarding how you can style the text please visit:
87
+ [Simple Text Messages](https://developers.google.com/hangouts/chat/reference/message-formats/basic)
88
+
89
+
90
+ #### Pre-Message
91
+
92
+ If you want to setup a pre-message that will prepend to all message string then after creating
93
+ instance of the class just set the **pre_message** as shown below.
94
+
95
+ ```ruby
96
+ GoogleHangout.pre_message = ['*', Rails.env.capitalize, "*\n"].join
97
+ ```
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "google/hangout/webhook"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'google/hangout/webhook/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'google-hangout-webhook'
9
+ spec.version = Google::Hangout::Webhook::VERSION
10
+ spec.authors = ['Saimon Lovell']
11
+ spec.email = ['staysynchronize@gmail.com']
12
+
13
+ spec.summary = %q{Google Hangout Webhook}
14
+ spec.description = %q{This gem allows you ruby application or rails to send webhook messages to Google hangout.}
15
+ spec.homepage = 'https://gitlab.com/slovell/google-hangout-webhook'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
+
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['source_code_uri'] = 'https://gitlab.com/slovell/google-hangout-webhook'
25
+ spec.metadata['changelog_uri'] = 'https://gitlab.com/slovell/google-hangout-webhook/blob/master/CHANGELOG.md'
26
+ else
27
+ raise 'RubyGems 2.1 or newer is required to protect against public gem pushes.'
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.add_dependency 'rest-client', '~> 2.0'
40
+
41
+ spec.add_development_dependency 'pry', '~> 0.1'
42
+ spec.add_development_dependency 'bundler', '~> 2.0'
43
+ spec.add_development_dependency 'rake', '~> 10.0'
44
+ spec.add_development_dependency 'rspec', '~> 3.0'
45
+ end
@@ -0,0 +1,10 @@
1
+ ---
2
+ channels:
3
+ sync:
4
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
5
+
6
+ import:
7
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
8
+
9
+ export:
10
+ url: 'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....'
@@ -0,0 +1,2 @@
1
+ path = File.expand_path(__dir__)
2
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| import f }
@@ -0,0 +1,12 @@
1
+ require 'rails'
2
+
3
+ module Google::Hangout::Webhook
4
+ class Railtie < Rails::Railtie
5
+ railtie_name 'google-hangout-webhook'
6
+
7
+ rake_tasks do
8
+ path = File.expand_path(__dir__)
9
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| load f }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ namespace :google_hangout do
2
+ desc 'Setup an example config yaml file for google hangout webhook'
3
+ task :setup do
4
+ puts ''
5
+ puts 'Setting up google hangout webhooks...'
6
+ puts ''
7
+ config_file = Rails.root.join('config/google-hangout.yml').to_s
8
+ initializer_file = Rails.root.join('config/initializers/google_hangout_webhook.rb').to_s
9
+
10
+ if File.exist?(config_file)
11
+ puts 'Config file already exist! Skipping'
12
+ else
13
+ puts 'Creating [config/google-hangout.yml] file.'
14
+ File.open(config_file, 'w') do |file|
15
+ file.write('---')
16
+ file.write("\n")
17
+ file.write('channels:')
18
+ file.write("\n")
19
+ file.write(' cheannel_name:')
20
+ file.write("\n")
21
+ file.write(' url: \'https://chat.googleapis.com/v1/spaces/...../messages?key=...&token=....\'')
22
+ file.write("\n")
23
+ end
24
+ end
25
+
26
+ if File.exist?(initializer_file)
27
+ puts 'setup file already exist in initializers. Skipping'
28
+ else
29
+ puts 'Creating [config/initializers/google_hangout_webhook.rb] file.'
30
+ File.open(initializer_file, 'w') do |file|
31
+ file.write('GoogleHangout = Google::Hangout::Webhook::Message.new(\'config/google-hangout.yml\')')
32
+ file.write("\n")
33
+ file.write('GoogleHangout.pre_message = [\'*\', Rails.env.upcase, "*\n"].join')
34
+ file.write("\n")
35
+ end
36
+ end
37
+
38
+ puts ''
39
+ puts 'Process complete.'
40
+ puts ''
41
+ true
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'google/hangout/webhook/version'
4
+ require 'google/hangout/railtie.rb' if defined?(Rails)
5
+
6
+ require 'rest-client'
7
+ require 'yaml'
8
+ require 'json'
9
+
10
+
11
+ module Google
12
+ module Hangout
13
+ module Webhook
14
+ class Message
15
+ attr_accessor :config_path, :settings, :pre_message, :response
16
+
17
+ def initialize(config_path)
18
+ self.config_path = config_path
19
+ self.settings = YAML.load_file(config_path)
20
+ self.pre_message = ''
21
+ end
22
+
23
+ def reload
24
+ self.settings = YAML.load_file(config_path)
25
+ end
26
+
27
+ def broadcast(channel, message)
28
+ raise "Channel name #{channel.to_s} not found" if settings['channels'][channel.to_s].nil?
29
+ raise "Channel url is missing" if settings['channels'][channel.to_s]['url'].nil?
30
+
31
+ self.response = RestClient.post(
32
+ settings['channels'][channel.to_s]['url'],
33
+ { text: [pre_message, message].join }.to_json,
34
+ { content_type: :json, accept: :json }
35
+ )
36
+ rescue StandardError => e
37
+ error = "Google Hangout Error: #{e.message}"
38
+ puts error
39
+ raise error
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Google
4
+ module Hangout
5
+ module Webhook
6
+ VERSION = '0.0.1'
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-hangout-webhook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Saimon Lovell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: This gem allows you ruby application or rails to send webhook messages
84
+ to Google hangout.
85
+ email:
86
+ - staysynchronize@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - google-hangout-webhook.gemspec
101
+ - hangout.example.yml
102
+ - lib/google/hangout/Rakefile
103
+ - lib/google/hangout/railtie.rb
104
+ - lib/google/hangout/tasks/google_hangout.rake
105
+ - lib/google/hangout/webhook.rb
106
+ - lib/google/hangout/webhook/version.rb
107
+ homepage: https://gitlab.com/slovell/google-hangout-webhook
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ homepage_uri: https://gitlab.com/slovell/google-hangout-webhook
113
+ source_code_uri: https://gitlab.com/slovell/google-hangout-webhook
114
+ changelog_uri: https://gitlab.com/slovell/google-hangout-webhook/blob/master/CHANGELOG.md
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubygems_version: 3.0.3
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Google Hangout Webhook
134
+ test_files: []