hipchat 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2ec52d652412c7540c45f243508e99f5a155ec1
4
- data.tar.gz: 0082b930a02ab0a0fac1d46d7181a7cd64202634
3
+ metadata.gz: 6073dc06bef01e6ad218249ec887d775fa89e8e2
4
+ data.tar.gz: 4b10a0deedf65b55dd331613d6dbc25a41809122
5
5
  SHA512:
6
- metadata.gz: 0470720c384fce9a0403b3df9fc930b98cd1047d496b783a62cb0fbbec8999bdd4998db5f76153f366450ffc91e2ec48f2a44cfaeb8181c9ebcf47d11dbc9fac
7
- data.tar.gz: 82098108cb71cffb51993058336b39072da7154ae8a579e7077365dc98a1dc6c22671a29f817f0fed68f8d5dd1bf60056ec44924a4b016a94ff6febb926e874e
6
+ metadata.gz: 66edf59e5fc4fc96fdbc43846648a76c48c48d32c3f13cbc0fdf9ce22bc15f72a8ebad3818dc716f80330498800cdbaa4e6296867e1a7b076ce057262ef20b47
7
+ data.tar.gz: 226c2ea4a5447c1726bb20b5727c60112f9e1f214b29786bd8db31ec2874f7efd951fcd75ff67fa737657f4041a15c6d892c9f00aebef9764882b8cc357fdd41
@@ -3,4 +3,4 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - 2.1.0
6
+ - 2.1
@@ -20,7 +20,7 @@ bc.. client = HipChat::Client.new(api_token)
20
20
  client['my room'].send('username', 'I talk')
21
21
 
22
22
  # Send notifications to users (default false)
23
- client['my room'].send('username', 'I quit!', :notify => 1)
23
+ client['my room'].send('username', 'I quit!', :notify => true)
24
24
 
25
25
  # Color it red. or "yellow", "green", "purple", "random" (default "yellow")
26
26
  client['my room'].send('username', 'Build failed!', :color => 'red')
@@ -82,9 +82,46 @@ client['my room'].invite("USER_ID_OR_NAME", options = {})
82
82
  # Sends a user a private message. Valid value for user are user id or email address
83
83
  client.user('foo@bar.org').send('I can send private messages')
84
84
 
85
- h2. Capistrano
85
+ h2. Custom Server URL
86
86
 
87
- *APIv1 ONLY, use APIv1 Key*
87
+ bc.. client = HipChat::Client.new(api_token, :api_version => 'v2', :server_url => 'https://domain.com')
88
+ # 'username' is the name for which the message will be presented as from
89
+ client['my room'].send('username', 'I talk')
90
+
91
+ # Send notifications to users (default false)
92
+ client['my room'].send('username', 'I quit!', :notify => true)
93
+
94
+ # Color it red. or "yellow", "green", "purple", "random" (default "yellow")
95
+ client['my room'].send('username', 'Build failed!', :color => 'red')
96
+
97
+ # Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/apiv2/method/send_room_notification)
98
+ client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
99
+
100
+ # Update the topic of a room in HipChat (see https://www.hipchat.com/docs/apiv2/method/set_topic)
101
+ client['my room'].topic('Free Ice Cream in the kitchen')
102
+
103
+ # Change the from field for a topic update (default "API")
104
+ client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')
105
+
106
+ # Get history from a room
107
+ client['my room'].history()
108
+
109
+ # Get history for a date in time with a particular timezone (default is latest 75 messages, timezone default is 'UTC')
110
+ client['my room'].history(:date => '2010-11-19', :timezone => 'PST')
111
+
112
+ # Create a new room (see https://www.hipchat.com/docs/apiv2/method/create_room)
113
+ client.create_room("Name", options = {})
114
+
115
+ # Get room data (see https://www.hipchat.com/docs/apiv2/method/get_room)
116
+ client['my room'].get_room
117
+
118
+ # Invite user to room (see https://www.hipchat.com/docs/apiv2/method/invite_user)
119
+ client['my room'].invite("USER_ID_OR_NAME", options = {})
120
+
121
+ # Sends a user a private message. Valid value for user are user id or email address
122
+ client.user('foo@bar.org').send('I can send private messages')
123
+
124
+ h2. Capistrano
88
125
 
