campfiyah 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.md +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/campfiyah.gemspec +29 -0
- data/lib/campfiyah/account.rb +22 -0
- data/lib/campfiyah/adapters/http.rb +47 -0
- data/lib/campfiyah/adapters/memory/rooms.json +1 -0
- data/lib/campfiyah/adapters/memory.rb +13 -0
- data/lib/campfiyah/adapters.rb +21 -0
- data/lib/campfiyah/room.rb +16 -0
- data/lib/campfiyah/version.rb +3 -0
- data/lib/campfiyah.rb +23 -0
- data/spec/account_spec.rb +17 -0
- data/spec/room_spec.rb +9 -0
- data/spec/spec_helper.rb +24 -0
- metadata +178 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Corey Donohoe
|
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,48 @@
|
|
1
|
+
# Campfiyah
|
2
|
+
|
3
|
+
A simple faraday backed library for campfire. It comes with an in-memory adapter
|
4
|
+
to make working with campfire's API in dev/test a lot easier.
|
5
|
+
|
6
|
+
Given a subdomain and a token, Campfiyah gives you two things.
|
7
|
+
|
8
|
+
* List all rooms the token can access on a campfire subdomain
|
9
|
+
* Send messages to specific rooms
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'campfiyah'
|
16
|
+
|
17
|
+
|
18
|
+
Then require it in your code
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'campfiyah'
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
account = Campfiyah::Account.new(default_subdomain, default_token)
|
28
|
+
room = account.find_room("The Danger Room")
|
29
|
+
room.message("woot")
|
30
|
+
```
|
31
|
+
|
32
|
+
You can also enable the in-memory adapter for development or tests.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Campfiyah.enable_mock!
|
36
|
+
```
|
37
|
+
|
38
|
+
This won't hit the network at all but give you a consistent interface.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Create new Pull Request
|
43
|
+
|
44
|
+
## WTF is up with the name?
|
45
|
+
|
46
|
+
![](https://f.cloud.github.com/assets/38/359743/8b6cc2c0-a16d-11e2-8d90-6b84f53bde79.gif)
|
47
|
+
|
48
|
+
**Dylan... Dylan.. Dylan, Dylan, and Dylan. Because I spit hot fiyah.**
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/campfiyah.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'campfiyah/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "campfiyah"
|
8
|
+
spec.version = Campfiyah::VERSION
|
9
|
+
spec.authors = ["Corey Donohoe"]
|
10
|
+
spec.email = ["atmos@atmos.org"]
|
11
|
+
spec.description = %q{A simple faraday based Campfire API}
|
12
|
+
spec.summary = %q{Ruby API to Campfire's json endpoints}
|
13
|
+
spec.homepage = "https://github.com/atmos/campfiyah"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "yajl-ruby"
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
spec.add_dependency "faraday_middleware"
|
24
|
+
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Campfiyah
|
2
|
+
class Account
|
3
|
+
attr_accessor :subdomain, :token
|
4
|
+
|
5
|
+
def initialize(subdomain, token)
|
6
|
+
@adapter = Campfiyah.adapter.new(subdomain, token)
|
7
|
+
|
8
|
+
@token = token
|
9
|
+
@subdomain = subdomain
|
10
|
+
end
|
11
|
+
|
12
|
+
def rooms
|
13
|
+
@rooms ||= @adapter.rooms.map do |room|
|
14
|
+
Room.from_hash(room, @adapter)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_room(name)
|
19
|
+
rooms.find {|r| r.name == name}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Campfiyah
|
2
|
+
module Adapters
|
3
|
+
class HTTP < Campfiyah::Adapters::Adapter
|
4
|
+
def connection
|
5
|
+
@connection ||= connection!
|
6
|
+
end
|
7
|
+
|
8
|
+
def connection!
|
9
|
+
endpoint = "https://#{subdomain}.campfirenow.com"
|
10
|
+
Faraday.new endpoint do |conn|
|
11
|
+
conn.request :json
|
12
|
+
conn.response :json, :content_type => /\bjson$/
|
13
|
+
|
14
|
+
conn.basic_auth token, 'X'
|
15
|
+
conn.adapter Faraday.default_adapter
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def rooms
|
20
|
+
rooms = [ ]
|
21
|
+
response = connection.get("/rooms.json")
|
22
|
+
if response.status == 200
|
23
|
+
rooms = response.body["rooms"]
|
24
|
+
end
|
25
|
+
|
26
|
+
rooms.sort { |a,b| b['updated_at'] <=> a['updated_at'] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def message(room_id, message)
|
30
|
+
response = connection.post("/room/#{room_id}/speak.json") do |req|
|
31
|
+
req.headers['Content-Type'] = 'application/json'
|
32
|
+
req.body = %{{"message":{"body":#{quote(message)}}}}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def quote(string)
|
39
|
+
if string.respond_to?(:to_json)
|
40
|
+
string.to_json
|
41
|
+
else
|
42
|
+
string.inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"rooms":[ {"name":"The Danger Room","created_at":"2008/07/14 02:05:26 +0000","updated_at":"2013/04/09 18:39:27 +0000","topic":"Danger","id":123456,"locked":false}, {"name":"The Enterprise Room","created_at":"2009/06/17 00:24:59 +0000","updated_at":"2013/04/04 19:14:36 +0000","topic":"Enterprisey","id":123457,"locked":false}, {"name":"Notices","created_at":"2009/08/25 10:55:39 +0000","updated_at":"2012/09/06 18:11:10 +0000","topic":"Shit that Robots Say","id":123458,"locked":false}, {"name":"The Serious Room","created_at":"2009/10/14 05:18:58 +0000","updated_at":"2013/04/09 07:00:46 +0000","topic":"srsbzniss","id":123459,"locked":false}, {"name":"Ops","created_at":"2010/02/17 18:09:19 +0000","updated_at":"2013/04/09 19:15:42 +0000","topic":"Is production broken? 'hubot help' Otherwise, please create an issue","id":123460,"locked":false}]}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Campfiyah
|
2
|
+
module Adapters
|
3
|
+
class Memory < Campfiyah::Adapters::Adapter
|
4
|
+
def rooms
|
5
|
+
@rooms ||= Yajl.load(File.read("#{File.dirname(__FILE__)}/memory/rooms.json"))['rooms']
|
6
|
+
end
|
7
|
+
|
8
|
+
def message(room_id, message)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Campfiyah
|
2
|
+
module Adapters
|
3
|
+
class Adapter
|
4
|
+
attr_accessor :subdomain, :token
|
5
|
+
def initialize(subdomain, token)
|
6
|
+
@subdomain, @token = subdomain, token
|
7
|
+
end
|
8
|
+
|
9
|
+
def rooms
|
10
|
+
fail "Implement #rooms in your own adapter"
|
11
|
+
end
|
12
|
+
|
13
|
+
def message(room_id, message)
|
14
|
+
fail "Implement #message in your own adapter"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'campfiyah/adapters/http'
|
21
|
+
require 'campfiyah/adapters/memory'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Campfiyah
|
2
|
+
class Room
|
3
|
+
attr_accessor :updated_at, :id, :name
|
4
|
+
def initialize(adapter, id, name, updated_at)
|
5
|
+
@adapter, @id, @name, @updated_at = adapter, id, name, updated_at
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.from_hash(hash, adapter)
|
9
|
+
new(adapter, hash["id"], hash["name"], hash["updated_at"])
|
10
|
+
end
|
11
|
+
|
12
|
+
def message(message)
|
13
|
+
@adapter.message(id, message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/campfiyah.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'yajl'
|
2
|
+
require 'faraday'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
require "campfiyah/version"
|
6
|
+
require "campfiyah/account"
|
7
|
+
require "campfiyah/room"
|
8
|
+
require "campfiyah/adapters"
|
9
|
+
|
10
|
+
module Campfiyah
|
11
|
+
def self.enable_mock!
|
12
|
+
@mock = true
|
13
|
+
@adapter = Campfiyah::Adapters::Memory
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.adapter
|
17
|
+
@adapter ||= Campfiyah::Adapters::HTTP
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.adapter=(adapter)
|
21
|
+
@adapter = adapter
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Campfiyah::Account do
|
4
|
+
context "lists all available rooms" do
|
5
|
+
it "does shit" do
|
6
|
+
account = Campfiyah::Account.new(default_subdomain, default_token)
|
7
|
+
account.rooms.should_not be_empty
|
8
|
+
|
9
|
+
room = account.rooms.first
|
10
|
+
room.id.should_not be_nil
|
11
|
+
room.name.should_not be_nil
|
12
|
+
|
13
|
+
room = account.find_room("The Danger Room")
|
14
|
+
room.message("woot").should be
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/room_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
+
require 'campfiyah'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
Campfiyah.enable_mock!
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.before do
|
11
|
+
end
|
12
|
+
config.after do
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_token
|
16
|
+
ENV['CAMPFIYAH_TOKEN'] ||= "0xdeadbeef"
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_subdomain
|
20
|
+
ENV['CAMPFIYAH_SUBDOMAIN'] ||= "github"
|
21
|
+
end
|
22
|
+
|
23
|
+
config.order = "random"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: campfiyah
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Corey Donohoe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yajl-ruby
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: faraday_middleware
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: bundler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '1.3'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: rake
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: A simple faraday based Campfire API
|
127
|
+
email:
|
128
|
+
- atmos@atmos.org
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.md
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- campfiyah.gemspec
|
139
|
+
- lib/campfiyah.rb
|
140
|
+
- lib/campfiyah/account.rb
|
141
|
+
- lib/campfiyah/adapters.rb
|
142
|
+
- lib/campfiyah/adapters/http.rb
|
143
|
+
- lib/campfiyah/adapters/memory.rb
|
144
|
+
- lib/campfiyah/adapters/memory/rooms.json
|
145
|
+
- lib/campfiyah/room.rb
|
146
|
+
- lib/campfiyah/version.rb
|
147
|
+
- spec/account_spec.rb
|
148
|
+
- spec/room_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
homepage: https://github.com/atmos/campfiyah
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.8.23
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: Ruby API to Campfire's json endpoints
|
175
|
+
test_files:
|
176
|
+
- spec/account_spec.rb
|
177
|
+
- spec/room_spec.rb
|
178
|
+
- spec/spec_helper.rb
|