Module: Instagram::Client::Users

Included in:
Instagram::Client
Defined in:
lib/instagram_api/client/users.rb

Overview

Methods for the Users API.

Instance Method Summary collapse

Instance Method Details

#feedHashie::Mash

Get the authenticated user’s feed.

Examples:

client.feed

Returns:

  • (Hashie::Mash)

    The user’s feed.

See Also:



49
50
51
# File 'lib/instagram_api/client/users.rb', line 49

def feed
  get '/users/self/feed', auth_params
end

#likedHashie::Mash

See the authenticated user’s list of media they’ve liked.

Returns:

  • (Hashie::Mash)

    List of media.

See Also:



70
71
72
# File 'lib/instagram_api/client/users.rb', line 70

def liked
  get '/users/self/media/liked', auth_params
end

#recent(id = nil) ⇒ Hashie::Mash

Get the most recent media published by a user.

Returns the recent media for the user for the ID passed in as a parameter. If no ID is specified, then returns the authenticated user’s recent media.

Parameters:

  • id (Integer) (defaults to: nil)

    The user’s ID.

Returns:

  • (Hashie::Mash)

    The user’s recent media.

See Also:



61
62
63
64
# File 'lib/instagram_api/client/users.rb', line 61

def recent(id=nil)
  id = "self" unless id
  get "/users/#{id}/media/recent", auth_params
end

#search(query = nil) ⇒ Hashie::Mash

Search for a user by username.

Examples:

Search for a user

client.search('caseyscarborough')

Parameters:

  • query (String) (defaults to: nil)

    The username to search for.

Returns:

  • (Hashie::Mash)

    The search results.

See Also:



39
40
41
# File 'lib/instagram_api/client/users.rb', line 39

def search(query=nil)
  get "/users/search", auth_params.merge(q: query)
end

#user(user = nil) ⇒ Hashie::Mash

Retrieve a single user’s information.

Examples:

Get user by ID

client.user(16500486)

Get user by username

client.user('caseyscarborough')

Get authentication user

client.user

Parameters:

  • user (String, Integer) (defaults to: nil)

    The user ID or username.

Returns:

  • (Hashie::Mash)

    The user’s data.

See Also:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/instagram_api/client/users.rb', line 20

def user(user=nil)
  case user
  when Integer
    get "/users/#{user}", auth_params
  when String
    results = search(user)
    get "/users/#{results.data[0].id}", auth_params
  when nil
    get '/users/self', auth_params
  end
end