firebell 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: faa637876d0bf50ce95d1ea11cb717f9195bc82e
4
+ data.tar.gz: af8d7b4ac2abc4849e4f3544c3e77e0f2cd748d7
5
+ SHA512:
6
+ metadata.gz: 33af9bf718a733c273a66b8a74d57c9ae57f36156e222b501efa351f2125014fde10dc6248ed982a7656fbd2fc9fe2eaf280ebeaf3218074387c8d06a3da2fdb
7
+ data.tar.gz: 5f95e73ebe38245ce287567ab3034bb71f1ea4075323aba90be2fa857ac2b5e3d62109e2d76db980a23779d3333b07ac97f491086154471b88c44b07d64cda21
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Luke Carpenter
2
+
3
+ MIT License
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,41 @@
1
+ # Firebell
2
+
3
+ Firebell notifier for Ruby
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ firebell = Firebell::Client.new
9
+
10
+ # creating events
11
+
12
+ # with just a tag
13
+ firebell.notify "project.category.event"
14
+
15
+ # with a body
16
+ firebell.notify "project.category.event", "category has event"
17
+
18
+ # with parameters
19
+ firebell.notify "project.category.event", "location" => "http://server/file"
20
+
21
+ # with both
22
+ firebell.notify "project.category.event", "location" => "http://server/file", "category has event"
23
+ ```
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ gem 'firebell'
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install firebell
38
+
39
+ ## Contributing
40
+
41
+ PR via [Github](https://github.com/ghostworks/firebell), suggestions to luke@ghostworks.io
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/env.rb ADDED
@@ -0,0 +1,3 @@
1
+ $:.unshift File.expand_path(File.dirname(__FILE__) + "/lib")
2
+
3
+ require "firebell"
data/firebell.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firebell/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firebell"
8
+ spec.version = Firebell::VERSION
9
+ spec.authors = ["Luke Carpenter"]
10
+ spec.email = ["x@rubynerd.net"]
11
+ spec.summary = %q{Push notifications as a service}
12
+ spec.description = %q{A ruby client for Firebell, push notifications as a service}
13
+ spec.homepage = "https://github.com/ghostworks/firebell"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "mocha"
25
+ end
@@ -0,0 +1,40 @@
1
+ require "net/http"
2
+
3
+ class Firebell::Client
4
+ attr_accessor :token
5
+
6
+ def initialize(token = Firebell.configuration.token)
7
+ @token = token
8
+ end
9
+
10
+ def notify(tag, body_or_params = nil, body = nil)
11
+ if body_or_params
12
+ if body_or_params.is_a?(Hash)
13
+ attributes = { "tag" => tag, "parameters" => body_or_params }
14
+ attributes.merge!("body" => body) if body
15
+ else
16
+ attributes = { "tag" => tag, "body" => body_or_params }
17
+ end
18
+ else
19
+ attributes = { "tag" => tag }
20
+ end
21
+
22
+ send_request attributes
23
+ end
24
+
25
+ private
26
+ def send_request(attrs)
27
+ request = Net::HTTP::Post.new uri.request_uri, "Authorization" => "Token #{@token}"
28
+ request.set_form_data attrs
29
+
30
+ http.request(request)
31
+ end
32
+
33
+ def http
34
+ @http ||= Net::HTTP.new uri.host, uri.port
35
+ end
36
+
37
+ def uri
38
+ @uri ||= URI.parse Firebell.configuration.url
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Firebell
2
+ VERSION = "0.1.0"
3
+ end
data/lib/firebell.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "firebell/version"
2
+
3
+ module Firebell
4
+ def self.configure
5
+ yield configuration
6
+ configuration
7
+ end
8
+
9
+ def self.configuration
10
+ @@configuration ||= Configuration.new
11
+ end
12
+
13
+ class Configuration
14
+ attr_writer :host, :url
15
+ attr_accessor :token
16
+
17
+ def host
18
+ @host ||= "https://firebellapp.com"
19
+ end
20
+
21
+ def path
22
+ @path ||= "/api/v1/events"
23
+ end
24
+
25
+ def url
26
+ @url ||= "#{host}#{path}"
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ require "firebell/client"
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe Firebell::Client do
4
+ let(:client) { Firebell::Client.new "token" }
5
+
6
+ describe "#uri" do
7
+ it "is HTTPS by default" do
8
+ expect(client.send(:uri)).to be_instance_of URI::HTTPS
9
+ end
10
+
11
+ it "is a URI object of the configured URL" do
12
+ expect(client.send(:uri)).to eq URI.parse Firebell.configuration.url
13
+ end
14
+ end
15
+
16
+
17
+ context "with a tag and body" do
18
+ it "makes a request" do
19
+ Firebell::Client.any_instance.expects(:send_request).with("tag" => "test.subject", "body" => "hello")
20
+ client.notify "test.subject", "hello"
21
+ end
22
+ end
23
+
24
+ context "with a tag and parameters" do
25
+ it "makes a request" do
26
+ Firebell::Client.any_instance.expects(:send_request)
27
+ .with("tag" => "test.subject", "parameters" => { "p1" => 1 })
28
+
29
+ client.notify "test.subject", "p1" => 1
30
+ end
31
+ end
32
+
33
+ context "with a tag, parameters, and body" do
34
+ it "makes a request" do
35
+ Firebell::Client.any_instance.expects(:send_request)
36
+ .with("tag" => "test.subject", "parameters" => { "p1" => 1 }, "body" => "hello")
37
+
38
+ client.notify "test.subject", { "p1" => 1 }, "hello"
39
+ end
40
+ end
41
+
42
+ context "with just a tag" do
43
+ it "makes a request" do
44
+ Firebell::Client.any_instance.expects(:send_request)
45
+ .with("tag" => "test.subject")
46
+
47
+ client.notify "test.subject"
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Firebell::Configuration do
4
+ it "automatically sets a hostname" do
5
+ c = Firebell::Configuration.new
6
+ expect(c.host).to eq "https://firebellapp.com"
7
+ end
8
+
9
+ it "automatically sets a path" do
10
+ c = Firebell::Configuration.new
11
+ expect(c.path).to eq "/api/v1/events"
12
+ end
13
+
14
+ it "generates an events URL" do
15
+ c = Firebell::Configuration.new
16
+ expect(c.url).to eq "https://firebellapp.com/api/v1/events"
17
+ end
18
+
19
+ it "accepts a non-standard hostname" do
20
+ c = Firebell::Configuration.new
21
+ c.host = "http://cowbell.dev"
22
+ expect(c.url).to eq "http://cowbell.dev/api/v1/events"
23
+
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ describe Firebell do
4
+ describe "::configure" do
5
+ it "returns a Configuration object to ::configuration" do
6
+ configuration = Firebell.configure {}
7
+ expect(configuration).to be_instance_of Firebell::Configuration
8
+ expect(configuration).to eq Firebell.configuration
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'firebell'
5
+
6
+ RSpec.configure do |c|
7
+ c.mock_with :mocha
8
+
9
+ c.after(:each) do
10
+ Firebell.remove_class_variable :@@configuration if Firebell.class_variable_defined? :@@configuration
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firebell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Carpenter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
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
+ description: A ruby client for Firebell, push notifications as a service
70
+ email:
71
+ - x@rubynerd.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - env.rb
83
+ - firebell.gemspec
84
+ - lib/firebell.rb
85
+ - lib/firebell/client.rb
86
+ - lib/firebell/version.rb
87
+ - spec/firebell/client_spec.rb
88
+ - spec/firebell/configuration_spec.rb
89
+ - spec/firebell_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/ghostworks/firebell
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.2.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Push notifications as a service
115
+ test_files:
116
+ - spec/firebell/client_spec.rb
117
+ - spec/firebell/configuration_spec.rb
118
+ - spec/firebell_spec.rb
119
+ - spec/spec_helper.rb