pipl-api 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pipl.rb +3 -0
- data/lib/pipl/api.rb +2 -6
- data/lib/pipl/api/request.rb +1 -6
- data/lib/pipl/api/request/name.rb +4 -1
- data/lib/pipl/api/response.rb +27 -0
- data/lib/pipl/api/response/age.rb +28 -0
- data/lib/pipl/api/response/gender.rb +23 -0
- data/lib/pipl/api/response/location.rb +32 -0
- data/lib/pipl/api/response/name.rb +27 -0
- data/lib/pipl/api/response/person.rb +44 -0
- data/lib/pipl/api/version.rb +1 -1
- data/lib/pipl/client.rb +15 -0
- data/lib/pipl/client/name.rb +13 -0
- data/test/lib/pipl/api/request_test.rb +1 -3
- metadata +24 -5
- data/lib/pipl/api/request/get.rb +0 -19
- data/test/lib/pipl/api/request/get_test.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c697e18bae4c2053ae0748880ec12f9158a44139
|
4
|
+
data.tar.gz: cd14044050efd45485cdd96ad1394aac3dcd4b71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d72a343c5f3da146421e3a611ccf2dbc3477ade8a23865c806d8d291f44ce010525712b77cf671151bc6e58963265b7031f4284b88e105cabc26c6d8ea017a22
|
7
|
+
data.tar.gz: c7762721133551f86bc215eaa66d12f8a8a7286947ddcdbc46849a0c46dcb51bcc10091f59ea63e55a81bbeec01fcf6d648f2d3127f7ef88a9d939f7a0d95ee8
|
data/lib/pipl.rb
CHANGED
data/lib/pipl/api.rb
CHANGED
data/lib/pipl/api/request.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require_relative "request/name"
|
2
|
-
require_relative "request/get"
|
3
2
|
|
4
3
|
module Pipl
|
5
4
|
module API
|
@@ -19,7 +18,7 @@ module Pipl
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def call(verb)
|
22
|
-
|
21
|
+
RestClient.send(verb, uri, params: @parameters)
|
23
22
|
end
|
24
23
|
|
25
24
|
def uri
|
@@ -29,10 +28,6 @@ module Pipl
|
|
29
28
|
def protocol
|
30
29
|
"#{@protocol}://"
|
31
30
|
end
|
32
|
-
|
33
|
-
def parameters
|
34
|
-
Pipl::API.api_key ? @parameters.merge(key: Pipl::API.api_key) : @parameters
|
35
|
-
end
|
36
31
|
end
|
37
32
|
end
|
38
33
|
end
|
@@ -4,14 +4,17 @@ module Pipl
|
|
4
4
|
class Name
|
5
5
|
def initialize(raw, options = {})
|
6
6
|
@raw = raw
|
7
|
+
@options = options
|
7
8
|
end
|
8
9
|
|
9
10
|
def call
|
10
11
|
request.call("get")
|
11
12
|
end
|
12
13
|
|
14
|
+
private
|
15
|
+
|
13
16
|
def request
|
14
|
-
Request.new("name", raw_name: @raw)
|
17
|
+
Request.new("name", raw_name: @raw, key: @options[:key] )
|
15
18
|
end
|
16
19
|
end
|
17
20
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "response/person"
|
2
|
+
require_relative "response/name"
|
3
|
+
require_relative "response/age"
|
4
|
+
require_relative "response/location"
|
5
|
+
require_relative "response/gender"
|
6
|
+
|
7
|
+
module Pipl
|
8
|
+
module API
|
9
|
+
class Response
|
10
|
+
attr_reader :data
|
11
|
+
attr_reader :status
|
12
|
+
attr_reader :warnings
|
13
|
+
attr_reader :person
|
14
|
+
|
15
|
+
def initialize(raw)
|
16
|
+
@data = MultiJson.load(raw)
|
17
|
+
@status = @data.delete("@http_status_code")
|
18
|
+
@warnings = @data.delete("warnings")
|
19
|
+
@person = Person.new(@data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def ok?
|
23
|
+
status == 200
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pipl
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
class Age
|
5
|
+
attr_reader :from, :to
|
6
|
+
attr_reader :estimation
|
7
|
+
|
8
|
+
def initialize(age)
|
9
|
+
@from = age["from_age"]
|
10
|
+
@to = age["to_age"]
|
11
|
+
@estimation = age["estimated_percent"].to_f / 100
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_range
|
15
|
+
@from..@to
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
{
|
20
|
+
range: to_range,
|
21
|
+
estimation: estimation
|
22
|
+
}
|
23
|
+
end
|
24
|
+
alias_method :to_h, :to_hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Pipl
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
class Gender
|
5
|
+
attr_reader :code
|
6
|
+
attr_reader :estimation
|
7
|
+
|
8
|
+
def initialize(gender)
|
9
|
+
@code = gender.first
|
10
|
+
@estimation = gender.last
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash
|
14
|
+
{
|
15
|
+
code: code,
|
16
|
+
estimation: estimation
|
17
|
+
}
|
18
|
+
end
|
19
|
+
alias_method :to_h, :to_hash
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Pipl
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
class Location
|
5
|
+
attr_reader :code, :state, :country
|
6
|
+
attr_reader :estimation
|
7
|
+
|
8
|
+
def initialize(location)
|
9
|
+
@code = location["country"]
|
10
|
+
if location["display"].include?(",")
|
11
|
+
@state = location["display"].split(", ").first
|
12
|
+
@country = location["display"].split(", ").last
|
13
|
+
else
|
14
|
+
@country = location["display"]
|
15
|
+
end
|
16
|
+
@estimation = location["estimated_percent"].to_f / 100
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_hash
|
20
|
+
{
|
21
|
+
code: code,
|
22
|
+
state: state,
|
23
|
+
country: country,
|
24
|
+
estimation: estimation
|
25
|
+
}
|
26
|
+
end
|
27
|
+
alias_method :to_h, :to_hash
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pipl
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
class Name
|
5
|
+
attr_reader :first
|
6
|
+
attr_reader :middle
|
7
|
+
attr_reader :last
|
8
|
+
|
9
|
+
def initialize(name)
|
10
|
+
@first = name["first"]
|
11
|
+
@middle = name["middle"]
|
12
|
+
@last = name["last"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
first: first,
|
18
|
+
middle: middle,
|
19
|
+
last: last
|
20
|
+
}
|
21
|
+
end
|
22
|
+
alias_method :to_h, :to_hash
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Pipl
|
2
|
+
module API
|
3
|
+
class Response
|
4
|
+
class Person
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :full_names
|
7
|
+
attr_reader :nicknames
|
8
|
+
attr_reader :spellings
|
9
|
+
attr_reader :translations
|
10
|
+
attr_reader :locations
|
11
|
+
attr_reader :ages
|
12
|
+
attr_reader :gender
|
13
|
+
attr_reader :estimated_world_persons_count
|
14
|
+
|
15
|
+
def initialize(data)
|
16
|
+
@name = Name.new(data["name"])
|
17
|
+
@full_names = Name.new(data["full_names"]) unless data["full_names"] == {}
|
18
|
+
@nicknames = Name.new(data["nicknames"]) unless data["nicknames"] == {}
|
19
|
+
@spellings = Name.new(data["spellings"]) unless data["spellings"] == {}
|
20
|
+
@translations = data["translations"] unless data["translations"] == {}
|
21
|
+
@gender = Gender.new(data["gender"])
|
22
|
+
@locations = data["top_locations"].map { |location| Location.new(location) }
|
23
|
+
@ages = data["top_ages"].map { |age| Age.new(age) }
|
24
|
+
@estimated_world_persons_count = data["estimated_world_persons_count"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{
|
29
|
+
name: name.to_hash,
|
30
|
+
full_names: full_names.to_hash,
|
31
|
+
nicknames: nicknames.to_hash,
|
32
|
+
spellings: spellings.to_hash,
|
33
|
+
translations: translations,
|
34
|
+
gender: gender.to_hash,
|
35
|
+
locations: locations.map(&:to_hash),
|
36
|
+
ages: ages.map(&:to_hash),
|
37
|
+
estimated_world_persons_count: estimated_world_persons_count
|
38
|
+
}
|
39
|
+
end
|
40
|
+
alias_method :to_h, :to_hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/pipl/api/version.rb
CHANGED
data/lib/pipl/client.rb
ADDED
@@ -37,9 +37,7 @@ class TestPiplAPIRequest < Minitest::Test
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_call
|
40
|
-
get
|
41
|
-
get.expect :call!, "foo", [{}]
|
42
|
-
Pipl::API::Request::Get.stub :new, get do
|
40
|
+
RestClient.stub :get, "foo" do
|
43
41
|
expected = "foo"
|
44
42
|
actual = @request.call("get")
|
45
43
|
assert_equal(expected, actual)
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipl-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kurtis Rainbolt-Greene
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rest-client
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,15 +172,21 @@ executables:
|
|
158
172
|
extensions: []
|
159
173
|
extra_rdoc_files: []
|
160
174
|
files:
|
161
|
-
- lib/pipl/api/request/get.rb
|
162
175
|
- lib/pipl/api/request/name.rb
|
163
176
|
- lib/pipl/api/request.rb
|
177
|
+
- lib/pipl/api/response/age.rb
|
178
|
+
- lib/pipl/api/response/gender.rb
|
179
|
+
- lib/pipl/api/response/location.rb
|
180
|
+
- lib/pipl/api/response/name.rb
|
181
|
+
- lib/pipl/api/response/person.rb
|
182
|
+
- lib/pipl/api/response.rb
|
164
183
|
- lib/pipl/api/version.rb
|
165
184
|
- lib/pipl/api.rb
|
185
|
+
- lib/pipl/client/name.rb
|
186
|
+
- lib/pipl/client.rb
|
166
187
|
- lib/pipl-api.rb
|
167
188
|
- lib/pipl.rb
|
168
189
|
- test/helper.rb
|
169
|
-
- test/lib/pipl/api/request/get_test.rb
|
170
190
|
- test/lib/pipl/api/request_test.rb
|
171
191
|
- test/lib/pipl/api/version_test.rb
|
172
192
|
- test/lib/pipl/api_test.rb
|
@@ -198,7 +218,6 @@ specification_version: 4
|
|
198
218
|
summary: An interface for the Pipl API
|
199
219
|
test_files:
|
200
220
|
- test/helper.rb
|
201
|
-
- test/lib/pipl/api/request/get_test.rb
|
202
221
|
- test/lib/pipl/api/request_test.rb
|
203
222
|
- test/lib/pipl/api/version_test.rb
|
204
223
|
- test/lib/pipl/api_test.rb
|
data/lib/pipl/api/request/get.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Pipl
|
2
|
-
module API
|
3
|
-
class Request
|
4
|
-
class Get
|
5
|
-
def initialize(uri)
|
6
|
-
@uri = uri
|
7
|
-
end
|
8
|
-
|
9
|
-
def call!(parameters = {})
|
10
|
-
begin
|
11
|
-
RestClient.get(@uri, params: parameters)
|
12
|
-
rescue => e
|
13
|
-
raise e.response
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestPiplAPIRequestGet < Minitest::Test
|
4
|
-
def setup
|
5
|
-
@get = Pipl::API::Request::Get.new("http://www.foo.com/var")
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_call!
|
9
|
-
expected = "http://www.foo.com/var"
|
10
|
-
RestClient.stub :get, "http://www.foo.com/var" do
|
11
|
-
actual = @get.call!
|
12
|
-
assert_equal(expected, actual)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|