89
126
  Capfile
90
127
 
@@ -101,6 +138,9 @@ set :hipchat_color, 'yellow' #normal message color
101
138
  set :hipchat_success_color, 'green' #finished deployment message color
102
139
  set :hipchat_failed_color, 'red' #cancelled deployment message color
103
140
  set :hipchat_message_format, 'html' # Sets the deployment message format, see https://www.hipchat.com/docs/api/method/rooms/message
141
+ set :hipchat_options, {
142
+ :api_version => "v2" # Set "v2" to send messages with API v2
143
+ }
104
144
 
105
145
  h3. Who did it?
106
146
 
@@ -13,14 +13,15 @@ module HipChat
13
13
 
14
14
  class Client < ApiVersion
15
15
 
16
- def initialize(version = 'v1')
17
- @version = !version.nil? ? version : 'v1'
16
+ def initialize(options = {})
17
+ # puts options.inspect
18
+ @version = options[:api_version]
18
19
  if @version.eql?('v1')
19
- @base_uri = "https://api.hipchat.com/v1"
20
+ @base_uri = "#{options[:server_url]}/v1"
20
21
  @headers = {'Accept' => 'application/json',
21
22
  'Content-Type' => 'application/x-www-form-urlencoded'}
22
23
  else
23
- @base_uri = "https://api.hipchat.com/v2"
24
+ @base_uri = "#{options[:server_url]}/v2"
24
25
  @headers = {'Accept' => 'application/json',
25
26
  'Content-Type' => 'application/json'}
26
27
  end
@@ -65,15 +66,15 @@ module HipChat
65
66
 
66
67
  class Room < ApiVersion
67
68
 
68
- def initialize(room_id, version = 'v1')
69
- @room_id = room_id
70
- @version = !version.nil? ? version : 'v1'
69
+ def initialize(options = {})
70
+ @room_id = options[:room_id]
71
+ @version = options[:api_version]
71
72
  if @version.eql?('v1')
72
- @base_uri = "https://api.hipchat.com/v1/rooms"
73
+ @base_uri = "#{options[:server_url]}/v1/rooms"
73
74
  @headers = {'Accept' => 'application/json',
74
75
  'Content-Type' => 'application/x-www-form-urlencoded'}
75
76
  else
76
- @base_uri = "https://api.hipchat.com/v2/room"
77
+ @base_uri = "#{options[:server_url]}/v2/room"
77
78
  @headers = {'Accept' => 'application/json',
78
79
  'Content-Type' => 'application/json'}
79
80
  end
@@ -140,10 +141,10 @@ module HipChat
140
141
 
141
142
  class User
142
143
 
143
- def initialize(user_id, version)
144
+ def initialize(user_id, options)
144
145
  @user_id = user_id
145
- raise InvalidApiVersion, "user API calls invalid for API v1" if ! version.eql?('v2')
146
- @base_uri = "https://api.hipchat.com/v2/user"
146
+ raise InvalidApiVersion, "user API calls invalid for API v1" if ! options[:api_version].eql?('v2')
147
+ @base_uri = "#{options[:server_url]}/v2/user"
147
148
  @headers = {'Accept' => 'application/json',
148
149
  'Content-Type' => 'application/json'}
149
150
  end
@@ -3,17 +3,17 @@ require 'hipchat'
3
3
  namespace :hipchat do
4
4
 
5
5
  task :notify_deploy_started do
6
- send_message("#{human} is deploying #{deployment_name} to #{environment_name}.", send_options)
6
+ send_message("#{human} is deploying #{deployment_name} to #{environment_string}.", send_options)
7
7
  end
8
8
 
