hiptail 0.0.2 → 0.0.3

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: c40f2b86adfb078fdfb6c2ab65914df13d287662
4
- data.tar.gz: e86ecd9975dc49d3f4cff0ebe9ae534b6b8d7d12
3
+ metadata.gz: 080df2b0b73328a9b0604413adfeefc8292fc9aa
4
+ data.tar.gz: fd4008027616aeda25d04578e75f9c4f0bdd7109
5
5
  SHA512:
6
- metadata.gz: 99118dd455c9787bf37dfc8dcbbefc3cb519ae55602c6f09c32c8424fd832eab7a870e0a99221354f1e568b162d5b1567663713935c49bf33697d08dbf4b6d7a
7
- data.tar.gz: 1783b1cd1b84b0867c25da66b26f953d5f2a4e706e82d8c240691f242fbb25b8bee7cab3a76f60caea53ee834811e1f7c6c01ddb6d64607fbcc49949bae86ccb
6
+ metadata.gz: a84d101dcce6ac0ea5bda7b3bcda1c963a21792223dd086fed53020f1fb149b995301d8facbc6ae00a50a8d6edf7acd2827e81470d6634f6e5cda1fa3b532c5a
7
+ data.tar.gz: 069b76c1859dd8981b6149487b8a581dfb7699d3fdaf2182d28c17ba8f5554d11a854bcaf9ae2087adac441dbb9497d9c9673d6666a2d6a0d562afa205e272ee
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.3
2
+ * Use :ascii_only flag of JSON.generate. (thx to kimoto)
3
+
1
4
  ## 0.0.2
2
5
  * Support room_topic_message event.
3
6
  * Change default vendor name / url.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # HipTail
2
2
 
3
- HipChat Add-on Framework
3
+ HipChat Integration (Add-on) Framework
4
4
 
5
5
  ## Installation
6
6
 
@@ -5,5 +5,5 @@
5
5
  $ bundle install
6
6
  $ bundle exec -- rackup
7
7
 
8
- Then install this add-on on integrations page in HipChat administration page.
8
+ Then install this integration on integrations page in HipChat administration page.
9
9
  Specify the application capability URL (e.g. http://example.com:4567/cap).
@@ -5,5 +5,5 @@
5
5
  $ bundle install
6
6
  $ bundle exec -- rackup
7
7
 
8
- Then install this add-on on integrations page in HipChat administration page.
8
+ Then install this integration on integrations page in HipChat administration page.
9
9
  Specify the application capability URL (e.g. http://example.com:9292/cap).
@@ -5,5 +5,5 @@
5
5
  $ bundle install
6
6
  $ bundle exec -- rackup
7
7
 
8
- Then install this add-on on integrations page in HipChat administration page.
8
+ Then install this integration on integrations page in HipChat administration page.
9
9
  Specify the application capability URL (e.g. http://example.com:9292/cap).
data/hiptail.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = HipTail::VERSION
9
9
  spec.authors = ["ITO Nobuaki"]
10
10
  spec.email = ["daydream.trippers@gmail.com"]
11
- spec.summary = %q{HipChat Add-on Framework}
12
- spec.description = %q{HipChat Add-on Framework}
11
+ spec.summary = %q{HipChat Integration (Add-on) Framework}
12
+ spec.description = %q{HipChat Integration (Add-on) Framework}
13
13
  spec.homepage = "https://github.com/dayflower/hiptail"
14
14
  spec.license = "MIT"
15
15
 
@@ -96,7 +96,8 @@ module HipTail
96
96
  # @return [HipTail::Rooms]
97
97
  def get_all_rooms(params = {})
98
98
  res = call_api(:method => :get, :uri => @api_base.merge("room"), :query_params => params)
99
- Rooms.new(res)
99
+ return unless res.successful?
100
+ Rooms.new(res.data)
100
101
  end
101
102
 
102
103
  # Issues get room API.
@@ -107,27 +108,30 @@ module HipTail
107
108
  room_id = self.room_id || params.delete(:room_id)
108
109
  raise ArgumentError.new("room_id required") unless room_id
109
110
  res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}"), :query_params => params)
110
- Room::Detail.new(res)
111
+ return unless res.successful?
112
+ Room::Detail.new(res.data)
111
113
  end
112
114
 
113
115
  # Issues get all members API.
114
116
  # @param [Hash] params Parameters for get all members API.
115
117
  # @return [HipTail::Users]
116
- def get_all_members(params)
118
+ def get_all_members(params = {})
117
119
  room_id = self.room_id || params.delete(:room_id)
118
120
  raise ArgumentError.new("room_id required") unless room_id
119
121
  res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}/member"), :query_params => params)
120
- Users.new(res)
122
+ return unless res.successful?
123
+ Users.new(res.data)
121
124
  end
122
125
 
123
126
  # Issues get all participants API.
124
127
  # @param [Hash] params Parameters for get all participants API.
125
128
  # @return [HipTail::Users]
126
- def get_all_participants(params)
129
+ def get_all_participants(params = {})
127
130
  room_id = self.room_id || params.delete(:room_id)
128
131
  raise ArgumentError.new("room_id required") unless room_id
129
132
  res = call_api(:method => :get, :uri => @api_base.merge("room/#{room_id}/participant"), :query_params => params)
130
- Users.new(res)
133
+ return unless res.successful?
134
+ Users.new(res.data)
131
135
  end
132
136
 
133
137
  # Issues add member API.
@@ -164,6 +168,27 @@ module HipTail
164
168
  call_api(:method => :delete, :uri => @api_base.merge("room/#{room_id}/member/#{user_name}"), :body_params => params)
165
169
  end
166
170
 
171
+ # Issues view user API.
172
+ # @param [Hash] params Parameters for view user API with :user_id.
173
+ # @option params [String] :user_id User ID or email or mention name (beginning with an '@').
174
+ # @return [HipTail::User]
175
+ def view_user(params)
176
+ user_id = params.delete(:user_id)
177
+ raise ArgumentError.new("user_id required") unless user_id
178
+ res = call_api(:method => :get, :uri => @api_base.merge("user/#{user_id}"), :query_params => params)
179
+ return unless res.successful?
180
+ User::Person.new(res.data)
181
+ end
182
+
183
+ # Issues get all users API.
184
+ # @param [Hash] params Parameters for get all users API.
185
+ # @return [HipTail::Users]
186
+ def get_all_users(params = {})
187
+ res = call_api(:method => :get, :uri => @api_base.merge("user"), :query_params => params)
188
+ return unless res.successful?
189
+ Users.new(res.data)
190
+ end
191
+
167
192
  private
168
193
 
169
194
  def user_name_from_params(params)
@@ -190,7 +215,7 @@ module HipTail
190
215
  }
