glip-poster 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +22 -0
- data/README.md +123 -0
- data/Rakefile +19 -0
- data/glip-poster.gemspec +22 -0
- data/lib/glip-poster.rb +1 -0
- data/lib/glip-poster/poster.rb +46 -0
- data/test/test_base.rb +8 -0
- data/test/test_setup.rb +42 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b72ca65835c0688d71743550c8109b05598e1359
|
4
|
+
data.tar.gz: 8ea536b2c136393622648fb818c18536b4e7fba1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85189e54802e9e589c1ace75df7557eedf27f0d85af38b6fbfea1ecafbf5a4fd2a8f7ea6e6f1f41388e8e25cbff6e1a15d5eae2df262f0877a4cdad0e77ce8f3
|
7
|
+
data.tar.gz: 599b917ea7a74090050e4f3f161fb41b80f648ab3f6b891a1c1c55118a7d44d4d6711da74551ee254bb1bcc87081d1f569503124cf5dd93801ccc64eb4811609
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coveralls (0.8.10)
|
5
|
+
json (~> 1.8)
|
6
|
+
rest-client (>= 1.6.8, < 2)
|
7
|
+
simplecov (~> 0.11.0)
|
8
|
+
term-ansicolor (~> 1.3)
|
9
|
+
thor (~> 0.19.1)
|
10
|
+
tins (~> 1.6.0)
|
11
|
+
docile (1.1.5)
|
12
|
+
domain_name (0.5.25)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
faraday (0.9.2)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
faraday_middleware (0.10.0)
|
17
|
+
faraday (>= 0.7.4, < 0.10)
|
18
|
+
http-cookie (1.0.2)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
json (1.8.3)
|
21
|
+
logger (1.2.8)
|
22
|
+
metaclass (0.0.4)
|
23
|
+
mime-types (2.99)
|
24
|
+
mocha (1.1.0)
|
25
|
+
metaclass (~> 0.0.1)
|
26
|
+
multipart-post (2.0.0)
|
27
|
+
netrc (0.11.0)
|
28
|
+
power_assert (0.2.7)
|
29
|
+
rake (10.5.0)
|
30
|
+
rest-client (1.8.0)
|
31
|
+
http-cookie (>= 1.0.2, < 2.0)
|
32
|
+
mime-types (>= 1.16, < 3.0)
|
33
|
+
netrc (~> 0.7)
|
34
|
+
simplecov (0.11.1)
|
35
|
+
docile (~> 1.1.0)
|
36
|
+
json (~> 1.8)
|
37
|
+
simplecov-html (~> 0.10.0)
|
38
|
+
simplecov-html (0.10.0)
|
39
|
+
term-ansicolor (1.3.2)
|
40
|
+
tins (~> 1.0)
|
41
|
+
test-unit (3.1.7)
|
42
|
+
power_assert
|
43
|
+
thor (0.19.1)
|
44
|
+
tins (1.6.0)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.7.1)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
coveralls
|
54
|
+
faraday (~> 0.9.0)
|
55
|
+
faraday_middleware
|
56
|
+
logger
|
57
|
+
mocha
|
58
|
+
rake
|
59
|
+
simplecov
|
60
|
+
test-unit
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.11.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 John Wang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
Glip Poster
|
2
|
+
========================
|
3
|
+
|
4
|
+
[![Gem Version][gem-version-svg]][gem-version-link]
|
5
|
+
[![Build Status][build-status-svg]][build-status-link]
|
6
|
+
[![Coverage Status][coverage-status-svg]][coverage-status-link]
|
7
|
+
[![Dependency Status][dependency-status-svg]][dependency-status-link]
|
8
|
+
[![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
|
9
|
+
[![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link]
|
10
|
+
[![Downloads][downloads-svg]][downloads-link]
|
11
|
+
[![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
|
12
|
+
[![License][license-svg]][license-link]
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
### Via Bundler
|
17
|
+
|
18
|
+
Add 'glip-poster' to Gemfile and then run `bundle`:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
$ echo "gem 'glip-poster'" >> Gemfile
|
22
|
+
$ bundle
|
23
|
+
```
|
24
|
+
|
25
|
+
### Via RubyGems
|
26
|
+
|
27
|
+
```sh
|
28
|
+
$ gem install glip-poster
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
First you have to initialize your poster and then you can use `send_message` to send your message.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
poster = Glip::Poster.new(YOUR_WEBHOOK_URL)
|
37
|
+
poster.send_message('Hello World!') # Faraday::Response
|
38
|
+
```
|
39
|
+
|
40
|
+
You can send text in Markdown:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
poster = Glip::Poster.new(YOUR_WEBHOOK_URL)
|
44
|
+
poster.send_message('* Location: [The Funky Buddha Lounge](http://www.thefunkybuddha.com)\n*Beer Advocate Rating: [99](http://tinyurl.com/psf4uzq)')
|
45
|
+
```
|
46
|
+
|
47
|
+
You can use an options array if you don't want to use the default settings.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
options => {
|
51
|
+
:icon": "http://example.com/icon.png",
|
52
|
+
:activity": "Activity Alert",
|
53
|
+
:title": "A New Incoming Message Has Been Received",
|
54
|
+
}
|
55
|
+
poster = Glip::Poster.new(YOUR_WEBHOOK_URL)
|
56
|
+
poster.send_message('Hello Beer!', options)
|
57
|
+
```
|
58
|
+
|
59
|
+
You can preset your options:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
poster = Glip::Poster.new(YOUR_WEBHOOK_URL)
|
63
|
+
poster.options[:icon] = 'http://example.com/icon.png'
|
64
|
+
poster.options = {:icon => 'http://example.com/icon.png'}
|
65
|
+
poster.send_message('Hello World!')
|
66
|
+
```
|
67
|
+
|
68
|
+
## Supported Ruby Versions
|
69
|
+
|
70
|
+
This library supports and is [tested against](https://travis-ci.org/grokify/glip-poster-ruby) the following Ruby implementations:
|
71
|
+
|
72
|
+
1. Ruby 2.3.0
|
73
|
+
2. Ruby 2.2.0
|
74
|
+
3. Ruby 2.1.0
|
75
|
+
4. Ruby 2.0.0
|
76
|
+
5. Ruby 1.9.3
|
77
|
+
6. [JRuby](http://jruby.org/)
|
78
|
+
7. [Rubinius](http://rubinius.com/)
|
79
|
+
|
80
|
+
## Releases
|
81
|
+
|
82
|
+
Releases with release notes are availabe on [GitHub releases](https://github.com/grokify/glip-poster/releases). Release notes include a high level description of the release as well as lists of non-breaking and breaking changes.
|
83
|
+
|
84
|
+
### Change Log
|
85
|
+
|
86
|
+
See [CHANGELOG.md](CHANGELOG.md)
|
87
|
+
|
88
|
+
## Links
|
89
|
+
|
90
|
+
Project Repo
|
91
|
+
|
92
|
+
* https://github.com/grokify/glip-poster-ruby
|
93
|
+
|
94
|
+
Glip
|
95
|
+
|
96
|
+
* https://glip.com
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it ( http://github.com/grokify/glip-poster-ruby/fork )
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create new Pull Request
|
105
|
+
|
106
|
+
[gem-version-svg]: https://badge.fury.io/rb/glip-poster.svg
|
107
|
+
[gem-version-link]: http://badge.fury.io/rb/glip-poster
|
108
|
+
[downloads-svg]: http://ruby-gem-downloads-badge.herokuapp.com/glip-poster
|
109
|
+
[downloads-link]: https://rubygems.org/gems/glip-poster
|
110
|
+
[build-status-svg]: https://api.travis-ci.org/grokify/glip-poster-ruby.svg?branch=master
|
111
|
+
[build-status-link]: https://travis-ci.org/grokify/glip-poster-ruby
|
112
|
+
[coverage-status-svg]: https://coveralls.io/repos/grokify/glip-poster-ruby/badge.svg?branch=master
|
113
|
+
[coverage-status-link]: https://coveralls.io/r/grokify/glip-poster-ruby?branch=master
|
114
|
+
[dependency-status-svg]: https://gemnasium.com/grokify/glip-poster-ruby.svg
|
115
|
+
[dependency-status-link]: https://gemnasium.com/grokify/glip-poster-ruby
|
116
|
+
[codeclimate-status-svg]: https://codeclimate.com/github/grokify/glip-poster-ruby/badges/gpa.svg
|
117
|
+
[codeclimate-status-link]: https://codeclimate.com/github/grokify/glip-poster-ruby
|
118
|
+
[scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/glip-poster-ruby/badges/quality-score.png?b=master
|
119
|
+
[scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/glip-poster-ruby/?branch=master
|
120
|
+
[docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
|
121
|
+
[docs-rubydoc-link]: http://www.rubydoc.info/gems/glip-poster/
|
122
|
+
[license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
|
123
|
+
[license-link]: https://github.com/grokify/glip-poster-ruby/blob/master/LICENSE.txt
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Test the library.'
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.pattern = 'test/**/test_*.rb'
|
11
|
+
t.verbose = false
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Generate YARD documentation.'
|
15
|
+
task :gendoc do
|
16
|
+
# puts 'yard doc generation disabled until JRuby build native extensions for redcarpet or yard removes the dependency.'
|
17
|
+
system 'yardoc'
|
18
|
+
system 'yard stats --list-undoc'
|
19
|
+
end
|
data/glip-poster.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = 'glip-poster'
|
2
|
+
lib_file = File.expand_path("../lib/#{lib}/poster.rb", __FILE__)
|
3
|
+
File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/
|
4
|
+
version = $1
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'glip-poster'
|
8
|
+
s.version = version
|
9
|
+
s.date = '2016-01-30'
|
10
|
+
s.summary = 'Glip Poster - Ruby SDK for post messages via Glip webhooks'
|
11
|
+
s.description = 'A Ruby SDK for post messages via Glip webhooks'
|
12
|
+
s.authors = ['John Wang']
|
13
|
+
s.email = 'johncwang@gmail.com'
|
14
|
+
s.homepage = 'https://github.com/grokify/'
|
15
|
+
s.licenses = ['MIT']
|
16
|
+
s.files = Dir['lib/**/**/*'] # + Dir['bin/*']
|
17
|
+
s.files += Dir['[A-Z]*'] + Dir['test/**/*']
|
18
|
+
# s.files.reject! { |fn| fn.include? "CVS" }
|
19
|
+
# s.required_ruby_version = '>= 1.8.7' # 1.8.7+ is tested
|
20
|
+
s.add_dependency 'faraday', '~> 0.9', '>= 0.9'
|
21
|
+
s.add_dependency 'faraday_middleware', '~> 0', '>= 0'
|
22
|
+
end
|
data/lib/glip-poster.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'glip-poster/poster'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Glip
|
5
|
+
class Poster
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
GLIP_WEBHOOK_BASE_URL = 'https://hooks.glip.com/webhook/'
|
8
|
+
|
9
|
+
attr_reader :webhook_url
|
10
|
+
attr_accessor :options
|
11
|
+
attr_accessor :http
|
12
|
+
|
13
|
+
def initialize(webhook_url_or_id)
|
14
|
+
webhook_uri(webhook_url_or_id)
|
15
|
+
|
16
|
+
@options = {}
|
17
|
+
|
18
|
+
@http = Faraday.new(:url => GLIP_WEBHOOK_BASE_URL) do |faraday|
|
19
|
+
faraday.request :json
|
20
|
+
faraday.response :logger
|
21
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def webhook_uri(webhook_url_or_id)
|
26
|
+
if webhook_url_or_id.to_s !~ %r{/}
|
27
|
+
@webhook_url = GLIP_WEBHOOK_BASE_URL + webhook_url_or_id
|
28
|
+
elsif webhook_url_or_id =~ %r{^https?://}
|
29
|
+
@webhook_url = webhook_url_or_id
|
30
|
+
else
|
31
|
+
raise 'must include webhook URL or id argument'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def send_message(message, opts={})
|
36
|
+
opts = @options.merge opts
|
37
|
+
opts[:body] = message
|
38
|
+
|
39
|
+
res = @http.post do |req|
|
40
|
+
req.url @webhook_url
|
41
|
+
req.body = opts
|
42
|
+
end
|
43
|
+
return res
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/test/test_base.rb
ADDED
data/test/test_setup.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require './test/test_base.rb'
|
2
|
+
|
3
|
+
class GlipPosterTest < Test::Unit::TestCase
|
4
|
+
def test_setup
|
5
|
+
poster = Glip::Poster.new('deadbeef')
|
6
|
+
|
7
|
+
assert_equal 'Glip::Poster', poster.class.name
|
8
|
+
assert_equal 'https://hooks.glip.com/webhook/deadbeef', poster.webhook_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_url
|
12
|
+
url = 'https://hooks.glip.com/webhook/11111111-2222-3333-4444-555555555555'
|
13
|
+
poster = Glip::Poster.new(url)
|
14
|
+
assert_equal url, poster.webhook_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_farday
|
18
|
+
poster = Glip::Poster.new('deadbeef')
|
19
|
+
Faraday::Connection.any_instance.stubs(:post).returns(Faraday::Response.new)
|
20
|
+
res = poster.send_message('Hello World!')
|
21
|
+
assert_equal 'Faraday::Response', res.class.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_raise
|
25
|
+
assert_raise do
|
26
|
+
poster = Glip::Poster.new
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_raise do
|
30
|
+
poster = Glip::Poster.new('dead/beef')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_options
|
35
|
+
poster = Glip::Poster.new('deadbeef')
|
36
|
+
|
37
|
+
assert_equal true, poster.options.is_a?(Hash)
|
38
|
+
|
39
|
+
poster.options[:icon] = 'http://example.com/icon.png'
|
40
|
+
assert_equal 'http://example.com/icon.png', poster.options[:icon]
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glip-poster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Wang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.9'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.9'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday_middleware
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
description: A Ruby SDK for post messages via Glip webhooks
|
54
|
+
email: johncwang@gmail.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- CHANGELOG.md
|
60
|
+
- Gemfile
|
61
|
+
- Gemfile.lock
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- glip-poster.gemspec
|
66
|
+
- lib/glip-poster.rb
|
67
|
+
- lib/glip-poster/poster.rb
|
68
|
+
- test/test_base.rb
|
69
|
+
- test/test_setup.rb
|
70
|
+
homepage: https://github.com/grokify/
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Glip Poster - Ruby SDK for post messages via Glip webhooks
|
94
|
+
test_files: []
|