bearychat 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +10 -0
- data/bearychat.gemspec +27 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/bearychat.rb +9 -0
- data/lib/bearychat/capistrano.rb +1 -0
- data/lib/bearychat/capistrano/tasks/bearychat.rake +64 -0
- data/lib/bearychat/incoming.rb +47 -0
- data/lib/bearychat/version.rb +3 -0
- data/test/bearychat_test.rb +19 -0
- data/test/test_helper.rb +4 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2809571a5483b3f2e75573bf7ae008e929391dbf
|
4
|
+
data.tar.gz: 82041144cc71686307b05335640a78d5cd274ba0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: baee79ed490fc5c368e193903956019b59178f94ba7c61ad01c594ea111acbd630cc2b04976bf600315aeb5e9e4a03d409591d25460fb7a06baab60b66431ab9
|
7
|
+
data.tar.gz: cfd6f0d347e1b14f46e32b738d07256967de54fe9fe0e14708bef8cf45367e0e918a3d0550d594af11df9bcbbf6f55db010fd1ab5e75d9eaef9e98897ebe7520
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 pokka
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
## bearychat-rb
|
2
|
+
|
3
|
+
Simple ruby library to interact with [Bearychat](https://bearychat.com/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```
|
10
|
+
gem 'bearychat'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bearychat
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Common
|
24
|
+
|
25
|
+
Check bearychat [incoming API](https://github.com/bearyinnovative/bearychat-tutorial/blob/master/robots/incoming.md)
|
26
|
+
|
27
|
+
```
|
28
|
+
require 'bearychat'
|
29
|
+
incoming = Bearychat.incoming('hook_uri')
|
30
|
+
incoming.text = "Willllll"
|
31
|
+
incoming.markdown = true
|
32
|
+
incoming.attachments << {"title"=>"Professor John Frink=>", "text"=>"Numbers are fun. ", "color"=>"#ffa500", "images"=>[{"url"=>"http://img3.douban.com/icon/ul15067564-30.jpg"}]}
|
33
|
+
|
34
|
+
incoming.send
|
35
|
+
```
|
36
|
+
|
37
|
+
### Capistrano3(git)
|
38
|
+
|
39
|
+
```
|
40
|
+
require 'bearychat/capistrano'
|
41
|
+
|
42
|
+
set :bearychat_hook, your_bearychat_hook_uri
|
43
|
+
```
|
44
|
+
|
45
|
+
# options
|
46
|
+
```
|
47
|
+
#default: true
|
48
|
+
set :bearychat_enabled
|
49
|
+
|
50
|
+
#default: #E51C23
|
51
|
+
set :bearychat_failed_color
|
52
|
+
|
53
|
+
#default: #259B24
|
54
|
+
set :bearychat_successed_color
|
55
|
+
|
56
|
+
#default: #FFC107
|
57
|
+
set :bearychat_starting_color
|
58
|
+
```
|
59
|
+
|
60
|
+
## TODO
|
61
|
+
|
62
|
+
* show git revision in starting
|
63
|
+
* Capistrano2 support
|
64
|
+
* not only Capistrano
|
65
|
+
* test
|
66
|
+
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
71
|
+
|
data/Rakefile
ADDED
data/bearychat.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'bearychat/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "bearychat"
|
7
|
+
spec.version = Bearychat::VERSION
|
8
|
+
spec.authors = ["pokka"]
|
9
|
+
spec.email = ["ifunafu@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Simple ruby library to interact with Bearychat}
|
12
|
+
spec.description = %q{Simple ruby library to interact with Bearychat}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty", "~> 0.13.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bearychat"
|
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
|
data/bin/setup
ADDED
data/lib/bearychat.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('capistrano/tasks/bearychat.rake', File.dirname(__FILE__))
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'bearychat'
|
2
|
+
|
3
|
+
namespace :bearychat do
|
4
|
+
task :notify_deploy_started do
|
5
|
+
attachments = [{title: "#{default_title('is deploying')}" , color: starting_color }]
|
6
|
+
send_message nil, attachments
|
7
|
+
end
|
8
|
+
|
9
|
+
task :notify_deploy_finished do
|
10
|
+
attachments = [{title: "#{default_title('finished deploying')}", color: successed_color }]
|
11
|
+
send_message nil, attachments
|
12
|
+
end
|
13
|
+
|
14
|
+
task :notify_deploy_fail do
|
15
|
+
attachments = [{title: "#{default_title('cancelled deployment of')}", color: failed_color }]
|
16
|
+
send_message nil, attachments
|
17
|
+
end
|
18
|
+
|
19
|
+
before 'deploy:starting', 'bearychat:notify_deploy_started'
|
20
|
+
after 'deploy:finishing', 'bearychat:notify_deploy_finished'
|
21
|
+
if Rake::Task.task_defined? 'deploy:failed'
|
22
|
+
after 'deploy:failed', 'bearychat:notify_deploy_fail'
|
23
|
+
end
|
24
|
+
|
25
|
+
def git_user
|
26
|
+
`git config user.name`.gsub "\n", ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def failed_color
|
30
|
+
fetch(:bearychat_failed_color, "#E51C23")
|
31
|
+
end
|
32
|
+
|
33
|
+
def successed_color
|
34
|
+
fetch(:bearychat_successed_color, "#259B24")
|
35
|
+
end
|
36
|
+
|
37
|
+
def starting_color
|
38
|
+
fetch(:bearychat_starting_color, "#FFC107")
|
39
|
+
end
|
40
|
+
|
41
|
+
def default_title(action)
|
42
|
+
"#{git_user} #{action} #{deployment_info} to #{stage_string} @ #{Time.now}."
|
43
|
+
end
|
44
|
+
|
45
|
+
def deployment_info
|
46
|
+
"#{fetch(:application)}/#{fetch(:branch)} (#{fetch(:current_revision)})"
|
47
|
+
end
|
48
|
+
|
49
|
+
def stage_string
|
50
|
+
fetch(:stage)
|
51
|
+
end
|
52
|
+
|
53
|
+
def send_message(text, attachments)
|
54
|
+
return unless enabled?
|
55
|
+
return unless bearychat_hook = fetch(:bearychat_hook)
|
56
|
+
text ||= "#{fetch(:application)} deployment:"
|
57
|
+
Bearychat.incoming(bearychat_hook).send { |i| i.text = text;i.attachments += attachments }
|
58
|
+
end
|
59
|
+
|
60
|
+
def enabled?
|
61
|
+
fetch(:bearychat_enabled, true)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Bearychat
|
5
|
+
class Incoming < OpenStruct
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
DEFAULT_PARAMS = {
|
9
|
+
text: "text, this field may accept markdown",
|
10
|
+
markdown: false,
|
11
|
+
channel: "",
|
12
|
+
attachments: []
|
13
|
+
}
|
14
|
+
|
15
|
+
attr_reader :hook
|
16
|
+
|
17
|
+
def initialize(hook, info={})
|
18
|
+
@hook = hook
|
19
|
+
super(DEFAULT_PARAMS.merge(info))
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset(info)
|
23
|
+
info.each { |key, value| self[key] = value }
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def send
|
28
|
+
if block_given?
|
29
|
+
yield self
|
30
|
+
send()
|
31
|
+
else
|
32
|
+
self.class.post(hook, body: { payload: as_json })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def switch(channel)
|
37
|
+
self.channel = channel
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def as_json
|
43
|
+
to_h.to_json
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BearychatTest < Minitest::Test
|
4
|
+
MOCK_HOOK_URI = 'https://hook.bearychat.com/mock/incoming/hook'
|
5
|
+
|
6
|
+
def test_that_it_has_a_version_number
|
7
|
+
refute_nil ::Bearychat::VERSION
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_incoming_build_by_module
|
11
|
+
assert_equal true, ::Bearychat.incoming(MOCK_HOOK_URI).is_a?(::Bearychat::Incoming)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_incoming_send
|
15
|
+
incoming_stub = stub_request(:post, MOCK_HOOK_URI).with(body: hash_including(:payload))
|
16
|
+
::Bearychat.incoming(MOCK_HOOK_URI).send
|
17
|
+
assert_requested(incoming_stub)
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bearychat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pokka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Simple ruby library to interact with Bearychat
|
84
|
+
email:
|
85
|
+
- ifunafu@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bearychat.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/bearychat.rb
|
101
|
+
- lib/bearychat/capistrano.rb
|
102
|
+
- lib/bearychat/capistrano/tasks/bearychat.rake
|
103
|
+
- lib/bearychat/incoming.rb
|
104
|
+
- lib/bearychat/version.rb
|
105
|
+
- test/bearychat_test.rb
|
106
|
+
- test/test_helper.rb
|
107
|
+
homepage: ''
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.2.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Simple ruby library to interact with Bearychat
|
131
|
+
test_files: []
|