191
216
 
192
217
  if args[:body_params]
193
- body = JSON.generate(args[:body_params] || {})
218
+ body = JSON.generate(args[:body_params] || {}, :ascii_only => true)
194
219
  headers['Content-Length'] = body.bytesize.to_s
195
220
  else
196
221
  body = nil
@@ -215,11 +240,24 @@ module HipTail
215
240
  http.request(req)
216
241
  end
217
242
 
243
+ def res.successful?
244
+ self.is_a?(Net::HTTPSuccess)
245
+ end
246
+
218
247
  if res.content_type =~ %r{\A application/json}x
219
- return JSON.parse(res.body)
248
+ body_data = JSON.parse(res.body)
220
249
  else
221
- return {}
250
+ body_data = {}
222
251
  end
252
+
253
+ res_class = class << res; self; end
254
+ res_class.class_eval do
255
+ define_method(:data) do
256
+ body_data
257
+ end
258
+ end
259
+
260
+ res
223
261
  end
224
262
 
225
263
  def token
data/lib/hiptail/util.rb CHANGED
@@ -5,13 +5,13 @@ module HipTail
5
5
 
6
6
  # Build capability object.
7
7
  # @param [Hash] params
8
- # @option params [String] :key Identical key for add-on
9
- # @option params [String] :name Add-on name
10
- # @option params [String] :base_url Base URL for add-on
8
+ # @option params [String] :key Identical key for integration
9
+ # @option params [String] :name integration name
10
+ # @option params [String] :base_url Base URL for integration
11
11
  # @option params [String] :capability_url URL for capability
12
12
  # @option params [String] :webhook_url URL for event webhook
13
13
  # @option params [String] :installed_url URL for installed / uninstalled event webhook
14
- # @option params [String] :description (same as :name) Add-on description (optional)
14
+ # @option params [String] :description (same as :name) integration description (optional)
15
15
  # @option params [String] :vendor_name (same as :name) Vendor name (optional)
16
16
  # @option params [String] :vendor_url (same as :base_url) Vendor URL (optional)
17
17
  # @option params [String] :homepage_url (same as :base_url) Homepage (optional)
@@ -1,3 +1,3 @@
1
1
  module HipTail
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -46,13 +46,13 @@ module HipTail
46
46
  # Handles retrieving capability request.
47
47
  # @param [Rack::Request] request
48
48
  # @param [Hash] params Capability parameters
49
- # @option params [String] :key Identical key for add-on
50
- # @option params [String] :name Add-on name
51
- # @option params [String] :base_url Base URL for add-on
49
+ # @option params [String] :key Identical key for integration
50
+ # @option params [String] :name integration name
51
+ # @option params [String] :base_url Base URL for integration
52
52
  # @option params [String] :capability_url URL for capability
