Class: Pipl::Client::SearchResponse
- Inherits:
-
Object
- Object
- Pipl::Client::SearchResponse
- Defined in:
- lib/pipl/response.rb
Instance Attribute Summary collapse
-
#available_data ⇒ Object
readonly
Returns the value of attribute available_data.
-
#available_sources ⇒ Object
readonly
Returns the value of attribute available_sources.
-
#http_status_code ⇒ Object
readonly
Returns the value of attribute http_status_code.
-
#match_requirements ⇒ Object
readonly
Returns the value of attribute match_requirements.
-
#person ⇒ Object
readonly
Returns the value of attribute person.
-
#person_count ⇒ Object
readonly
Returns the value of attribute person_count.
-
#possible_persons ⇒ Object
readonly
Returns the value of attribute possible_persons.
-
#qps_allotted ⇒ Object
readonly
Returns the value of attribute qps_allotted.
-
#qps_current ⇒ Object
readonly
Returns the value of attribute qps_current.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#quota_allotted ⇒ Object
readonly
Returns the value of attribute quota_allotted.
-
#quota_current ⇒ Object
readonly
Returns the value of attribute quota_current.
-
#quota_reset ⇒ Object
readonly
Returns the value of attribute quota_reset.
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#search_id ⇒ Object
readonly
Returns the value of attribute search_id.
-
#source_category_requirements ⇒ Object
readonly
Returns the value of attribute source_category_requirements.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#visible_sources ⇒ Object
readonly
Returns the value of attribute visible_sources.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
- .deserialize(json_str, headers = {}) ⇒ Object
- .from_http_response(resp) ⇒ Object
-
.from_json(json_str) ⇒ Object
Here for backward compatibility.
Instance Method Summary collapse
- #address ⇒ Object
- #age ⇒ Object
- #education ⇒ Object
- #email ⇒ Object
- #ethnicity ⇒ Object
- #gender ⇒ Object
- #group_sources_by_category ⇒ Object
- #group_sources_by_domain ⇒ Object
- #group_sources_by_match ⇒ Object
- #image ⇒ Object
-
#initialize(params = {}) ⇒ SearchResponse
constructor
A new instance of SearchResponse.
- #job ⇒ Object
- #language ⇒ Object
- #matching_sources ⇒ Object
- #name ⇒ Object
- #origin_country ⇒ Object
- #phone ⇒ Object
- #relationship ⇒ Object
- #url ⇒ Object
- #user_id ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ SearchResponse
Returns a new instance of SearchResponse.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pipl/response.rb', line 16 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] @quota_allotted = params[:quota_allotted] @quota_current = params[:quota_current] @quota_reset = params[:quota_reset] end |
Instance Attribute Details
#available_data ⇒ Object (readonly)
Returns the value of attribute available_data.
12 13 14 |
# File 'lib/pipl/response.rb', line 12 def available_data @available_data end |
#available_sources ⇒ Object (readonly)
Returns the value of attribute available_sources.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def available_sources @available_sources end |
#http_status_code ⇒ Object (readonly)
Returns the value of attribute http_status_code.
12 13 14 |
# File 'lib/pipl/response.rb', line 12 def http_status_code @http_status_code end |
#match_requirements ⇒ Object (readonly)
Returns the value of attribute match_requirements.
12 13 14 |
# File 'lib/pipl/response.rb', line 12 def match_requirements @match_requirements end |
#person ⇒ Object (readonly)
Returns the value of attribute person.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def person @person end |
#person_count ⇒ Object (readonly)
Returns the value of attribute person_count.
13 14 15 |
# File 'lib/pipl/response.rb', line 13 def person_count @person_count end |
#possible_persons ⇒ Object (readonly)
Returns the value of attribute possible_persons.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def possible_persons @possible_persons end |
#qps_allotted ⇒ Object (readonly)
Returns the value of attribute qps_allotted.
14 15 16 |
# File 'lib/pipl/response.rb', line 14 def qps_allotted @qps_allotted end |
#qps_current ⇒ Object (readonly)
Returns the value of attribute qps_current.
14 15 16 |
# File 'lib/pipl/response.rb', line 14 def qps_current @qps_current end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def query @query end |
#quota_allotted ⇒ Object (readonly)
Returns the value of attribute quota_allotted.
14 15 16 |
# File 'lib/pipl/response.rb', line 14 def quota_allotted @quota_allotted end |
#quota_current ⇒ Object (readonly)
Returns the value of attribute quota_current.
14 15 16 |
# File 'lib/pipl/response.rb', line 14 def quota_current @quota_current end |
#quota_reset ⇒ Object (readonly)
Returns the value of attribute quota_reset.
14 15 16 |
# File 'lib/pipl/response.rb', line 14 def quota_reset @quota_reset end |
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
12 13 14 |
# File 'lib/pipl/response.rb', line 12 def raw_response @raw_response end |
#search_id ⇒ Object (readonly)
Returns the value of attribute search_id.
12 13 14 |
# File 'lib/pipl/response.rb', line 12 def search_id @search_id end |
#source_category_requirements ⇒ Object (readonly)
Returns the value of attribute source_category_requirements.
13 14 15 |
# File 'lib/pipl/response.rb', line 13 def source_category_requirements @source_category_requirements end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def sources @sources end |
#visible_sources ⇒ Object (readonly)
Returns the value of attribute visible_sources.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def visible_sources @visible_sources end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/pipl/response.rb', line 11 def warnings @warnings end |
Class Method Details
.deserialize(json_str, headers = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pipl/response.rb', line 38 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 # Quota and Throttle headers params[:qps_allotted] = headers['X-APIKey-QPS-Allotted'].to_i if headers.key? 'X-APIKey-QPS-Allotted' params[:qps_current] = headers['X-APIKey-QPS-Current'].to_i if headers.key? 'X-APIKey-QPS-Current' params[:quota_allotted] = headers['X-APIKey-Quota-Allotted'].to_i if headers.key? 'X-APIKey-Quota-Allotted' params[:quota_current] = headers['X-APIKey-Quota-Current'].to_i if headers.key? 'X-APIKey-Quota-Current' params[:quota_reset] = DateTime.strptime(headers['X-Quota-Reset'], '%A, %B %d, %Y %I:%M:%S %p %Z') if headers.key? 'X-Quota-Reset' self.new(params) end |
.from_http_response(resp) ⇒ Object
77 78 79 |
# File 'lib/pipl/response.rb', line 77 def self.from_http_response(resp) self.deserialize(resp.body, resp) end |
.from_json(json_str) ⇒ Object
Here for backward compatibility
82 83 84 |
# File 'lib/pipl/response.rb', line 82 def self.from_json(json_str) self.deserialize(json_str) end |
Instance Method Details
#address ⇒ Object
114 115 116 |
# File 'lib/pipl/response.rb', line 114 def address @person.address if @person end |
#age ⇒ Object
106 107 108 |
# File 'lib/pipl/response.rb', line 106 def age @person.age if @person end |
#education ⇒ Object
118 119 120 |
# File 'lib/pipl/response.rb', line 118 def education @person.education if @person end |
#email ⇒ Object
138 139 140 |
# File 'lib/pipl/response.rb', line 138 def email @person.email if @person end |
#ethnicity ⇒ Object
126 127 128 |
# File 'lib/pipl/response.rb', line 126 def ethnicity @person.ethnicity if @person end |
#gender ⇒ Object
102 103 104 |
# File 'lib/pipl/response.rb', line 102 def gender @person.gender if @person end |
#group_sources_by_category ⇒ Object
94 95 96 |
# File 'lib/pipl/response.rb', line 94 def group_sources_by_category @sources.group_by { |s| s.category } if @sources end |
#group_sources_by_domain ⇒ Object
90 91 92 |
# File 'lib/pipl/response.rb', line 90 def group_sources_by_domain @sources.group_by { |s| s.domain } if @sources end |
#group_sources_by_match ⇒ Object
98 99 100 |
# File 'lib/pipl/response.rb', line 98 def group_sources_by_match @sources.group_by { |s| s.match } if @sources end |
#image ⇒ Object
146 147 148 |
# File 'lib/pipl/response.rb', line 146 def image @person.image if @person end |
#job ⇒ Object
110 111 112 |
# File 'lib/pipl/response.rb', line 110 def job @person.job if @person end |
#language ⇒ Object
122 123 124 |
# File 'lib/pipl/response.rb', line 122 def language @person.language if @person end |
#matching_sources ⇒ Object
86 87 88 |
# File 'lib/pipl/response.rb', line 86 def matching_sources @sources.select { |s| s.match == 1.0 } if @sources end |
#name ⇒ Object
142 143 144 |
# File 'lib/pipl/response.rb', line 142 def name @person.name if @person end |
#origin_country ⇒ Object
130 131 132 |
# File 'lib/pipl/response.rb', line 130 def origin_country @person.origin_country if @person end |
#phone ⇒ Object
134 135 136 |
# File 'lib/pipl/response.rb', line 134 def phone @person.phone if @person end |
#relationship ⇒ Object
162 163 164 |
# File 'lib/pipl/response.rb', line 162 def relationship @person.relationship if @person end |
#url ⇒ Object
150 151 152 |
# File 'lib/pipl/response.rb', line 150 def url @person.url if @person end |
#user_id ⇒ Object
158 159 160 |
# File 'lib/pipl/response.rb', line 158 def user_id @person.user_id if @person end |
#username ⇒ Object
154 155 156 |
# File 'lib/pipl/response.rb', line 154 def username @person.username if @person end |