Class: SearchApi::InstagramProfileRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/searchapi/instagram_profile_request.rb

Constant Summary

Constants inherited from Request

Request::BASE_URI

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from SearchApi::Request

Instance Method Details

#profile(username, options = nil, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/searchapi/instagram_profile_request.rb', line 4

def profile( username, options = nil, &block )
  if options
    options = options.is_a?( InstagramProfileOptions ) ? options : InstagramProfileOptions.build!( options.to_h )
    options = options.to_h
  else
    options = { engine: 'instagram_profile' }
  end
  options[ :username ] = username.to_s

  response = get( "#{ BASE_URI }/search", options, &block )
  attributes = ( JSON.parse( response.body, symbolize_names: true ) rescue nil )

  result = if response.success?
    InstagramProfileResult.new( attributes || {} )
  else
    ErrorResult.new( response.status, attributes )
  end

  ResponseMethods.install( response, result )
end