matchstick 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ gem "rest-client", "~>1.6.1"
9
+
10
+ group :development do
11
+ gem "cover_me", ">=0"
12
+ gem "shoulda", ">= 0"
13
+ gem "mocha", ">= 0"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.5.2"
16
+ end
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ configatron (2.6.4)
5
+ yamler (>= 0.1.0)
6
+ cover_me (1.0.0.rc4)
7
+ configatron
8
+ hashie
9
+ git (1.2.5)
10
+ hashie (0.4.0)
11
+ jeweler (1.5.2)
12
+ bundler (~> 1.0.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ mime-types (1.16)
16
+ mocha (0.9.10)
17
+ rake
18
+ rake (0.8.7)
19
+ rest-client (1.6.1)
20
+ mime-types (>= 1.16)
21
+ shoulda (2.11.3)
22
+ yamler (0.1.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.0.0)
29
+ cover_me
30
+ jeweler (~> 1.5.2)
31
+ mocha
32
+ rest-client (~> 1.6.1)
33
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Kyle Daigle
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.
@@ -0,0 +1,19 @@
1
+ = matchstick
2
+
3
+ This is the beginnings of a stable framework for communicating with Campfire. Currently, completely and utterly alpha.
4
+
5
+ == Contributing to matchstick
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Kyle Daigle. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "matchstick"
16
+ gem.homepage = "http://github.com/kdaigle/matchstick"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A simple framework for communicating with 37signals' Campfire API.}
19
+ gem.description = %Q{A simple framework for communicating with 37signals' Campfire API. Currently still a work in progress.}
20
+ gem.email = "kyle@digitalworkbox.com"
21
+ gem.authors = ["Kyle Daigle"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'rest-client', '~>1.6.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'cover_me'
37
+ namespace :cover_me do
38
+
39
+ desc "Run the cover_me rport"
40
+ task :report do
41
+ require 'cover_me'
42
+ CoverMe.complete!
43
+ end
44
+
45
+ end
46
+
47
+ task :test do
48
+ Rake::Task['cover_me:report'].invoke
49
+ end
50
+
51
+ task :default => :test
52
+
53
+ require 'rake/rdoctask'
54
+ Rake::RDocTask.new do |rdoc|
55
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
56
+
57
+ rdoc.rdoc_dir = 'rdoc'
58
+ rdoc.title = "matchstick #{version}"
59
+ rdoc.rdoc_files.include('README*')
60
+ rdoc.rdoc_files.include('lib/**/*.rb')
61
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,9 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ require 'matchstick/campfire'
5
+ require 'matchstick/room'
6
+
7
+ module Matchstick
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,43 @@
1
+ module Matchstick
2
+
3
+ class Campfire
4
+ HOST = "campfirenow.com"
5
+
6
+ attr_reader :subdomain, :api_key, :use_ssl, :connection
7
+
8
+ def initialize(subdomain, api_key, use_ssl=false)
9
+ @subdomain = subdomain
10
+ @api_key = api_key
11
+ @use_ssl = use_ssl
12
+ @connection = build_connection
13
+
14
+ self
15
+ end
16
+
17
+ def rooms
18
+ get("rooms")["rooms"].collect {|room| Room.new(room, connection)}
19
+ end
20
+
21
+ def get(action)
22
+ response = RestClient.get "#{connection}/#{action}", :content_type => :json, :accept => :json
23
+ response.body.strip.empty? ? true : JSON.parse(response.body)
24
+ end
25
+
26
+ def post(action, body = {})
27
+ response = RestClient.post "#{connection}/#{action}", body.to_json, :content_type => :json, :accept => :json
28
+ response.body.strip.empty? ? true : JSON.parse(response.body)
29
+ end
30
+
31
+ protected
32
+
33
+ def authentication
34
+ "#{api_key}:x"
35
+ end
36
+
37
+ def build_connection
38
+ "#{use_ssl ? 'https' : 'http'}://#{authentication}@#{subdomain}.#{HOST}"
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,35 @@
1
+ module Matchstick
2
+
3
+ class Room < Campfire
4
+
5
+ attr_reader :id, :name, :connection
6
+
7
+ def initialize(raw_room, connection)
8
+ @name = raw_room["name"]
9
+ @id = raw_room["id"]
10
+ @connection = connection
11
+ end
12
+
13
+ def speak(message)
14
+ post("room/#{@id}/speak", {:message =>
15
+ {:type => "TextMessage", :body => message}
16
+ })
17
+ end
18
+
19
+ def paste(message)
20
+ post("room/#{@id}/speak", {:message =>
21
+ {:type => "PasteMessage", :body => message}
22
+ })
23
+ end
24
+
25
+ def join
26
+ post("room/#{@id}/join")
27
+ end
28
+
29
+ def leave
30
+ post("room/#{@id}/leave")
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{matchstick}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kyle Daigle"]
12
+ s.date = %q{2011-01-03}
13
+ s.description = %q{A simple framework for communicating with 37signals' Campfire API. Currently still a work in progress.}
14
+ s.email = %q{kyle@digitalworkbox.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/matchstick.rb",
28
+ "lib/matchstick/campfire.rb",
29
+ "lib/matchstick/room.rb",
30
+ "matchstick.gemspec",
31
+ "test/helper.rb",
32
+ "test/matchstick/campfire_test.rb",
33
+ "test/matchstick/room_test.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/kdaigle/matchstick}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{A simple framework for communicating with 37signals' Campfire API.}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/matchstick/campfire_test.rb",
43
+ "test/matchstick/room_test.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
52
+ s.add_development_dependency(%q<cover_me>, [">= 0"])
53
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_development_dependency(%q<mocha>, [">= 0"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.1"])
58
+ else
59
+ s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
60
+ s.add_dependency(%q<cover_me>, [">= 0"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<mocha>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
66
+ end
67
+ else
68
+ s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
69
+ s.add_dependency(%q<cover_me>, [">= 0"])
70
+ s.add_dependency(%q<shoulda>, [">= 0"])
71
+ s.add_dependency(%q<mocha>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
74
+ s.add_dependency(%q<rest-client>, ["~> 1.6.1"])
75
+ end
76
+ end
77
+
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'cover_me'
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'test/unit'
12
+ require 'shoulda'
13
+ require 'mocha'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require 'matchstick'
18
+
19
+ class Test::Unit::TestCase
20
+
21
+ def post_rest_client_arguments(action, message={})
22
+ ["#{@connection}/#{action}", message.to_json, {:content_type => :json, :accept => :json}]
23
+ end
24
+
25
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ class CampfireTest < Test::Unit::TestCase
4
+
5
+ context "With a matchstick" do
6
+
7
+ setup do
8
+ @matchstick = Matchstick::Campfire.new("samplebusiness", "123abc", true)
9
+ end
10
+
11
+ should "have a valid subdomain" do
12
+ assert_equal "samplebusiness", @matchstick.subdomain
13
+ end
14
+
15
+ should "have a valid API key" do
16
+ assert_equal "123abc", @matchstick.api_key
17
+ end
18
+
19
+ should "have build a valid connection" do
20
+ assert_equal "https://123abc:x@samplebusiness.campfirenow.com", @matchstick.connection
21
+ end
22
+
23
+ should "return and build a set of rooms" do
24
+ json_string = {"rooms" => [
25
+ {"id" => 1, "name" => "Business"},
26
+ {"id" => 2, "name" => "Funtimes"}
27
+ ]}.to_json.to_s
28
+
29
+ response = RestClient::Response.create(json_string, 200, {})
30
+
31
+ RestClient.expects(:get).with("https://123abc:x@samplebusiness.campfirenow.com/rooms", {:content_type => :json, :accept => :json}).returns(response)
32
+
33
+ result = @matchstick.rooms
34
+
35
+ assert_equal 2, result.size
36
+ assert result.all? {|r| r.instance_of?(Matchstick::Room) }
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,57 @@
1
+ require 'helper'
2
+
3
+ class RoomTest < Test::Unit::TestCase
4
+
5
+ context "With a room" do
6
+
7
+ setup do
8
+ @connection = "https://123abc:x@samplebusiness.campfirenow.com"
9
+ raw_room = {"id" => 12345, "name" => "Business Room", "created_at" => Time.now.to_s}
10
+ @room = Matchstick::Room.new(raw_room, @connection)
11
+ end
12
+
13
+ should "have a valid name" do
14
+ assert_equal "Business Room", @room.name
15
+ end
16
+
17
+ should "have a valid id" do
18
+ assert_equal 12345, @room.id
19
+ end
20
+
21
+ should "speak a message to this room" do
22
+ json_string = {:message => {:type => "TextMessage", :body => "Hello World"}}.to_json.to_s
23
+ response = RestClient::Response.create(json_string, 200, {})
24
+
25
+ RestClient.expects(:post).with( *post_rest_client_arguments("room/12345/speak", {:message => {:type => "TextMessage", :body => "Hello World"}}) ).returns(response)
26
+
27
+ @room.speak("Hello World")
28
+ end
29
+
30
+ should "speak a pasted message to this room" do
31
+ json_string = {:message => {:type => "TextMessage", :body => "PasteMessage"}}.to_json.to_s
32
+ response = RestClient::Response.create(json_string, 200, {})
33
+
34
+ RestClient.expects(:post).with( *post_rest_client_arguments("room/12345/speak", {:message => {:type => "PasteMessage", :body => "Hello World"}}) ).returns(response)
35
+
36
+ @room.paste("Hello World")
37
+ end
38
+
39
+ should "join this room" do
40
+ response = RestClient::Response.create(" ", 200, {})
41
+
42
+ RestClient.expects(:post).with( *post_rest_client_arguments("room/12345/join") ).returns(response)
43
+
44
+ @room.join
45
+ end
46
+
47
+ should "leave this room" do
48
+ response = RestClient::Response.create(" ", 200, {})
49
+
50
+ RestClient.expects(:post).with( *post_rest_client_arguments("room/12345/leave") ).returns(response)
51
+
52
+ @room.leave
53
+ end
54
+
55
+ end
56
+
57
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matchstick
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Kyle Daigle
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-03 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 6
30
+ - 1
31
+ version: 1.6.1
32
+ type: :runtime
33
+ prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: cover_me
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: shoulda
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: bundler
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 0
84
+ - 0
85
+ version: 1.0.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: jeweler
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 1
98
+ - 5
99
+ - 2
100
+ version: 1.5.2
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: rest-client
106
+ requirement: &id007 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 1
113
+ - 6
114
+ - 1
115
+ version: 1.6.1
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: *id007
119
+ description: A simple framework for communicating with 37signals' Campfire API. Currently still a work in progress.
120
+ email: kyle@digitalworkbox.com
121
+ executables: []
122
+
123
+ extensions: []
124
+
125
+ extra_rdoc_files:
126
+ - LICENSE.txt
127
+ - README.rdoc
128
+ files:
129
+ - .document
130
+ - Gemfile
131
+ - Gemfile.lock
132
+ - LICENSE.txt
133
+ - README.rdoc
134
+ - Rakefile
135
+ - VERSION
136
+ - lib/matchstick.rb
137
+ - lib/matchstick/campfire.rb
138
+ - lib/matchstick/room.rb
139
+ - matchstick.gemspec
140
+ - test/helper.rb
141
+ - test/matchstick/campfire_test.rb
142
+ - test/matchstick/room_test.rb
143
+ has_rdoc: true
144
+ homepage: http://github.com/kdaigle/matchstick
145
+ licenses:
146
+ - MIT
147
+ post_install_message:
148
+ rdoc_options: []
149
+
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 2422956089847336013
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ requirements: []
170
+
171
+ rubyforge_project:
172
+ rubygems_version: 1.3.7
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: A simple framework for communicating with 37signals' Campfire API.
176
+ test_files:
177
+ - test/helper.rb
178
+ - test/matchstick/campfire_test.rb
179
+ - test/matchstick/room_test.rb