hipchat 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -20,6 +20,14 @@ client['my room'].send('username', 'Build failed!', :color => 'red')
20
20
  # Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/api/method/rooms/message)
21
21
  client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
22
22
 
23
+ # Update the topic of a room in HipChat (see https://www.hipchat.com/docs/api/method/rooms/topic)
24
+ client['my room'].topic('Free Ice Cream in the kitchen')
25
+
26
+ # Change the from field for a topic update (default "API")
27
+ client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')
28
+
29
+
30
+
23
31
  h2. Capistrano
24
32
 
25
33
  bc.. require 'hipchat/capistrano'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.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.6.1"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["HipChat/Atlassian"]
12
- s.date = %q{2012-11-06}
12
+ s.date = %q{2012-11-10}
13
13
  s.description = %q{Ruby library to interact with HipChat}
14
14
  s.email = %q{support@hipchat.com}
15
15
  s.extra_rdoc_files = [
data/lib/hipchat.rb CHANGED
@@ -90,5 +90,40 @@ module HipChat
90
90
  raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
91
91
  end
92
92
  end
93
+
94
+ # Change this room's topic
95
+ #
96
+ # Usage:
97
+ #
98
+ # # Default
99
+ # topic 'my awesome topic'
100
+ #
101
+ # Options:
102
+ #
103
+ # +from+:: the name of the person changing the topic
104
+ # (default "API")
105
+ def topic(new_topic, options = {})
106
+
107
+ options = { :from => 'API' }.merge options
108
+
109
+ response = self.class.post('/topic',
110
+ :query => { :auth_token => @token },
111
+ :body => {
112
+ :room_id => room_id,
113
+ :from => options[:from],
114
+ :topic => new_topic
115
+ }
116
+ )
117
+
118
+ case response.code
119
+ when 200; true
120
+ when 404
121
+ raise UnknownRoom, "Unknown room: `#{room_id}'"
122
+ when 401
123
+ raise Unauthorized, "Access denied to room `#{room_id}'"
124
+ else
125
+ raise UnknownResponseCode, "Unexpected #{response.code} for room `#{room_id}'"
126
+ end
127
+ end
93
128
  end
94
129
  end
data/spec/hipchat_spec.rb CHANGED
@@ -20,6 +20,56 @@ describe HipChat do
20
20
  }
21
21
  end
22
22
 
23
+ def mock_successful_topic_change(topic, options={})
24
+ options = {:from => 'API'}.merge(options)
25
+ mock(HipChat::Room).post("/topic",
26
+ :query => {:auth_token => "blah"},
27
+ :body => {:room_id => "Hipchat",
28
+ :from => options[:from],
29
+ :topic => "Nice topic" } ) {
30
+ OpenStruct.new(:code => 200)
31
+ }
32
+ end
33
+
34
+ describe "#topic" do
35
+ it "is successful without custom options" do
36
+ mock_successful_topic_change("Nice topic")
37
+
38
+ room.topic("Nice topic").should be_true
39
+ end
40
+
41
+ it "is successful with a custom from" do
42
+ mock_successful_topic_change("Nice topic", :from => "Me")
43
+
44
+ room.topic("Nice topic", :from => "Me").should be_true
45
+ end
46
+
47
+ it "fails when the room doesn't exist" do
48
+ mock(HipChat::Room).post(anything, anything) {
49
+ OpenStruct.new(:code => 404)
50
+ }
51
+
52
+ lambda { room.topic "" }.should raise_error(HipChat::UnknownRoom)
53
+ end
54
+
55
+ it "fails when we're not allowed to do so" do
56
+ mock(HipChat::Room).post(anything, anything) {
57
+ OpenStruct.new(:code => 401)
58
+ }
59
+
60
+ lambda { room.topic "" }.should raise_error(HipChat::Unauthorized)
61
+ end
62
+
63
+ it "fails if we get an unknown response code" do
64
+ mock(HipChat::Room).post(anything, anything) {
65
+ OpenStruct.new(:code => 403)
66
+ }
67
+
68
+ lambda { room.topic "" }.
69
+ should raise_error(HipChat::UnknownResponseCode)
70
+ end
71
+ end
72
+
23
73
  describe "sends a message to a room" do
24
74
  it "successfully without custom options" do
25
75
  mock_successful_send 'Dude', 'Hello world'
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 1
9
- version: 0.6.1
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - HipChat/Atlassian
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-11-06 00:00:00 -08:00
17
+ date: 2012-11-10 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency