piplapis-ruby 5.0.4 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +10 -10
- data/README.md +25 -25
- data/lib/pipl.rb +35 -35
- data/lib/pipl/client.rb +177 -177
- data/lib/pipl/configurable.rb +58 -58
- data/lib/pipl/consts.rb +76 -76
- data/lib/pipl/containers.rb +294 -294
- data/lib/pipl/default.rb +66 -67
- data/lib/pipl/errors.rb +61 -61
- data/lib/pipl/fields.rb +732 -732
- data/lib/pipl/response.rb +220 -220
- data/lib/pipl/utils.rb +68 -68
- data/lib/pipl/version.rb +2 -2
- data/pipl.gemspec +18 -18
- metadata +2 -2
data/lib/pipl/response.rb
CHANGED
@@ -1,220 +1,220 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
require_relative 'containers'
|
4
|
-
|
5
|
-
module Pipl
|
6
|
-
|
7
|
-
class Client
|
8
|
-
|
9
|
-
class SearchResponse
|
10
|
-
|
11
|
-
attr_reader :query, :person, :sources, :possible_persons, :warnings, :visible_sources, :available_sources
|
12
|
-
attr_reader :search_id, :http_status_code, :raw_response, :available_data, :match_requirements
|
13
|
-
attr_reader :source_category_requirements, :person_count
|
14
|
-
attr_reader :qps_allotted, :qps_current, :qps_live_allotted, :qps_live_current, :qps_demo_allotted,
|
15
|
-
:qps_demo_current, :quota_allotted, :quota_current, :quota_reset, :demo_usage_allotted,
|
16
|
-
:demo_usage_current, :demo_usage_expiry
|
17
|
-
|
18
|
-
|
19
|
-
def initialize(params={})
|
20
|
-
@query = params[:query]
|
21
|
-
@person = params[:person]
|
22
|
-
@sources = params[:sources]
|
23
|
-
@possible_persons = params[:possible_persons]
|
24
|
-
@warnings = params[:warnings]
|
25
|
-
@visible_sources = params[:visible_sources]
|
26
|
-
@available_sources = params[:available_sources]
|
27
|
-
@search_id = params[:search_id]
|
28
|
-
@http_status_code = params[:http_status_code]
|
29
|
-
@raw_response = params[:raw_response]
|
30
|
-
@available_data = params[:available_data]
|
31
|
-
@match_requirements = params[:match_requirements]
|
32
|
-
@source_category_requirements = params[:source_category_requirements]
|
33
|
-
@person_count = params[:person_count]
|
34
|
-
@qps_allotted = params[:qps_allotted]
|
35
|
-
@qps_current = params[:qps_current]
|
36
|
-
@qps_live_allotted = params[:qps_live_allotted]
|
37
|
-
@qps_live_current = params[:qps_live_current]
|
38
|
-
@qps_demo_allotted = params[:qps_demo_allotted]
|
39
|
-
@qps_demo_current = params[:qps_demo_current]
|
40
|
-
@quota_allotted = params[:quota_allotted]
|
41
|
-
@quota_current = params[:quota_current]
|
42
|
-
@quota_reset = params[:quota_reset]
|
43
|
-
@demo_usage_allotted = params[:demo_usage_allotted]
|
44
|
-
@demo_usage_current = params[:demo_usage_current]
|
45
|
-
@demo_usage_expiry = params[:demo_usage_expiry]
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.deserialize(json_str, headers={})
|
49
|
-
h = JSON.parse(json_str, symbolize_names: true)
|
50
|
-
|
51
|
-
params = {}
|
52
|
-
params[:query] = Pipl::Person.from_hash(h[:query]) if h.key? :query
|
53
|
-
params[:person] = Pipl::Person.from_hash(h[:person]) if h.key? :person
|
54
|
-
params[:sources] = h[:sources].map { |s| Pipl::Source.from_hash(s) } if h.key? :sources
|
55
|
-
params[:possible_persons] = h[:possible_persons].map { |p| Pipl::Person.from_hash(p) } if h.key? :possible_persons
|
56
|
-
params[:warnings] = h[:warnings]
|
57
|
-
params[:visible_sources] = h[:@visible_sources]
|
58
|
-
params[:available_sources] = h[:@available_sources]
|
59
|
-
params[:search_id] = h[:@search_id]
|
60
|
-
params[:http_status_code] = h[:@http_status_code]
|
61
|
-
params[:raw_response] = json_str
|
62
|
-
params[:match_requirements] = h[:match_requirements]
|
63
|
-
params[:source_category_requirements] = h[:source_category_requirements]
|
64
|
-
params[:available_data] = AvailableData.from_hash(h[:available_data]) if h.key? :available_data
|
65
|
-
|
66
|
-
# person_count: API v4 doesn't send this in the response so we compute it here
|
67
|
-
if h.key? :@person_count
|
68
|
-
params[:person_count] = h[:@person_count]
|
69
|
-
elsif h.key?(:person)
|
70
|
-
params[:person_count] = 1
|
71
|
-
elsif h.key?(:possible_persons)
|
72
|
-
params[:person_count] = h[:possible_persons].length
|
73
|
-
else
|
74
|
-
params[:person_count] = 0
|
75
|
-
end
|
76
|
-
|
77
|
-
params.merge! Utils::extract_rate_limits(headers)
|
78
|
-
|
79
|
-
self.new(params)
|
80
|
-
end
|
81
|
-
|
82
|
-
def self.from_http_response(resp)
|
83
|
-
self.deserialize(resp.body, resp)
|
84
|
-
end
|
85
|
-
|
86
|
-
# Here for backward compatibility
|
87
|
-
def self.from_json(json_str)
|
88
|
-
self.deserialize(json_str)
|
89
|
-
end
|
90
|
-
|
91
|
-
def matching_sources
|
92
|
-
@sources.select { |s| s.match == 1.0 } if @sources
|
93
|
-
end
|
94
|
-
|
95
|
-
def group_sources_by_domain
|
96
|
-
@sources.group_by { |s| s.domain } if @sources
|
97
|
-
end
|
98
|
-
|
99
|
-
def group_sources_by_category
|
100
|
-
@sources.group_by { |s| s.category } if @sources
|
101
|
-
end
|
102
|
-
|
103
|
-
def group_sources_by_match
|
104
|
-
@sources.group_by { |s| s.match } if @sources
|
105
|
-
end
|
106
|
-
|
107
|
-
def gender
|
108
|
-
@person.gender if @person
|
109
|
-
end
|
110
|
-
|
111
|
-
def age
|
112
|
-
@person.age if @person
|
113
|
-
end
|
114
|
-
|
115
|
-
def job
|
116
|
-
@person.job if @person
|
117
|
-
end
|
118
|
-
|
119
|
-
def address
|
120
|
-
@person.address if @person
|
121
|
-
end
|
122
|
-
|
123
|
-
def education
|
124
|
-
@person.education if @person
|
125
|
-
end
|
126
|
-
|
127
|
-
def language
|
128
|
-
@person.language if @person
|
129
|
-
end
|
130
|
-
|
131
|
-
def ethnicity
|
132
|
-
@person.ethnicity if @person
|
133
|
-
end
|
134
|
-
|
135
|
-
def origin_country
|
136
|
-
@person.origin_country if @person
|
137
|
-
end
|
138
|
-
|
139
|
-
def phone
|
140
|
-
@person.phone if @person
|
141
|
-
end
|
142
|
-
|
143
|
-
def email
|
144
|
-
@person.email if @person
|
145
|
-
end
|
146
|
-
|
147
|
-
def name
|
148
|
-
@person.name if @person
|
149
|
-
end
|
150
|
-
|
151
|
-
def image
|
152
|
-
@person.image if @person
|
153
|
-
end
|
154
|
-
|
155
|
-
def url
|
156
|
-
@person.url if @person
|
157
|
-
end
|
158
|
-
|
159
|
-
def username
|
160
|
-
@person.username if @person
|
161
|
-
end
|
162
|
-
|
163
|
-
def user_id
|
164
|
-
@person.user_id if @person
|
165
|
-
end
|
166
|
-
|
167
|
-
def relationship
|
168
|
-
@person.relationship if @person
|
169
|
-
end
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
class AvailableData
|
174
|
-
attr_reader :basic, :premium
|
175
|
-
|
176
|
-
def initialize(params={})
|
177
|
-
@basic = params[:basic]
|
178
|
-
@premium = params[:premium]
|
179
|
-
end
|
180
|
-
|
181
|
-
def self.from_hash(h)
|
182
|
-
params = {}
|
183
|
-
params[:basic] = FieldCount.new(h[:basic]) if h.key? :basic
|
184
|
-
params[:premium] = FieldCount.new(h[:premium]) if h.key? :premium
|
185
|
-
self.new(params)
|
186
|
-
end
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
class FieldCount
|
191
|
-
attr_reader :addresses, :ethnicities, :emails, :dobs, :genders, :user_ids, :social_profiles, :educations, :jobs,
|
192
|
-
:images, :languages, :origin_countries, :names, :phones, :mobile_phones, :landline_phones,
|
193
|
-
:relationships, :usernames
|
194
|
-
|
195
|
-
def initialize(params={})
|
196
|
-
@addresses = params[:addresses] || 0
|
197
|
-
@ethnicities = params[:ethnicities] || 0
|
198
|
-
@emails = params[:emails] || 0
|
199
|
-
@dobs = params[:dobs] || 0
|
200
|
-
@genders = params[:genders] || 0
|
201
|
-
@user_ids = params[:user_ids] || 0
|
202
|
-
@social_profiles = params[:social_profiles] || 0
|
203
|
-
@educations = params[:educations] || 0
|
204
|
-
@jobs = params[:jobs] || 0
|
205
|
-
@images = params[:images] || 0
|
206
|
-
@languages = params[:languages] || 0
|
207
|
-
@origin_countries = params[:origin_countries] || 0
|
208
|
-
@names = params[:names] || 0
|
209
|
-
@phones = params[:phones] || 0
|
210
|
-
@mobile_phones = params[:mobile_phones] || 0
|
211
|
-
@landline_phones = params[:landline_phones] || 0
|
212
|
-
@relationships = params[:relationships] || 0
|
213
|
-
@usernames = params[:usernames] || 0
|
214
|
-
end
|
215
|
-
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
end
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative 'containers'
|
4
|
+
|
5
|
+
module Pipl
|
6
|
+
|
7
|
+
class Client
|
8
|
+
|
9
|
+
class SearchResponse
|
10
|
+
|
11
|
+
attr_reader :query, :person, :sources, :possible_persons, :warnings, :visible_sources, :available_sources
|
12
|
+
attr_reader :search_id, :http_status_code, :raw_response, :available_data, :match_requirements
|
13
|
+
attr_reader :source_category_requirements, :person_count
|
14
|
+
attr_reader :qps_allotted, :qps_current, :qps_live_allotted, :qps_live_current, :qps_demo_allotted,
|
15
|
+
:qps_demo_current, :quota_allotted, :quota_current, :quota_reset, :demo_usage_allotted,
|
16
|
+
:demo_usage_current, :demo_usage_expiry
|
17
|
+
|
18
|
+
|
19
|
+
def initialize(params={})
|
20
|
+
@query = params[:query]
|
21
|
+
@person = params[:person]
|
22
|
+
@sources = params[:sources]
|
23
|
+
@possible_persons = params[:possible_persons]
|
24
|
+
@warnings = params[:warnings]
|
25
|
+
@visible_sources = params[:visible_sources]
|
26
|
+
@available_sources = params[:available_sources]
|
27
|
+
@search_id = params[:search_id]
|
28
|
+
@http_status_code = params[:http_status_code]
|
29
|
+
@raw_response = params[:raw_response]
|
30
|
+
@available_data = params[:available_data]
|
31
|
+
@match_requirements = params[:match_requirements]
|
32
|
+
@source_category_requirements = params[:source_category_requirements]
|
33
|
+
@person_count = params[:person_count]
|
34
|
+
@qps_allotted = params[:qps_allotted]
|
35
|
+
@qps_current = params[:qps_current]
|
36
|
+
@qps_live_allotted = params[:qps_live_allotted]
|
37
|
+
@qps_live_current = params[:qps_live_current]
|
38
|
+
@qps_demo_allotted = params[:qps_demo_allotted]
|
39
|
+
@qps_demo_current = params[:qps_demo_current]
|
40
|
+
@quota_allotted = params[:quota_allotted]
|
41
|
+
@quota_current = params[:quota_current]
|
42
|
+
@quota_reset = params[:quota_reset]
|
43
|
+
@demo_usage_allotted = params[:demo_usage_allotted]
|
44
|
+
@demo_usage_current = params[:demo_usage_current]
|
45
|
+
@demo_usage_expiry = params[:demo_usage_expiry]
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.deserialize(json_str, headers={})
|
49
|
+
h = JSON.parse(json_str, symbolize_names: true)
|
50
|
+
|
51
|
+
params = {}
|
52
|
+
params[:query] = Pipl::Person.from_hash(h[:query]) if h.key? :query
|
53
|
+
params[:person] = Pipl::Person.from_hash(h[:person]) if h.key? :person
|
54
|
+
params[:sources] = h[:sources].map { |s| Pipl::Source.from_hash(s) } if h.key? :sources
|
55
|
+
params[:possible_persons] = h[:possible_persons].map { |p| Pipl::Person.from_hash(p) } if h.key? :possible_persons
|
56
|
+
params[:warnings] = h[:warnings]
|
57
|
+
params[:visible_sources] = h[:@visible_sources]
|
58
|
+
params[:available_sources] = h[:@available_sources]
|
59
|
+
params[:search_id] = h[:@search_id]
|
60
|
+
params[:http_status_code] = h[:@http_status_code]
|
61
|
+
params[:raw_response] = json_str
|
62
|
+
params[:match_requirements] = h[:match_requirements]
|
63
|
+
params[:source_category_requirements] = h[:source_category_requirements]
|
64
|
+
params[:available_data] = AvailableData.from_hash(h[:available_data]) if h.key? :available_data
|
65
|
+
|
66
|
+
# person_count: API v4 doesn't send this in the response so we compute it here
|
67
|
+
if h.key? :@person_count
|
68
|
+
params[:person_count] = h[:@person_count]
|
69
|
+
elsif h.key?(:person)
|
70
|
+
params[:person_count] = 1
|
71
|
+
elsif h.key?(:possible_persons)
|
72
|
+
params[:person_count] = h[:possible_persons].length
|
73
|
+
else
|
74
|
+
params[:person_count] = 0
|
75
|
+
end
|
76
|
+
|
77
|
+
params.merge! Utils::extract_rate_limits(headers)
|
78
|
+
|
79
|
+
self.new(params)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.from_http_response(resp)
|
83
|
+
self.deserialize(resp.body, resp)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Here for backward compatibility
|
87
|
+
def self.from_json(json_str)
|
88
|
+
self.deserialize(json_str)
|
89
|
+
end
|
90
|
+
|
91
|
+
def matching_sources
|
92
|
+
@sources.select { |s| s.match == 1.0 } if @sources
|
93
|
+
end
|
94
|
+
|
95
|
+
def group_sources_by_domain
|
96
|
+
@sources.group_by { |s| s.domain } if @sources
|
97
|
+
end
|
98
|
+
|
99
|
+
def group_sources_by_category
|
100
|
+
@sources.group_by { |s| s.category } if @sources
|
101
|
+
end
|
102
|
+
|
103
|
+
def group_sources_by_match
|
104
|
+
@sources.group_by { |s| s.match } if @sources
|
105
|
+
end
|
106
|
+
|
107
|
+
def gender
|
108
|
+
@person.gender if @person
|
109
|
+
end
|
110
|
+
|
111
|
+
def age
|
112
|
+
@person.age if @person
|
113
|
+
end
|
114
|
+
|
115
|
+
def job
|
116
|
+
@person.job if @person
|
117
|
+
end
|
118
|
+
|
119
|
+
def address
|
120
|
+
@person.address if @person
|
121
|
+
end
|
122
|
+
|
123
|
+
def education
|
124
|
+
@person.education if @person
|
125
|
+
end
|
126
|
+
|
127
|
+
def language
|
128
|
+
@person.language if @person
|
129
|
+
end
|
130
|
+
|
131
|
+
def ethnicity
|
132
|
+
@person.ethnicity if @person
|
133
|
+
end
|
134
|
+
|
135
|
+
def origin_country
|
136
|
+
@person.origin_country if @person
|
137
|
+
end
|
138
|
+
|
139
|
+
def phone
|
140
|
+
@person.phone if @person
|
141
|
+
end
|
142
|
+
|
143
|
+
def email
|
144
|
+
@person.email if @person
|
145
|
+
end
|
146
|
+
|
147
|
+
def name
|
148
|
+
@person.name if @person
|
149
|
+
end
|
150
|
+
|
151
|
+
def image
|
152
|
+
@person.image if @person
|
153
|
+
end
|
154
|
+
|
155
|
+
def url
|
156
|
+
@person.url if @person
|
157
|
+
end
|
158
|
+
|
159
|
+
def username
|
160
|
+
@person.username if @person
|
161
|
+
end
|
162
|
+
|
163
|
+
def user_id
|
164
|
+
@person.user_id if @person
|
165
|
+
end
|
166
|
+
|
167
|
+
def relationship
|
168
|
+
@person.relationship if @person
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
class AvailableData
|
174
|
+
attr_reader :basic, :premium
|
175
|
+
|
176
|
+
def initialize(params={})
|
177
|
+
@basic = params[:basic]
|
178
|
+
@premium = params[:premium]
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.from_hash(h)
|
182
|
+
params = {}
|
183
|
+
params[:basic] = FieldCount.new(h[:basic]) if h.key? :basic
|
184
|
+
params[:premium] = FieldCount.new(h[:premium]) if h.key? :premium
|
185
|
+
self.new(params)
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
class FieldCount
|
191
|
+
attr_reader :addresses, :ethnicities, :emails, :dobs, :genders, :user_ids, :social_profiles, :educations, :jobs,
|
192
|
+
:images, :languages, :origin_countries, :names, :phones, :mobile_phones, :landline_phones,
|
193
|
+
:relationships, :usernames
|
194
|
+
|
195
|
+
def initialize(params={})
|
196
|
+
@addresses = params[:addresses] || 0
|
197
|
+
@ethnicities = params[:ethnicities] || 0
|
198
|
+
@emails = params[:emails] || 0
|
199
|
+
@dobs = params[:dobs] || 0
|
200
|
+
@genders = params[:genders] || 0
|
201
|
+
@user_ids = params[:user_ids] || 0
|
202
|
+
@social_profiles = params[:social_profiles] || 0
|
203
|
+
@educations = params[:educations] || 0
|
204
|
+
@jobs = params[:jobs] || 0
|
205
|
+
@images = params[:images] || 0
|
206
|
+
@languages = params[:languages] || 0
|
207
|
+
@origin_countries = params[:origin_countries] || 0
|
208
|
+
@names = params[:names] || 0
|
209
|
+
@phones = params[:phones] || 0
|
210
|
+
@mobile_phones = params[:mobile_phones] || 0
|
211
|
+
@landline_phones = params[:landline_phones] || 0
|
212
|
+
@relationships = params[:relationships] || 0
|
213
|
+
@usernames = params[:usernames] || 0
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
data/lib/pipl/utils.rb
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
require 'date'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module Pipl
|
5
|
-
|
6
|
-
module Utils
|
7
|
-
|
8
|
-
class << self
|
9
|
-
|
10
|
-
def str_to_date(s)
|
11
|
-
Date.strptime(s, DATE_FORMAT)
|
12
|
-
end
|
13
|
-
|
14
|
-
def date_to_str(d)
|
15
|
-
d.strftime(DATE_FORMAT)
|
16
|
-
end
|
17
|
-
|
18
|
-
def is_valid_url?(url)
|
19
|
-
not ((url =~ URI::ABS_URI).nil?)
|
20
|
-
end
|
21
|
-
|
22
|
-
def alpha_chars(s)
|
23
|
-
s.gsub(/[^\p{Alpha}]/, '')
|
24
|
-
end
|
25
|
-
|
26
|
-
def alnum_chars(s)
|
27
|
-
s.gsub(/[^\p{Alnum}]/, '')
|
28
|
-
end
|
29
|
-
|
30
|
-
def titleize(s)
|
31
|
-
s.gsub(/\w+/) { |x| x.capitalize }
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_utf8(obj)
|
35
|
-
if obj.respond_to?(:encode)
|
36
|
-
begin
|
37
|
-
obj.encode('UTF-8')
|
38
|
-
rescue Exception
|
39
|
-
puts "Could not convert #{obj} to UTF-8"
|
40
|
-
raise
|
41
|
-
end
|
42
|
-
else
|
43
|
-
obj
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def extract_rate_limits(headers={})
|
48
|
-
res = {}
|
49
|
-
res[:qps_allotted] = headers['X-QPS-Allotted'].to_i if headers.key? 'X-QPS-Allotted'
|
50
|
-
res[:qps_current] = headers['X-QPS-Current'].to_i if headers.key? 'X-QPS-Current'
|
51
|
-
res[:qps_live_allotted] = headers['X-QPS-Live-Allotted'].to_i if headers.key? 'X-QPS-Live-Allotted'
|
52
|
-
res[:qps_live_current] = headers['X-QPS-Live-Current'].to_i if headers.key? 'X-QPS-Live-Current'
|
53
|
-
res[:qps_demo_allotted] = headers['X-QPS-Demo-Allotted'].to_i if headers.key? 'X-QPS-Demo-Allotted'
|
54
|
-
res[:qps_demo_current] = headers['X-QPS-Demo-Current'].to_i if headers.key? 'X-QPS-Demo-Current'
|
55
|
-
res[:quota_allotted] = headers['X-APIKey-Quota-Allotted'].to_i if headers.key? 'X-APIKey-Quota-Allotted'
|
56
|
-
res[:quota_current] = headers['X-APIKey-Quota-Current'].to_i if headers.key? 'X-APIKey-Quota-Current'
|
57
|
-
res[:quota_reset] = DateTime.strptime(headers['X-Quota-Reset'], '%A, %B %d, %Y %I:%M:%S %p %Z') if headers.key? 'X-Quota-Reset'
|
58
|
-
res[:demo_usage_allotted] = headers['X-Demo-Usage-Allotted'].to_i if headers.key? 'X-Demo-Usage-Allotted'
|
59
|
-
res[:demo_usage_current] = headers['X-Demo-Usage-Current'].to_i if headers.key? 'X-Demo-Usage-Current'
|
60
|
-
res[:demo_usage_expiry] = DateTime.strptime(headers['X-Demo-Usage-Expiry'], '%A, %B %d, %Y %I:%M:%S %p %Z') if headers.key? 'X-Demo-Usage-Expiry'
|
61
|
-
res
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
1
|
+
require 'date'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Pipl
|
5
|
+
|
6
|
+
module Utils
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def str_to_date(s)
|
11
|
+
Date.strptime(s, DATE_FORMAT)
|
12
|
+
end
|
13
|
+
|
14
|
+
def date_to_str(d)
|
15
|
+
d.strftime(DATE_FORMAT)
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_valid_url?(url)
|
19
|
+
not ((url =~ URI::ABS_URI).nil?)
|
20
|
+
end
|
21
|
+
|
22
|
+
def alpha_chars(s)
|
23
|
+
s.gsub(/[^\p{Alpha}]/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
def alnum_chars(s)
|
27
|
+
s.gsub(/[^\p{Alnum}]/, '')
|
28
|
+
end
|
29
|
+
|
30
|
+
def titleize(s)
|
31
|
+
s.gsub(/\w+/) { |x| x.capitalize }
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_utf8(obj)
|
35
|
+
if obj.respond_to?(:encode)
|
36
|
+
begin
|
37
|
+
obj.encode('UTF-8')
|
38
|
+
rescue Exception
|
39
|
+
puts "Could not convert #{obj} to UTF-8"
|
40
|
+
raise
|
41
|
+
end
|
42
|
+
else
|
43
|
+
obj
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def extract_rate_limits(headers={})
|
48
|
+
res = {}
|
49
|
+
res[:qps_allotted] = headers['X-QPS-Allotted'].to_i if headers.key? 'X-QPS-Allotted'
|
50
|
+
res[:qps_current] = headers['X-QPS-Current'].to_i if headers.key? 'X-QPS-Current'
|
51
|
+
res[:qps_live_allotted] = headers['X-QPS-Live-Allotted'].to_i if headers.key? 'X-QPS-Live-Allotted'
|
52
|
+
res[:qps_live_current] = headers['X-QPS-Live-Current'].to_i if headers.key? 'X-QPS-Live-Current'
|
53
|
+
res[:qps_demo_allotted] = headers['X-QPS-Demo-Allotted'].to_i if headers.key? 'X-QPS-Demo-Allotted'
|
54
|
+
res[:qps_demo_current] = headers['X-QPS-Demo-Current'].to_i if headers.key? 'X-QPS-Demo-Current'
|
55
|
+
res[:quota_allotted] = headers['X-APIKey-Quota-Allotted'].to_i if headers.key? 'X-APIKey-Quota-Allotted'
|
56
|
+
res[:quota_current] = headers['X-APIKey-Quota-Current'].to_i if headers.key? 'X-APIKey-Quota-Current'
|
57
|
+
res[:quota_reset] = DateTime.strptime(headers['X-Quota-Reset'], '%A, %B %d, %Y %I:%M:%S %p %Z') if headers.key? 'X-Quota-Reset'
|
58
|
+
res[:demo_usage_allotted] = headers['X-Demo-Usage-Allotted'].to_i if headers.key? 'X-Demo-Usage-Allotted'
|
59
|
+
res[:demo_usage_current] = headers['X-Demo-Usage-Current'].to_i if headers.key? 'X-Demo-Usage-Current'
|
60
|
+
res[:demo_usage_expiry] = DateTime.strptime(headers['X-Demo-Usage-Expiry'], '%A, %B %d, %Y %I:%M:%S %p %Z') if headers.key? 'X-Demo-Usage-Expiry'
|
61
|
+
res
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|