9
9
  task :notify_deploy_finished do
10
10
  send_options.merge!(:color => success_message_color)
11
- send_message("#{human} finished deploying #{deployment_name} to #{environment_name}.", send_options)
11
+ send_message("#{human} finished deploying #{deployment_name} to #{environment_string}.", send_options)
12
12
  end
13
13
 
14
14
  task :notify_deploy_reverted do
15
15
  send_options.merge!(:color => failed_message_color)
16
- send_message("#{human} cancelled deployment of #{deployment_name} to #{environment_name}.", send_options)
16
+ send_message("#{human} cancelled deployment of #{deployment_name} to #{environment_string}.", send_options)
17
17
  end
18
18
 
19
19
  def send_options
@@ -27,8 +27,9 @@ namespace :hipchat do
27
27
  def send_message(message, options)
28
28
  hipchat_token = fetch(:hipchat_token)
29
29
  hipchat_room_name = fetch(:hipchat_room_name)
30
+ hipchat_options = fetch(:hipchat_options, {})
30
31
 
31
- hipchat_client = fetch(:hipchat_client, HipChat::Client.new(hipchat_token))
32
+ hipchat_client = fetch(:hipchat_client, HipChat::Client.new(hipchat_token, hipchat_options))
32
33
 
33
34
  if hipchat_room_name.is_a?(String)
34
35
  rooms = [hipchat_room_name]
@@ -48,6 +49,14 @@ namespace :hipchat do
48
49
  }
49
50
  end
50
51
 
52
+ def environment_string
53
+ if fetch(:stage)
54
+ "#{fetch(:stage)} (#{environment_name})"
55
+ else
56
+ environment_name
57
+ end
58
+ end
59
+
51
60
  def deployment_name
52
61
  if fetch(:branch, nil)
53
62
  application = fetch(:application)
@@ -63,7 +72,7 @@ namespace :hipchat do
63
72
  end
64
73
 
65
74
  def message_color
66
- fetch(:hipchat_color)
75
+ fetch(:hipchat_color, 'yellow')
67
76
  end
68
77
 
69
78
  def success_message_color
@@ -58,7 +58,8 @@ Capistrano::Configuration.instance(:must_exist).load do
58
58
  end
59
59
 
60
60
  def send(message, options)
61
- set :hipchat_client, HipChat::Client.new(hipchat_token) if fetch(:hipchat_client, nil).nil?
61
+ hipchat_options = fetch(:hipchat_options, {})
62
+ set :hipchat_client, HipChat::Client.new(hipchat_token, hipchat_options) if fetch(:hipchat_client, nil).nil?
62
63
 
63
64
  if hipchat_room_name.is_a?(String)
64
65
  rooms = [hipchat_room_name]
@@ -9,8 +9,10 @@ module HipChat
9
9
 
10
10
  def initialize(token, options={})
11
11
  @token = token
12
+ default_options = { api_version: 'v1', server_url: 'https://api.hipchat.com' }
13
+ @options = default_options.merge options
12
14
  @api_version = options[:api_version]
13
- @api = HipChat::ApiVersion::Client.new(@api_version)
15
+ @api = HipChat::ApiVersion::Client.new(@options)
14
16
  self.class.base_uri(@api.base_uri)
15
17
  http_proxy = options[:http_proxy] || ENV['http_proxy']
16
18
  setup_proxy(http_proxy) if http_proxy
@@ -21,7 +23,7 @@ module HipChat
21
23
  end
22
24
 
23
25
  def [](name)
24
- Room.new(@token, :room_id => name, :api_version => @api_version)
26
+ Room.new(@token, { room_id: name }.merge(@options))
25
27
  end
26
28
 
27
29
  def create_room(name, options={})
@@ -35,7 +37,7 @@ module HipChat
35
37
  unless options[:guest_access].nil?
36
38
  options[:guest_access] = @api.bool_val(options[:guest_access])
37
39
  end