53
53
  # @option params [String] :webhook_url URL for event webhook
54
54
  # @option params [String] :installed_url URL for installed / uninstalled event webhook
55
- # @option params [String] :description (same as :name) Add-on description (optional)
55
+ # @option params [String] :description (same as :name) integration description (optional)
56
56
  # @option params [String] :vendor_name (same as :name) Vendor name (optional)
57
57
  # @option params [String] :vendor_url (same as :base_url) Vendor URL (optional)
58
58
  # @option params [String] :homepage_url (same as :base_url) Homepage (optional)
@@ -85,10 +85,7 @@ module HipTail
85
85
  # @param [Hash] data
86
86
  # @param [Integer] status (200)
87
87
  def create_response(data, status = 200)
88
- body = JSON.generate(data)
89
-
90
- body.gsub!(/[\u{007f}-\u{10ffff}]+/) { |match| match.unpack("U*").map! { |i| "\\u#{i.to_s(16)}" }.join }
91
-
88
+ body = JSON.generate(data, :ascii_only => true)
92
89
  headers = {
93
90
  'Content-Type' => 'application/json; charset=UTF-8',
94
91
  'Content-Length' => body.bytesize.to_s,
@@ -8,17 +8,17 @@ module HipTail
8
8
 
9
9
  class Web::RackApp
10
10
  # @return [HipTail::Manager] Returns HipTail::Manager.
11
- attr_reader :manager
11
+ attr_reader :manager, :path
12
12
 
13
13
  # @param [Hash] params Capability parameters (and manager)
14
14
  # @option params [HipTail::Manager] :manager HipTail::Manager instance (optional)
15
- # @option params [String] :key Identical key for add-on
16
- # @option params [String] :name Add-on name
17
- # @option params [String] :base_url Base URL for add-on
15
+ # @option params [String] :key Identical key for integration
16
+ # @option params [String] :name integration name
17
+ # @option params [String] :base_url Base URL for integration
18
18
  # @option params [String] :capability_url URL for capability
19
19
  # @option params [String] :webhook_url URL for event webhook
20
20
  # @option params [String] :installed_url URL for installed / uninstalled event webhook
21
- # @option params [String] :description (same as :name) Add-on description (optional)
21
+ # @option params [String] :description (same as :name) integration description (optional)
22
22
  # @option params [String] :vendor_name (same as :name) Vendor name (optional)
23
23
  # @option params [String] :vendor_url (same as :base_url) Vendor URL (optional)
24
24
  # @option params [String] :homepage_url (same as :base_url) Homepage (optional)
@@ -38,19 +38,19 @@ module HipTail
38
38
  @capability_params = params
39
39
 
40
40
  base_url = URI.parse('http://example.com/').merge(params[:base_path])
41
- path = {
41
+ @path = {
42
42
  :base => base_url.request_uri,
43
43
  }
44
44
  [ :webhook, :installed, :capability ].each do |key|
45
- path[key] = base_url.merge('./' + params["#{key}_path".to_sym]).request_uri
45
+ @path[key] = base_url.merge('./' + params["#{key}_path".to_sym]).request_uri
46
46
  end
47
47
 
48
48
  @regex = {}
49
- @regex[:capability] = %r{\A #{Regexp.escape(path[:capability])} \z}xm
50
- @regex[:event] = %r{\A #{Regexp.escape(path[:webhook])} \z}xm
49
+ @regex[:capability] = %r{\A #{Regexp.escape(@path[:capability])} \z}xm
50
+ @regex[:event] = %r{\A #{Regexp.escape(@path[:webhook])} \z}xm
51
51
 
52
- @regex[:install] = %r{\A #{Regexp.escape(path[:installed])} \z}xm
53
- @regex[:uninstall] = %r{\A #{Regexp.escape(path[:installed])} / ([-0-9a-fA-F]+) \z}xm
52
+ @regex[:install] = %r{\A #{Regexp.escape(@path[:installed])} \z}xm
53
+ @regex[:uninstall] = %r{\A #{Regexp.escape(@path[:installed])} / ([-0-9a-fA-F]+) \z}xm
54
54
  end
55
55
 
56
56
  def call(env)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiptail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ITO Nobuaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
- description: HipChat Add-on Framework
69
+ description: HipChat Integration (Add-on) Framework
70
70
  email:
71
71
  - daydream.trippers@gmail.com
72
72
  executables: []
@@ -123,5 +123,5 @@ rubyforge_project:
123
123
  rubygems_version: 2.2.2
124
124
  signing_key:
125
125
  specification_version: 4
126
- summary: HipChat Add-on Framework
126
+ summary: HipChat Integration (Add-on) Framework
127
127
  test_files: []