Class: InstagramBasicDisplay::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/instagram_basic_display/profile.rb

Overview

Module for interacting with an Instagram user’s profile. You can retrieve profile information

and media.

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Object

Constructor

Parameters:



32
33
34
# File 'lib/instagram_basic_display/profile.rb', line 32

def initialize(configuration)
  @configuration = configuration
end

Instance Method Details

#media_feed(user_id: nil, fields: %i[id media_url],, paginated_url: nil, **params) ⇒ Object

Method for retrieving a user’s media feed.

Parameters:

  • user_id (String) (defaults to: nil)

    the id of the user whose information you are retrieving. If no user_id is passed, the query will be made agains the user associated with the current auth token.

  • fields (Array<Symbol>) (defaults to: %i[id media_url],)

    array of fields to retrieve. Defaults to id and media_url. The full list of fields can be found in the Instagram documentation: developers.facebook.com/docs/instagram-basic-display-api/reference/media/

  • paginated_url (String) (defaults to: nil)

    a url to retrieve the next or previous set of results from the API. This url is provided by the response from Instagram.

  • params (Hash)

    any additional request parameters that should be passed to the API

Raises:



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/instagram_basic_display/profile.rb', line 84

def media_feed(user_id: nil, fields: %i[id media_url], paginated_url: nil, **params)
  check_for_auth_token!(params)

  uri = if paginated_url
          URI(paginated_url)
        else
          URI(base_profile_uri(user_id: user_id) + '/media')
        end

  params = {
    fields: fields.map(&:to_s).join(','),
    access_token: configuration.auth_token,
    **params
  }

  make_request(uri, params)
end

#media_node(media_id:, fields: %i[id media_url],, **params) ⇒ Object

Method for retrieving information for a particular media node (i.e. one image or video).

Parameters:

  • media_id (String)

    the id of the media you are querying for.

  • fields (Array<Symbol>) (defaults to: %i[id media_url],)

    array of fields to retrieve. Defaults to id and media_url. The full list of fields can be found in the Instagram documentation: developers.facebook.com/docs/instagram-basic-display-api/reference/media/

  • params (Hash)

    any additional request parameters that should be passed to the API

Raises:



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/instagram_basic_display/profile.rb', line 114

def media_node(media_id:, fields: %i[id media_url], **params)
  check_for_auth_token!(params)

  uri = URI("https://graph.instagram.com/#{media_id}")
  params = {
    fields: fields.map(&:to_s).join(','),
    access_token: configuration.auth_token,
    **params
  }

  make_request(uri, params)
end

#profile(user_id: nil, fields: %i[id username],, **params) ⇒ InstagramBasicDisplay::Response

Method for interacting with an Instagram user’s profile. Can be used to retrieve

information such as their id and username.

Parameters:

  • user_id (String) (defaults to: nil)

    the id of the user whose information you are retrieving. If no user_id is passed, the query will be made agains the user associated with the current auth token.

  • fields (Array<Symbol>) (defaults to: %i[id username],)

    array of fields to retrieve. Defaults to id and username. The full list of fields can be found in the Instagram documentation: developers.facebook.com/docs/instagram-basic-display-api/reference/user#fields

  • params (Hash)

    any additional request parameters that should be passed to the API.

Returns:

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/instagram_basic_display/profile.rb', line 54

def profile(user_id: nil, fields: %i[id username], **params)
  check_for_auth_token!(params)

  uri = URI(base_profile_uri(user_id: user_id))
  params = {
    fields: fields.map(&:to_s).join(','),
    access_token: configuration.auth_token,
    **params
  }

  make_request(uri, params)
end