38
-
40
+
39
41
  response = self.class.post(@api.create_room_config[:url],
40
42
  :query => { :auth_token => @token },
41
43
  :body => {
@@ -57,7 +59,7 @@ module HipChat
57
59
  end
58
60
 
59
61
  def user(name)
60
- User.new(@token, :user_id => name, :api_version => @api_version)
62
+ User.new(@token, { :user_id => name }.merge(@options))
61
63
  end
62
64
 
63
65
  def users
@@ -94,18 +96,19 @@ module HipChat
94
96
  def _users
95
97
  response = self.class.get(@api.users_config[:url],
96
98
  :query => {
97
- :auth_token => @token
99
+ :auth_token => @token,
100
+ :expand => 'items'
98
101
  },
99
102
  :headers => @api.headers
100
103
  )
101
104
  case response.code
102
105
  when 200
103
106
  response[@api.users_config[:data_key]].map do |r|
104
- Room.new(@token, r.merge(:api_version => @api_version, :user_id => r['id']))
107
+ User.new(@token, r.merge(:api_version => @api_version, :user_id => r['id']))
105
108
  end
106
109
  else
107
110
  raise UnknownResponseCode, "Unexpected #{response.code} for room"
108
111
  end
109
- end
112
+ end
110
113
  end
111
- end
114
+ end
@@ -14,7 +14,8 @@ namespace :hipchat do
14
14
  :room => ENV['ROOM'],
15
15
  :color => ENV['COLOR'],
16
16
  :token => ENV['TOKEN'],
17
- :api_version => ENV['API_VERSION']
17
+ :api_version => ENV['API_VERSION'],
18
+ :server_url => ENV['SERVER_URL']
18
19
  }.reject { |k, v| v.blank? }
19
20
 
20
21
  system_options = {
@@ -10,8 +10,7 @@ module HipChat
10
10
 
11
11
  def initialize(token, params)
12
12
  @token = token
13
- @api = HipChat::ApiVersion::Room.new(params[:room_id],
14
- params.delete(:api_version))
13
+ @api = HipChat::ApiVersion::Room.new(params)
15
14
  self.class.base_uri(@api.base_uri)
16
15
  super(params)
17
16
  end
@@ -190,4 +189,4 @@ module HipChat
190
189
  end
191
190
  end
192
191
  end
193
- end
192
+ end
@@ -11,7 +11,7 @@ module HipChat
11
11
  def initialize(token, params)
12
12
  @token = token
13
13
  @api = HipChat::ApiVersion::User.new(params[:user_id],
14
- params.delete(:api_version))
14
+ params)
15
15
  self.class.base_uri(@api.base_uri)
16
16
  super(params)
17
17
  end
@@ -38,25 +38,23 @@ module HipChat
38
38
  raise UnknownResponseCode, "Unexpected #{response.code} for private message to `#{user_id}'"
39
39
  end
40
40
  end
41
-
41
+
42
42
  #
43
43
  # Get a user's details.
44
44
  #
45
45
  def view
46
46
  puts "#{@api.base_uri}#{@api.view_config[:url]}"
47
- response = self.class.post(@api.view_config[:url],
47
+ response = self.class.get(@api.view_config[:url],
48
48
  :query => { :auth_token => @token },
49
49
  :headers => @api.headers
50
50
  )
51
51
 
52
52
  case response.code
53
53
  when 200
54
- response[@api.users_config[:data_key]].map do |r|
55
- User.new(@token, r.merge(:api_version => @api_version))
56
- end
54
+ User.new(@token, response.merge(:api_version => 'v2'))
57
55
  else
58
56
  raise UnknownResponseCode, "Unexpected #{response.code} for view message to `#{user_id}'"
59
57
  end
60
58
  end
61
59
  end
62
- end
60
+ end
@@ -1,3 +1,3 @@
1
1
  module HipChat
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hipchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HipChat/Atlassian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-11 00:00:00.000000000 Z
11
+ date: 2014-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty