Class: HipChat::ApiVersion::User
- Inherits:
-
Object
- Object
- HipChat::ApiVersion::User
- Defined in:
- lib/hipchat/api_version.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #delete_config ⇒ Object
- #get_id_attribute ⇒ Object
- #history_config ⇒ Object
-
#initialize(options) ⇒ User
constructor
A new instance of User.
- #send_config ⇒ Object
- #send_file_config ⇒ Object
- #user_joined_rooms_config ⇒ Object
-
#user_update_config ⇒ Object
Same signature as view_config but separating code to keep any future changes safe.
- #view_config ⇒ Object
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() @version = [:api_version] [:user_id] ||= [get_id_attribute] @user_id = [:user_id] if @version.eql?('v1') @base_uri = "#{[:server_url]}/v1/users" @headers = {'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded'} else @base_uri = "#{[:server_url]}/v2/user" @headers = {'Accept' => 'application/json', 'Content-Type' => 'application/json'} end end |
Instance Attribute Details
#base_uri ⇒ Object (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 |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
288 289 290 |
# File 'lib/hipchat/api_version.rb', line 288 def headers @headers end |
#user_id ⇒ Object (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 |
#version ⇒ Object (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_config ⇒ Object
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_attribute ⇒ Object
290 291 292 |
# File 'lib/hipchat/api_version.rb', line 290 def get_id_attribute version.eql?('v1') ? 'user_id' : 'id' end |
#history_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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 |