class HipChat::ApiVersion::User

Attributes

base_uri[R]
headers[R]
user_id[R]
version[R]

Public Class Methods

new(options) click to toggle source
# File lib/hipchat/api_version.rb, line 253
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

Public Instance Methods

delete_config() click to toggle source
# File lib/hipchat/api_version.rb, line 306
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() click to toggle source
# File lib/hipchat/api_version.rb, line 270
def get_id_attribute
  version.eql?('v1') ? 'user_id' : 'id'
end
history_config() click to toggle source
# File lib/hipchat/api_version.rb, line 321
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() click to toggle source
# File lib/hipchat/api_version.rb, line 274
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() click to toggle source
# File lib/hipchat/api_version.rb, line 283
def send_file_config
  {
    :url => URI::escape("/#{user_id}/share/file"),
    :body_format => :to_json
  }
end
view_config() click to toggle source
# File lib/hipchat/api_version.rb, line 290
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