Module: Peerindex::Client::User

Included in:
Peerindex::Client
Defined in:
lib/peerindex/client/user.rb

Overview

Defines methods related to users

Instance Method Summary collapse

Instance Method Details

#merge_user_into_options!(user_id_or_screen_name, options = {}) ⇒ Hash

Take a single user ID or screen name and merge it into an options hash with the correct key

Parameters:

  • user_id_or_screen_name (Integer, String)

    A Twitter user ID or screen_name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Returns:

  • (Hash)


48
49
50
51
52
53
54
55
56
57
# File 'lib/peerindex/client/user.rb', line 48

def merge_user_into_options!(user_id_or_screen_name, options={})
  case user_id_or_screen_name
  when Fixnum
    options[:id] = user_id_or_screen_name
  when String
    options[:id] = user_id_or_screen_name
  end
  options[:api_key] = self.api_key
  options
end

#user(user, options = {}) ⇒ Hashie::Mash

Returns extended information of a given user

Returns The requested user.

Examples:

Return extended information for @sferik

Peerindex.user("sferik")
Peerindex.user(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :include_entities (Boolean, String, Integer)

    Include Tweet Entities when set to true, 't' or 1.

Returns:

  • (Hashie::Mash)

    The requested user.

See Also:

Rate Limited?:

  • Yes

Requires Authentication?:

  • No

Response Formats:

  • json

  • xml



20
21
22
23
24
# File 'lib/peerindex/client/user.rb', line 20

def user(user, options={})
  merge_user_into_options!(user, options)
  response = get('version/profile/show', options)
  format.to_s.downcase == 'xml' ? response['user'] : response
end

#user?(user, options = {}) ⇒ Boolean

Returns true if the specified user exists

Examples:

Return true if @sferik exists

Peerindex.user?("sferik")
Peerindex.user?(7505382)  # Same as above

Parameters:

  • user (Integer, String)

    A Twitter user ID or screen name.

Returns:

  • (Boolean)

    true if the user exists, otherwise false.

Rate Limited?:

  • Yes

Requires Authentication?:

  • No



35
36
37
38
39
40
41
# File 'lib/peerindex/client/user.rb', line 35

def user?(user, options={})
  merge_user_into_options!(user, options)
  get('version/profile/show', options, :format => :json, :raw => true)
  true
rescue Peerindex::NotFound
  false
end