twinkle-client 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 +9 -0
- data/.rspec +4 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +51 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/twinkle/client.rb +57 -0
- data/lib/twinkle/client/default_formatter.rb +22 -0
- data/lib/twinkle/client/version.rb +5 -0
- data/twinkle-client.gemspec +28 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 40db9134efad382ac5af62130a65756ae9d70456
|
4
|
+
data.tar.gz: addded47d1815952ce2d730cc01c08694797b412
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a82aea8ddc6264fb8a309ff6926e79ba91179daa931796ea30054522e7b402d5742576737d7d7651dcf3f368f1d6d92c3cdbcde0bdcfc8e314c90a31ab51d033
|
7
|
+
data.tar.gz: ff578bfb7b5b5a0e2d0cd0af25e196911434b3abf9f0a6bb2432e40b114a2c28d507efef6698b7c25f80883e7e0f51d1cee0b6192314202b52745697f3c3ed2c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Twinkle::Client
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/bibendi/twinkle-client)
|
4
|
+
[](https://codeclimate.com/github/bibendi/twinkle-client/coverage)
|
5
|
+
[](https://travis-ci.org/bibendi/twinkle-client)
|
6
|
+
|
7
|
+
A ruby client for [Twinkle](https://github.com/bibendi/twinkle) notification service.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'twinkle-client'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install twinkle-client
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
#### Basic configuration
|
28
|
+
```ruby
|
29
|
+
Twinkle::Client.configure do |config|
|
30
|
+
config.endpoint = "http://example.com"
|
31
|
+
config.token = "hex-digest-user-token"
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
#### Sending a message
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Twinkle::Client.create_message("deploy", "Release!")
|
39
|
+
|
40
|
+
Twinkle::Client.create_message("sadness", exception)
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bibendi/twinkle-client.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "twinkle/client"
|
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
@@ -0,0 +1,57 @@
|
|
1
|
+
require "curb"
|
2
|
+
require "twinkle/client/version"
|
3
|
+
require "twinkle/client/default_formatter"
|
4
|
+
|
5
|
+
module Twinkle
|
6
|
+
module Client
|
7
|
+
Config = Struct.new(:endpoint, :token, :formatter)
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
@config ||= Config.new.tap do |config|
|
11
|
+
config.formatter = ::Twinkle::Client::DefaultFormatter
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield config
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.reset
|
20
|
+
@resources = nil
|
21
|
+
@config = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# Send a message
|
25
|
+
#
|
26
|
+
# channel - String The name of channel
|
27
|
+
# message - String|Exception A text message or failure object
|
28
|
+
# options - Hash
|
29
|
+
# :formatter - Proc A formatter block (default: :simple)
|
30
|
+
def self.create_message(channel, message, options = {})
|
31
|
+
formatter = options.fetch(:formatter, config.formatter)
|
32
|
+
message = formatter.call(message)
|
33
|
+
|
34
|
+
post "/messages", channel: channel, message: message
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def self.post(path, params = {})
|
40
|
+
add_default_params(params)
|
41
|
+
http = Curl.post(resource(path), params) do |client|
|
42
|
+
client.headers["Content-Type"] = "application/json"
|
43
|
+
end
|
44
|
+
|
45
|
+
http.body_str
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.add_default_params(params)
|
49
|
+
params[:token] ||= config.token
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.resource(path)
|
53
|
+
@resources ||= Hash.new({})
|
54
|
+
@resources[config.endpoint][path] ||= File.join(config.endpoint, path)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Twinkle
|
2
|
+
module Client
|
3
|
+
class DefaultFormatter
|
4
|
+
@backtrace_num_lines = 3
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :backtrace_num_lines
|
8
|
+
|
9
|
+
def call(message)
|
10
|
+
formatted_message = message.message if message.respond_to?(:message)
|
11
|
+
formatted_message ||= message.to_s
|
12
|
+
|
13
|
+
if message.respond_to?(:backtrace)
|
14
|
+
formatted_message << "\n#{message.backtrace.take(@backtrace_num_lines).join("\n")}"
|
15
|
+
end
|
16
|
+
|
17
|
+
formatted_message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'twinkle/client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "twinkle-client"
|
8
|
+
spec.version = Twinkle::Client::VERSION
|
9
|
+
spec.authors = ["Michail Merkushin"]
|
10
|
+
spec.email = ["merkushin.m.s@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A ruby client for Twinkle notification service.}
|
13
|
+
spec.description = %q{A ruby client for Twinkle notification service}
|
14
|
+
spec.homepage = "https://github.com/bibendi/twinkle-client"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
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_runtime_dependency "curb"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
27
|
+
spec.add_development_dependency "webmock", "~> 1.24"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twinkle-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michail Merkushin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - '>='
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: curb
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.11'
|
33
|
+
name: bundler
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '1.11'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '10.0'
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '10.0'
|
53
|
+
type: :development
|
54
|
+
prerelease: false
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ~>
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
name: rspec
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
name: codeclimate-test-reporter
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.24'
|
89
|
+
name: webmock
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '1.24'
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
97
|
+
description: A ruby client for Twinkle notification service
|
98
|
+
email:
|
99
|
+
- merkushin.m.s@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/twinkle/client.rb
|
113
|
+
- lib/twinkle/client/default_formatter.rb
|
114
|
+
- lib/twinkle/client/version.rb
|
115
|
+
- twinkle-client.gemspec
|
116
|
+
homepage: https://github.com/bibendi/twinkle-client
|
117
|
+
licenses: []
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.4.8
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: A ruby client for Twinkle notification service.
|
139
|
+
test_files: []
|