Class: HipChat::ApiVersion::User

Inherits:
Object
  • Object
show all
Defined in:
lib/hipchat/api_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ User

Returns a new instance of User.



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/hipchat/api_version.rb', line 273

def initialize(options)
  @version = options[:api_version]
  options[:user_id] ||= options[get_id_attribute]
  @user_id = options[:user_id]
  if @version.eql?('v1')
    @base_uri = "#{options[:server_url]}/v1/users"
    @headers = {'Accept' => 'application/json',
                'Content-Type' => 'application/x-www-form-urlencoded'}
  else
    @base_uri = "#{options[:server_url]}/v2/user"
    @headers = {'Accept' => 'application/json',
                'Content-Type' => 'application/json'}
  end
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



288
289
290
# File 'lib/hipchat/api_version.rb', line 288

def base_uri
  @base_uri
end

#headersObject (readonly)

Returns the value of attribute headers.



288
289
290
# File 'lib/hipchat/api_version.rb', line 288

def headers
  @headers
end

#user_idObject (readonly)

Returns the value of attribute user_id.



288
289
290
# File 'lib/hipchat/api_version.rb', line 288

def user_id
  @user_id
end

#versionObject (readonly)

Returns the value of attribute version.



288
289
290
# File 'lib/hipchat/api_version.rb', line 288

def version
  @version
end

Instance Method Details

#delete_configObject



354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/hipchat/api_version.rb', line 354

def delete_config
  {
    'v1' => {
      :url => URI::escape('/delete'),
      :body_format => :to_json,
      :query_params => { :user_id => user_id }
    },
    'v2' => {
      :url => URI::escape("/#{user_id}"),
      :body_format => :to_json,
      :query_params => {}
    }
  }[version]
end

#get_id_attributeObject



290
291
292
# File 'lib/hipchat/api_version.rb', line 290

def get_id_attribute
  version.eql?('v1') ? 'user_id' : 'id'
end

#history_configObject

Raises:



369
370
371
372
373
374
375
376
377
# File 'lib/hipchat/api_version.rb', line 369

def history_config
  raise InvalidApiVersion, 'This functionality is not supported in API v1' unless version.eql?('v2')

  {
    :url => URI::escape("/#{user_id}/history/latest"),
    :body_format => :to_json,
    :allowed_params => [:'max-results', :timezone, :'not-before']
  }
end

#send_configObject

Raises:



294
295
296
297
298
299
300
301
# File 'lib/hipchat/api_version.rb', line 294

def send_config
  raise InvalidApiVersion, 'This functionality is not supported in API v1' unless version.eql?('v2')

  {
    :url => URI::escape("/#{user_id}/message"),
    :body_format => :to_json
  }
end

#send_file_configObject



303
304
305
306
307
308
# File 'lib/hipchat/api_version.rb', line 303

def send_file_config
  {
    :url => URI::escape("/#{user_id}/share/file"),
    :body_format => :to_json
  }
end

#user_joined_rooms_configObject

Raises:



325
326
327
328
329
330
331
332
333
334
335
# File 'lib/hipchat/api_version.rb', line 325

def user_joined_rooms_config
  raise InvalidApiVersion, 'This functionality is not supported in API v1' unless version.eql?('v2')

  {
    'v2' => {
      :url => URI::escape("/#{user_id}/preference/auto-join"),
      :body_format => :to_json,
      :query_params => {}
    }
  }[version]
end

#user_update_configObject

Same signature as view_config but separating code to keep any future changes safe



338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/hipchat/api_version.rb', line 338

def user_update_config
  {
    'v1' => {
      :url => URI::escape('/show'),
      :body_format => :to_json,
      :query_params => { :user_id => user_id }
    },
    'v2' => {
      :url => URI::escape("/#{user_id}"),
      :body_format => :to_json,
      :query_params => {}
    }
  }[version]
end

#view_configObject



310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/hipchat/api_version.rb', line 310

def view_config
  {
    'v1' => {
      :url => URI::escape('/show'),
      :body_format => :to_json,
      :query_params => { :user_id => user_id }
    },
    'v2' => {
      :url => URI::escape("/#{user_id}"),
      :body_format => :to_json,
      :query_params => {}
    }
  }[version]
end