Class: SocialMiner::Instagram::ProfileInfo

Inherits:
Base
  • Object
show all
Defined in:
lib/social_miner/instagram/profile_info.rb

Constant Summary collapse

URL =
"#{API_URL}/users/web_profile_info/".freeze

Constants inherited from Base

Base::API_URL, Base::DEFAULT_HEADERS, Base::GRAPHQL_URL, Base::SOURCE_URL

Instance Attribute Summary

Attributes inherited from Base

#request_headers

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from SocialMiner::Instagram::Base

Instance Method Details

#call(username:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/social_miner/instagram/profile_info.rb', line 8

def call(username:)
  uri = URI(URL)
  uri.query = URI.encode_www_form([
                                    [:username, username]
                                  ])

  response = Net::HTTP.get_response(uri, request_headers)

  case response
  when Net::HTTPSuccess
    response_data = JSON.parse(response.body)
    record = Helpers::Hash.fetch_nested(response_data, "data", "user")

    if block_given?
      yield(record)
    else
      SocialMiner.mapper_for_klass(self.class).map(record)
    end
  else
    raise Net::HTTPError.new("Request Failed #{response.code}", response)
  end
end