hipchat 0.2.2 → 0.3.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.
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/hipchat.gemspec +8 -5
- data/lib/hipchat.rb +22 -12
- data/spec/hipchat_spec.rb +43 -3
- data/spec/spec_helper.rb +4 -4
- metadata +23 -9
data/Rakefile
CHANGED
|
@@ -11,7 +11,8 @@ begin
|
|
|
11
11
|
gem.homepage = "http://github.com/david/hipchat"
|
|
12
12
|
gem.authors = ["david"]
|
|
13
13
|
gem.add_dependency "httparty"
|
|
14
|
-
gem.add_development_dependency "rspec", "
|
|
14
|
+
gem.add_development_dependency "rspec", "~> 2.0"
|
|
15
|
+
gem.add_development_dependency "rr", "~> 1.0"
|
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
16
17
|
end
|
|
17
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0
|
data/hipchat.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{hipchat}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.3.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["david"]
|
|
12
|
-
s.date = %q{2011-06
|
|
12
|
+
s.date = %q{2011-07-06}
|
|
13
13
|
s.description = %q{Ruby library to interact with HipChat}
|
|
14
14
|
s.email = %q{dgleal@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -41,14 +41,17 @@ Gem::Specification.new do |s|
|
|
|
41
41
|
|
|
42
42
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
43
43
|
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
|
44
|
-
s.add_development_dependency(%q<rspec>, ["
|
|
44
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
|
45
|
+
s.add_development_dependency(%q<rr>, ["~> 1.0"])
|
|
45
46
|
else
|
|
46
47
|
s.add_dependency(%q<httparty>, [">= 0"])
|
|
47
|
-
s.add_dependency(%q<rspec>, ["
|
|
48
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
|
49
|
+
s.add_dependency(%q<rr>, ["~> 1.0"])
|
|
48
50
|
end
|
|
49
51
|
else
|
|
50
52
|
s.add_dependency(%q<httparty>, [">= 0"])
|
|
51
|
-
s.add_dependency(%q<rspec>, ["
|
|
53
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
|
54
|
+
s.add_dependency(%q<rr>, ["~> 1.0"])
|
|
52
55
|
end
|
|
53
56
|
end
|
|
54
57
|
|
data/lib/hipchat.rb
CHANGED
|
@@ -2,10 +2,14 @@ require 'httparty'
|
|
|
2
2
|
require 'ostruct'
|
|
3
3
|
|
|
4
4
|
module HipChat
|
|
5
|
+
class UnknownRoom < StandardError; end
|
|
6
|
+
class Unauthorized < StandardError; end
|
|
7
|
+
class UnknownResponseCode < StandardError; end
|
|
8
|
+
|
|
5
9
|
class Client
|
|
6
10
|
include HTTParty
|
|
7
11
|
|
|
8
|
-
base_uri '
|
|
12
|
+
base_uri 'https://api.hipchat.com/v1/rooms'
|
|
9
13
|
format :json
|
|
10
14
|
|
|
11
15
|
def initialize(token)
|
|
@@ -18,15 +22,14 @@ module HipChat
|
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
def [](name)
|
|
21
|
-
|
|
25
|
+
Room.new(@token, :room_id => name)
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
class Room < OpenStruct
|
|
26
30
|
include HTTParty
|
|
27
31
|
|
|
28
|
-
base_uri '
|
|
29
|
-
format :json
|
|
32
|
+
base_uri 'https://api.hipchat.com/v1/rooms'
|
|
30
33
|
|
|
31
34
|
def initialize(token, params)
|
|
32
35
|
@token = token
|
|
@@ -35,14 +38,21 @@ module HipChat
|
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
def send(from, message, notify = false)
|
|
38
|
-
self.class.post('/message',
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
response = self.class.post('/message',
|
|
42
|
+
:query => { :auth_token => @token },
|
|
43
|
+
:body => {:room_id => room_id,
|
|
44
|
+
:from => from,
|
|
45
|
+
:message => message,
|
|
46
|
+
:notify => notify ? 1 : 0})
|
|
47
|
+
|
|
48
|
+
case response.code
|
|
49
|
+
when 200; # weee
|
|
50
|
+
when 404; raise UnknownRoom, "Unknown room: `#{room_id}'"
|
|
51
|
+
when 401; raise Unauthorized, "Access denied to room `#{room_id}'"
|
|
52
|
+
else raise UnknownResponseCode, "Unexpected #{response.code} for " <<
|
|
53
|
+
"room `#{room_id}'"
|
|
54
|
+
|
|
55
|
+
end
|
|
46
56
|
end
|
|
47
57
|
end
|
|
48
58
|
end
|
data/spec/hipchat_spec.rb
CHANGED
|
@@ -1,7 +1,47 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
describe HipChat do
|
|
4
|
+
subject { HipChat::Client.new("blah") }
|
|
5
|
+
|
|
6
|
+
let(:room) { subject["Hipchat"] }
|
|
7
|
+
|
|
8
|
+
describe "sends a message to a room" do
|
|
9
|
+
it "successfully" do
|
|
10
|
+
mock(HipChat::Room).post("/message",
|
|
11
|
+
:query => {:auth_token => "blah"},
|
|
12
|
+
:body => {:room_id => "Hipchat",
|
|
13
|
+
:from => "Dude",
|
|
14
|
+
:message => "Hello world",
|
|
15
|
+
:notify => 0}) {
|
|
16
|
+
OpenStruct.new(:code => 200)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
room.send "Dude", "Hello world"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "but fails when the room doesn't exist" do
|
|
23
|
+
mock(HipChat::Room).post(anything, anything) {
|
|
24
|
+
OpenStruct.new(:code => 404)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lambda { room.send "", "" }.should raise_error(HipChat::UnknownRoom)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "but fails when we're not allowed to do so" do
|
|
31
|
+
mock(HipChat::Room).post(anything, anything) {
|
|
32
|
+
OpenStruct.new(:code => 401)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lambda { room.send "", "" }.should raise_error(HipChat::Unauthorized)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "but fails if we get an unknown response code" do
|
|
39
|
+
mock(HipChat::Room).post(anything, anything) {
|
|
40
|
+
OpenStruct.new(:code => 403)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
lambda { room.send "", "" }.
|
|
44
|
+
should raise_error(HipChat::UnknownResponseCode)
|
|
45
|
+
end
|
|
6
46
|
end
|
|
7
47
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
3
|
require 'hipchat'
|
|
4
|
-
require '
|
|
5
|
-
require '
|
|
4
|
+
require 'rspec'
|
|
5
|
+
require 'rspec/autorun'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
config.mock_with :rr
|
|
9
9
|
end
|
metadata
CHANGED
|
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 3
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.3.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- david
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-06
|
|
18
|
+
date: 2011-07-06 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -38,16 +38,30 @@ dependencies:
|
|
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
|
-
- -
|
|
41
|
+
- - ~>
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
hash:
|
|
43
|
+
hash: 3
|
|
44
44
|
segments:
|
|
45
|
-
- 1
|
|
46
45
|
- 2
|
|
47
|
-
-
|
|
48
|
-
version:
|
|
46
|
+
- 0
|
|
47
|
+
version: "2.0"
|
|
49
48
|
type: :development
|
|
50
49
|
version_requirements: *id002
|
|
50
|
+
- !ruby/object:Gem::Dependency
|
|
51
|
+
name: rr
|
|
52
|
+
prerelease: false
|
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
54
|
+
none: false
|
|
55
|
+
requirements:
|
|
56
|
+
- - ~>
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
hash: 15
|
|
59
|
+
segments:
|
|
60
|
+
- 1
|
|
61
|
+
- 0
|
|
62
|
+
version: "1.0"
|
|
63
|
+
type: :development
|
|
64
|
+
version_requirements: *id003
|
|
51
65
|
description: Ruby library to interact with HipChat
|
|
52
66
|
email: dgleal@gmail.com
|
|
53
67
|
executables: []
|