kindling 0.0.2
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.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +27 -0
- data/VERSION +1 -0
- data/kindling.gemspec +52 -0
- data/lib/kindling/campfire.rb +26 -0
- data/lib/kindling/request.rb +52 -0
- data/lib/kindling.rb +10 -0
- data/test/fixtures/rooms.json +14 -0
- data/test/kindling/request_test.rb +62 -0
- data/test/test_helper.rb +28 -0
- metadata +67 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 wal
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
= kindling
|
|
2
|
+
|
|
3
|
+
Description goes here.
|
|
4
|
+
|
|
5
|
+
== Note on Patches/Pull Requests
|
|
6
|
+
|
|
7
|
+
* Fork the project.
|
|
8
|
+
* Make your feature addition or bug fix.
|
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
|
10
|
+
future version unintentionally.
|
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
14
|
+
|
|
15
|
+
== Copyright
|
|
16
|
+
|
|
17
|
+
Copyright (c) 2009 wal. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
Rake::TestTask.new(:test) do |test|
|
|
6
|
+
test.libs << 'test'
|
|
7
|
+
test.ruby_opts << '-rubygems'
|
|
8
|
+
test.pattern = 'test/**/*_test.rb'
|
|
9
|
+
test.verbose = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
task :default => :test
|
|
13
|
+
|
|
14
|
+
begin
|
|
15
|
+
require 'jeweler'
|
|
16
|
+
Jeweler::Tasks.new do |gemspec|
|
|
17
|
+
gemspec.name = "kindling"
|
|
18
|
+
gemspec.summary = "Ruby wrapper for the 37 Signals Campfire API"
|
|
19
|
+
gemspec.description = "Ruby wrapper for the 37 Signals Campfire API"
|
|
20
|
+
gemspec.email = "wal@contrast.ie"
|
|
21
|
+
gemspec.homepage = "http://github.com/contrast/kindling"
|
|
22
|
+
gemspec.authors = ["Wal McConnell"]
|
|
23
|
+
Jeweler::GemcutterTasks.new
|
|
24
|
+
end
|
|
25
|
+
rescue LoadError
|
|
26
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
|
27
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.2
|
data/kindling.gemspec
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{kindling}
|
|
8
|
+
s.version = "0.0.2"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Wal McConnell"]
|
|
12
|
+
s.date = %q{2009-12-21}
|
|
13
|
+
s.description = %q{Ruby wrapper for the 37 Signals Campfire API}
|
|
14
|
+
s.email = %q{wal@contrast.ie}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.rdoc"
|
|
18
|
+
]
|
|
19
|
+
s.files = [
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"README.rdoc",
|
|
22
|
+
"Rakefile",
|
|
23
|
+
"VERSION",
|
|
24
|
+
"kindling.gemspec",
|
|
25
|
+
"lib/kindling.rb",
|
|
26
|
+
"lib/kindling/campfire.rb",
|
|
27
|
+
"lib/kindling/request.rb",
|
|
28
|
+
"test/fixtures/rooms.json",
|
|
29
|
+
"test/kindling/request_test.rb",
|
|
30
|
+
"test/test_helper.rb"
|
|
31
|
+
]
|
|
32
|
+
s.homepage = %q{http://github.com/contrast/kindling}
|
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
34
|
+
s.require_paths = ["lib"]
|
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
|
36
|
+
s.summary = %q{Ruby wrapper for the 37 Signals Campfire API}
|
|
37
|
+
s.test_files = [
|
|
38
|
+
"test/kindling/request_test.rb",
|
|
39
|
+
"test/test_helper.rb"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
if s.respond_to? :specification_version then
|
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
44
|
+
s.specification_version = 3
|
|
45
|
+
|
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
47
|
+
else
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Kindling
|
|
2
|
+
|
|
3
|
+
class Campfire
|
|
4
|
+
|
|
5
|
+
attr_accessor :api_token, :subdomain, :room_id
|
|
6
|
+
|
|
7
|
+
def initialize(api_token, subdomain, room_id)
|
|
8
|
+
@api_token = api_token
|
|
9
|
+
@subdomain = subdomain
|
|
10
|
+
@room_id = room_id
|
|
11
|
+
rooms
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def rooms
|
|
15
|
+
Kindling::Request.rooms(self)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def speak(message)
|
|
19
|
+
Kindling::Request.speak(message, self)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def credentials
|
|
23
|
+
{:username => @api_token, :password => 'x'}
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'httparty'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class Kindling::Request
|
|
6
|
+
|
|
7
|
+
CAMPFIRE_HOST = 'campfirenow.com'
|
|
8
|
+
include HTTParty
|
|
9
|
+
format :json
|
|
10
|
+
|
|
11
|
+
headers 'Content-Type' => 'application/json'
|
|
12
|
+
|
|
13
|
+
def self.rooms(campfire)
|
|
14
|
+
response = get rooms_url(campfire), :basic_auth => campfire.credentials
|
|
15
|
+
case response.code
|
|
16
|
+
when 404
|
|
17
|
+
raise Kindling::InvalidSubdomain.new(campfire.subdomain)
|
|
18
|
+
when 401
|
|
19
|
+
raise Kindling::InvalidAPIToken.new(campfire.api_token)
|
|
20
|
+
when 200
|
|
21
|
+
return response["rooms"]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.speak(message, campfire)
|
|
26
|
+
response = post room_url(campfire), :body => {:message => {:body => message, :type => "Textmessage"}}.to_json, :basic_auth => campfire.credentials
|
|
27
|
+
case response.code
|
|
28
|
+
when 404
|
|
29
|
+
raise Kindling::InvalidRoomID.new(campfire.room_id)
|
|
30
|
+
when 401
|
|
31
|
+
raise Kindling::InvalidAPIToken.new(campfire.api_token)
|
|
32
|
+
when 200..201
|
|
33
|
+
response
|
|
34
|
+
else
|
|
35
|
+
raise Kindling::Error.new("Unexpected error occured #{response.code}/#{response.message}")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def self.room_url(campfire)
|
|
42
|
+
"#{subdomain(campfire)}/room/#{campfire.room_id}/speak.json"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.rooms_url(campfire)
|
|
46
|
+
"#{subdomain(campfire)}/rooms.json"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.subdomain(campfire)
|
|
50
|
+
"http://#{campfire.subdomain}.#{CAMPFIRE_HOST}"
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/kindling.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module Kindling
|
|
2
|
+
class Error < StandardError; end
|
|
3
|
+
class InvalidSubdomain < StandardError; end
|
|
4
|
+
class InvalidAPIToken < StandardError; end
|
|
5
|
+
class InvalidRoomID < StandardError; end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
['campfire', 'request'].each do |file|
|
|
9
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'kindling', file)
|
|
10
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
class RequestTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
context "Request" do
|
|
7
|
+
setup do
|
|
8
|
+
stub_rooms_request({:code => 200, :[] => JSON.parse(fixture_file("rooms.json"))["rooms"]})
|
|
9
|
+
@campfire = Kindling::Campfire.new(TEST_API_TOKEN, TEST_SUBDOMAIN, TEST_ROOM_ID)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "rooms" do
|
|
13
|
+
|
|
14
|
+
should "should raise error if invalid subdomain" do
|
|
15
|
+
stub_rooms_request({:code => 404})
|
|
16
|
+
assert_raises Kindling::InvalidSubdomain do
|
|
17
|
+
Kindling::Request.rooms(@campfire)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
should "should raise error if invalid api_token" do
|
|
22
|
+
stub_rooms_request({:code => 401})
|
|
23
|
+
assert_raises Kindling::InvalidAPIToken do
|
|
24
|
+
Kindling::Request.rooms(@campfire)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
should "should return rooms list" do
|
|
29
|
+
stub_rooms_request({:code => 200, :[] => JSON.parse(fixture_file("rooms.json"))["rooms"]})
|
|
30
|
+
assert_equal [{"name"=>"Room 1", "id"=>201712}, {"name"=>"Room 2", "id"=>298625}, {"name"=>"Room 3", "id"=>206877}], Kindling::Request.rooms(@campfire)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
context "send message" do
|
|
36
|
+
should "send message successfully if 200" do
|
|
37
|
+
stub_send_message_request('test message', {:code => 200})
|
|
38
|
+
Kindling::Request.speak("test message", @campfire)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "send message successfully if 201" do
|
|
42
|
+
stub_send_message_request('test message', {:code => 201})
|
|
43
|
+
Kindling::Request.speak("test message", @campfire)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
should "raise error if invalid room id" do
|
|
47
|
+
stub_send_message_request('test message', {:code => 404})
|
|
48
|
+
assert_raises Kindling::InvalidRoomID do
|
|
49
|
+
Kindling::Request.speak("test message", @campfire)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should "raise error if invalid API token" do
|
|
54
|
+
stub_send_message_request('test message', {:code => 401})
|
|
55
|
+
assert_raises Kindling::InvalidAPIToken do
|
|
56
|
+
Kindling::Request.speak("test message", @campfire)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'shoulda'
|
|
3
|
+
require 'mocha'
|
|
4
|
+
|
|
5
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'kindling')
|
|
6
|
+
|
|
7
|
+
def fixture_file(filename)
|
|
8
|
+
return '' if filename == ''
|
|
9
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
|
10
|
+
File.read(file_path)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
TEST_SUBDOMAIN = 'testsubdomain'
|
|
14
|
+
TEST_API_TOKEN = '787654567654323456789098765432345678765432'
|
|
15
|
+
TEST_ROOM_ID = '201712'
|
|
16
|
+
|
|
17
|
+
def stub_rooms_request(resp)
|
|
18
|
+
response = mock('Net::HTTPResponse', resp)
|
|
19
|
+
Kindling::Request.expects(:get).with("http://#{TEST_SUBDOMAIN}.campfirenow.com/rooms.json", {:basic_auth => {:password => 'x', :username => "#{TEST_API_TOKEN}"}}).returns(response)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def stub_send_message_request(message, resp)
|
|
23
|
+
response = mock('Net::HTTPResponse', resp)
|
|
24
|
+
Kindling::Request.expects(:post).with(
|
|
25
|
+
"http://#{TEST_SUBDOMAIN}.campfirenow.com/room/#{TEST_ROOM_ID}/speak.json",
|
|
26
|
+
:body => {:message => {:body => message, :type => "Textmessage"}}.to_json,
|
|
27
|
+
:basic_auth => {:password => 'x', :username => "#{TEST_API_TOKEN}"}).returns(response)
|
|
28
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kindling
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Wal McConnell
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-12-21 00:00:00 +00:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Ruby wrapper for the 37 Signals Campfire API
|
|
17
|
+
email: wal@contrast.ie
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- LICENSE
|
|
27
|
+
- README.rdoc
|
|
28
|
+
- Rakefile
|
|
29
|
+
- VERSION
|
|
30
|
+
- kindling.gemspec
|
|
31
|
+
- lib/kindling.rb
|
|
32
|
+
- lib/kindling/campfire.rb
|
|
33
|
+
- lib/kindling/request.rb
|
|
34
|
+
- test/fixtures/rooms.json
|
|
35
|
+
- test/kindling/request_test.rb
|
|
36
|
+
- test/test_helper.rb
|
|
37
|
+
has_rdoc: true
|
|
38
|
+
homepage: http://github.com/contrast/kindling
|
|
39
|
+
licenses: []
|
|
40
|
+
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options:
|
|
43
|
+
- --charset=UTF-8
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: "0"
|
|
51
|
+
version:
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
version:
|
|
58
|
+
requirements: []
|
|
59
|
+
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.3.5
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 3
|
|
64
|
+
summary: Ruby wrapper for the 37 Signals Campfire API
|
|
65
|
+
test_files:
|
|
66
|
+
- test/kindling/request_test.rb
|
|
67
|
+
- test/test_helper.rb
|