pipl-lite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +62 -0
- data/LICENSE +201 -0
- data/README.md +30 -0
- data/coverage/assets/0.10.2/application.css +799 -0
- data/coverage/assets/0.10.2/application.js +1707 -0
- data/coverage/assets/0.10.2/colorbox/border.png +0 -0
- data/coverage/assets/0.10.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.10.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.10.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.10.2/favicon_green.png +0 -0
- data/coverage/assets/0.10.2/favicon_red.png +0 -0
- data/coverage/assets/0.10.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.10.2/loading.gif +0 -0
- data/coverage/assets/0.10.2/magnify.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/index.html +424 -0
- data/lib/pipl-lite.rb +2 -0
- data/lib/pipl/lite.rb +47 -0
- data/pipl-lite.gemspec +25 -0
- data/spec/pipl/lite_spec.rb +52 -0
- data/spec/spec_helper.rb +16 -0
- metadata +162 -0
data/lib/pipl-lite.rb
ADDED
data/lib/pipl/lite.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'httparty'
|
5
|
+
module Pipl
|
6
|
+
class Lite
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
class NotConfiguredError < StandardError; end
|
10
|
+
class ResponseError < StandardError; end
|
11
|
+
|
12
|
+
base_uri 'https://api.pipl.com'
|
13
|
+
@@configured = false
|
14
|
+
|
15
|
+
def self.configure(key:)
|
16
|
+
@@pipl_key = key
|
17
|
+
@@configured = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.key
|
21
|
+
@@pipl_key
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.reset_key!
|
25
|
+
@@pipl_key = nil
|
26
|
+
@@configured = false
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.search(args={})
|
30
|
+
raise NotConfiguredError unless @@configured
|
31
|
+
args[:key] = key
|
32
|
+
uri = URI(base_uri + '/search')
|
33
|
+
uri.query = URI.encode_www_form(args)
|
34
|
+
response = get(uri.to_s)
|
35
|
+
case response.code
|
36
|
+
when 200..299
|
37
|
+
# Return the top 0-5 matches, sorted by score in descending order:
|
38
|
+
JSON.parse(response.body, symbolize_names: true)[:possible_persons]
|
39
|
+
.select{ |person| person[:@match] > 0 }
|
40
|
+
.sort_by{ |x| x[:@match] }
|
41
|
+
.reverse[0..4]
|
42
|
+
else
|
43
|
+
raise ResponseError.new(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/pipl-lite.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = 'pipl-lite'
|
4
|
+
spec.version = '0.1.0'
|
5
|
+
spec.authors = ['John Drago']
|
6
|
+
spec.email = 'jdrago.999@gmail.com'
|
7
|
+
spec.homepage = 'https://github.com/jdrago999/pipl-lite'
|
8
|
+
spec.summary = 'Search Pipl API, the simple way'
|
9
|
+
spec.description = 'Search Pipl API, the simple way'
|
10
|
+
spec.required_rubygems_version = '>= 1.3.6'
|
11
|
+
|
12
|
+
spec.files = Dir['**/*'].keep_if { |file| File.file?(file) }
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(spec|features)/})
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
18
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
19
|
+
spec.add_development_dependency 'rspec'
|
20
|
+
spec.add_development_dependency 'shoulda-matchers'
|
21
|
+
spec.add_development_dependency 'simplecov'
|
22
|
+
|
23
|
+
spec.add_dependency 'httparty'
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pipl::Lite do
|
4
|
+
before do
|
5
|
+
described_class.reset_key!
|
6
|
+
end
|
7
|
+
describe '.configure(key:)' do
|
8
|
+
it 'configures the Pipl::Lite package' do
|
9
|
+
key = SecureRandom.uuid
|
10
|
+
described_class.configure(key: key)
|
11
|
+
expect(described_class.key).to eq(key)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe '.search(args={})' do
|
15
|
+
context 'when it is not yet confiured' do
|
16
|
+
it 'raises an exception' do
|
17
|
+
expect{described_class.search(raw_name: 'Clark Kent')}.to raise_error Pipl::Lite::NotConfiguredError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
context 'when it has been configured' do
|
21
|
+
before do
|
22
|
+
@key = SecureRandom.uuid
|
23
|
+
described_class.configure(key: @key)
|
24
|
+
end
|
25
|
+
it 'searches with the keys provided' do
|
26
|
+
expect(described_class).to receive(:get).with('https://api.pipl.com/search?raw_name=Clark+Kent&key=%s' % @key) do
|
27
|
+
OpenStruct.new(
|
28
|
+
code: 200,
|
29
|
+
body: {
|
30
|
+
possible_persons: [
|
31
|
+
{
|
32
|
+
:@match => 0.5
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}.to_json
|
36
|
+
)
|
37
|
+
end
|
38
|
+
described_class.search(raw_name: 'Clark Kent')
|
39
|
+
end
|
40
|
+
context 'when it receives an error response' do
|
41
|
+
before do
|
42
|
+
expect(described_class).to receive(:get) do
|
43
|
+
OpenStruct.new(code: 401)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
it 'raises an exception' do
|
47
|
+
expect{described_class.search(raw_name: 'Clark Kent')}.to raise_error Pipl::Lite::ResponseError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
add_filter 'spec/'
|
6
|
+
end
|
7
|
+
SimpleCov.minimum_coverage 100
|
8
|
+
require File.expand_path("../../lib/pipl-lite", __FILE__)
|
9
|
+
require 'rspec'
|
10
|
+
require 'shoulda-matchers'
|
11
|
+
|
12
|
+
Shoulda::Matchers.configure do |config|
|
13
|
+
config.integrate do |with|
|
14
|
+
with.test_framework :rspec
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pipl-lite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Drago
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda-matchers
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: httparty
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Search Pipl API, the simple way
|
98
|
+
email: jdrago.999@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- Gemfile
|
104
|
+
- Gemfile.lock
|
105
|
+
- LICENSE
|
106
|
+
- README.md
|
107
|
+
- coverage/assets/0.10.2/application.css
|
108
|
+
- coverage/assets/0.10.2/application.js
|
109
|
+
- coverage/assets/0.10.2/colorbox/border.png
|
110
|
+
- coverage/assets/0.10.2/colorbox/controls.png
|
111
|
+
- coverage/assets/0.10.2/colorbox/loading.gif
|
112
|
+
- coverage/assets/0.10.2/colorbox/loading_background.png
|
113
|
+
- coverage/assets/0.10.2/favicon_green.png
|
114
|
+
- coverage/assets/0.10.2/favicon_red.png
|
115
|
+
- coverage/assets/0.10.2/favicon_yellow.png
|
116
|
+
- coverage/assets/0.10.2/loading.gif
|
117
|
+
- coverage/assets/0.10.2/magnify.png
|
118
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
|
119
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
|
120
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
|
121
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
|
122
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_dadada_1x400.png
|
123
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
|
124
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
|
125
|
+
- coverage/assets/0.10.2/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
|
126
|
+
- coverage/assets/0.10.2/smoothness/images/ui-icons_222222_256x240.png
|
127
|
+
- coverage/assets/0.10.2/smoothness/images/ui-icons_2e83ff_256x240.png
|
128
|
+
- coverage/assets/0.10.2/smoothness/images/ui-icons_454545_256x240.png
|
129
|
+
- coverage/assets/0.10.2/smoothness/images/ui-icons_888888_256x240.png
|
130
|
+
- coverage/assets/0.10.2/smoothness/images/ui-icons_cd0a0a_256x240.png
|
131
|
+
- coverage/index.html
|
132
|
+
- lib/pipl-lite.rb
|
133
|
+
- lib/pipl/lite.rb
|
134
|
+
- pipl-lite.gemspec
|
135
|
+
- spec/pipl/lite_spec.rb
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
homepage: https://github.com/jdrago999/pipl-lite
|
138
|
+
licenses: []
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 1.3.6
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.5.1
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Search Pipl API, the simple way
|
160
|
+
test_files:
|
161
|
+
- spec/pipl/lite_spec.rb
|
162
|
+
- spec/spec_helper.rb
|