class Pipl::Client::SearchResponse

Attributes

available_data[R]
available_sources[R]
demo_usage_allotted[R]
demo_usage_current[R]
demo_usage_expiry[R]
http_status_code[R]
match_requirements[R]
person[R]
person_count[R]
possible_persons[R]
qps_allotted[R]
qps_current[R]
qps_demo_allotted[R]
qps_demo_current[R]
qps_live_allotted[R]
qps_live_current[R]
query[R]
quota_allotted[R]
quota_current[R]
quota_reset[R]
raw_response[R]
search_id[R]
source_category_requirements[R]
sources[R]
visible_sources[R]
warnings[R]

Public Class Methods

deserialize(json_str, headers={}) click to toggle source
# File lib/pipl/response.rb, line 48
def self.deserialize(json_str, headers={})
  h = JSON.parse(json_str, symbolize_names: true)

  params = {}
  params[:query] = Pipl::Person.from_hash(h[:query]) if h.key? :query
  params[:person] = Pipl::Person.from_hash(h[:person]) if h.key? :person
  params[:sources] = h[:sources].map { |s| Pipl::Source.from_hash(s) } if h.key? :sources
  params[:possible_persons] = h[:possible_persons].map { |p| Pipl::Person.from_hash(p) } if h.key? :possible_persons
  params[:warnings] = h[:warnings]
  params[:visible_sources] = h[:@visible_sources]
  params[:available_sources] = h[:@available_sources]
  params[:search_id] = h[:@search_id]
  params[:http_status_code] = h[:@http_status_code]
  params[:raw_response] = json_str
  params[:match_requirements] = h[:match_requirements]
  params[:source_category_requirements] = h[:source_category_requirements]
  params[:available_data] = AvailableData.from_hash(h[:available_data]) if h.key? :available_data

  # person_count: API v4 doesn't send this in the response so we compute it here
  if h.key? :@person_count
    params[:person_count] = h[:@person_count]
  elsif h.key?(:person)
    params[:person_count] = 1
  elsif h.key?(:possible_persons)
    params[:person_count] = h[:possible_persons].length
  else
    params[:person_count] = 0
  end

  params.merge! Utils::extract_rate_limits(headers)

  self.new(params)
end
from_http_response(resp) click to toggle source
# File lib/pipl/response.rb, line 82
def self.from_http_response(resp)
  self.deserialize(resp.body, resp)
end
from_json(json_str) click to toggle source

Here for backward compatibility

# File lib/pipl/response.rb, line 87
def self.from_json(json_str)
  self.deserialize(json_str)
end
new(params={}) click to toggle source
# File lib/pipl/response.rb, line 19
def initialize(params={})
  @query = params[:query]
  @person = params[:person]
  @sources = params[:sources]
  @possible_persons = params[:possible_persons]
  @warnings = params[:warnings]
  @visible_sources = params[:visible_sources]
  @available_sources = params[:available_sources]
  @search_id = params[:search_id]
  @http_status_code = params[:http_status_code]
  @raw_response = params[:raw_response]
  @available_data = params[:available_data]
  @match_requirements = params[:match_requirements]
  @source_category_requirements = params[:source_category_requirements]
  @person_count = params[:person_count]
  @qps_allotted = params[:qps_allotted]
  @qps_current = params[:qps_current]
  @qps_live_allotted = params[:qps_live_allotted]
  @qps_live_current = params[:qps_live_current]
  @qps_demo_allotted = params[:qps_demo_allotted]
  @qps_demo_current = params[:qps_demo_current]
  @quota_allotted = params[:quota_allotted]
  @quota_current = params[:quota_current]
  @quota_reset = params[:quota_reset]
  @demo_usage_allotted = params[:demo_usage_allotted]
  @demo_usage_current = params[:demo_usage_current]
  @demo_usage_expiry = params[:demo_usage_expiry]
end

Public Instance Methods

address() click to toggle source
# File lib/pipl/response.rb, line 119
def address
  @person.address if @person
end
age() click to toggle source
# File lib/pipl/response.rb, line 111
def age
  @person.age if @person
end
education() click to toggle source
# File lib/pipl/response.rb, line 123
def education
  @person.education if @person
end
email() click to toggle source
# File lib/pipl/response.rb, line 143
def email
  @person.email if @person
end
ethnicity() click to toggle source
# File lib/pipl/response.rb, line 131
def ethnicity
  @person.ethnicity if @person
end
gender() click to toggle source
# File lib/pipl/response.rb, line 107
def gender
  @person.gender if @person
end
group_sources_by_category() click to toggle source
# File lib/pipl/response.rb, line 99
def group_sources_by_category
  @sources.group_by { |s| s.category } if @sources
end
group_sources_by_domain() click to toggle source
# File lib/pipl/response.rb, line 95
def group_sources_by_domain
  @sources.group_by { |s| s.domain } if @sources
end
group_sources_by_match() click to toggle source
# File lib/pipl/response.rb, line 103
def group_sources_by_match
  @sources.group_by { |s| s.match } if @sources
end
image() click to toggle source
# File lib/pipl/response.rb, line 151
def image
  @person.image if @person
end
job() click to toggle source
# File lib/pipl/response.rb, line 115
def job
  @person.job if @person
end
language() click to toggle source
# File lib/pipl/response.rb, line 127
def language
  @person.language if @person
end
matching_sources() click to toggle source
# File lib/pipl/response.rb, line 91
def matching_sources
  @sources.select { |s| s.match == 1.0 } if @sources
end
name() click to toggle source
# File lib/pipl/response.rb, line 147
def name
  @person.name if @person
end
origin_country() click to toggle source
# File lib/pipl/response.rb, line 135
def origin_country
  @person.origin_country if @person
end
phone() click to toggle source
# File lib/pipl/response.rb, line 139
def phone
  @person.phone if @person
end
relationship() click to toggle source
# File lib/pipl/response.rb, line 167
def relationship
  @person.relationship if @person
end
url() click to toggle source
# File lib/pipl/response.rb, line 155
def url
  @person.url if @person
end
user_id() click to toggle source
# File lib/pipl/response.rb, line 163
def user_id
  @person.user_id if @person
end
username() click to toggle source
# File lib/pipl/response.rb, line 159
def username
  @person.username if @person
end