fullcontacter 0.3.2
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.
- data/.document +5 -0
- data/.gitignore +53 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +36 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/bugs.txt +2 -0
- data/fullcontact.gemspec +34 -0
- data/lib/faraday/request/gateway.rb +18 -0
- data/lib/faraday/response/fullcontact_errors.rb +33 -0
- data/lib/faraday/response/raise_http_4xx.rb +45 -0
- data/lib/faraday/response/raise_http_5xx.rb +24 -0
- data/lib/fullcontact.rb +27 -0
- data/lib/fullcontact/api.rb +21 -0
- data/lib/fullcontact/client.rb +32 -0
- data/lib/fullcontact/client/batch_process.rb +35 -0
- data/lib/fullcontact/client/contact.rb +119 -0
- data/lib/fullcontact/client/contact_list.rb +84 -0
- data/lib/fullcontact/client/icon.rb +35 -0
- data/lib/fullcontact/client/name.rb +167 -0
- data/lib/fullcontact/client/person.rb +94 -0
- data/lib/fullcontact/client/provisioning.rb +28 -0
- data/lib/fullcontact/client/snapshot.rb +31 -0
- data/lib/fullcontact/client/subscription.rb +45 -0
- data/lib/fullcontact/client/user.rb +28 -0
- data/lib/fullcontact/configuration.rb +95 -0
- data/lib/fullcontact/connection.rb +36 -0
- data/lib/fullcontact/error.rb +35 -0
- data/lib/fullcontact/request.rb +43 -0
- data/lib/fullcontact/version.rb +3 -0
- data/spec/faraday/response_spec.rb +56 -0
- data/spec/fixtures/clear_contact_list.json +3 -0
- data/spec/fixtures/contact_history.json +16 -0
- data/spec/fixtures/create_contact_list.json +4 -0
- data/spec/fixtures/create_snapshot.json +7 -0
- data/spec/fixtures/create_subscription.json +4 -0
- data/spec/fixtures/deduce_by_email.json +13 -0
- data/spec/fixtures/deduce_by_username.json +13 -0
- data/spec/fixtures/delete_contact.json +4 -0
- data/spec/fixtures/delete_contact_list.json +3 -0
- data/spec/fixtures/delete_subscription.json +3 -0
- data/spec/fixtures/get_contact.json +20 -0
- data/spec/fixtures/get_contact_lists.json +11 -0
- data/spec/fixtures/get_contacts_in_a_list.json +41 -0
- data/spec/fixtures/get_enriched_contact.json +261 -0
- data/spec/fixtures/get_updates.json +252 -0
- data/spec/fixtures/has_enriched_updates.json +4 -0
- data/spec/fixtures/list_snapshots.json +7 -0
- data/spec/fixtures/list_subscriptions.json +10 -0
- data/spec/fixtures/normalize.json +27 -0
- data/spec/fixtures/parse.json +10 -0
- data/spec/fixtures/person.json +47 -0
- data/spec/fixtures/queue_contact_list_for_enrichment.json +3 -0
- data/spec/fixtures/save_enriched_contact.json +261 -0
- data/spec/fixtures/similarity.json +45 -0
- data/spec/fixtures/stats_by_family_name.json +12 -0
- data/spec/fixtures/stats_by_given_and_family_name.json +62 -0
- data/spec/fixtures/stats_by_given_name.json +57 -0
- data/spec/fixtures/stats_by_name.json +64 -0
- data/spec/fixtures/update_contact.json +9 -0
- data/spec/fullcontact/api_spec.rb +68 -0
- data/spec/fullcontact/client/contact_list_spec.rb +89 -0
- data/spec/fullcontact/client/contact_spec.rb +108 -0
- data/spec/fullcontact/client/icon_spec.rb +24 -0
- data/spec/fullcontact/client/name_spec.rb +121 -0
- data/spec/fullcontact/client/person_spec.rb +77 -0
- data/spec/fullcontact/client/snapshot_spec.rb +35 -0
- data/spec/fullcontact/client/subscription_spec.rb +47 -0
- data/spec/fullcontact/client_spec.rb +10 -0
- data/spec/fullcontact_spec.rb +114 -0
- data/spec/helper.rb +39 -0
- metadata +384 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
43
|
+
|
44
|
+
# For redcar:
|
45
|
+
#.redcar
|
46
|
+
|
47
|
+
# For rubinius:
|
48
|
+
#*.rbc
|
49
|
+
|
50
|
+
.idea/
|
51
|
+
*.lock
|
52
|
+
|
53
|
+
*.gem
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Brandon West, Jai Pandya, Prafulla Kiran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
FullContact Ruby Gem
|
2
|
+
====================
|
3
|
+
A Ruby wrapper for the [FullContact API](http://www.fullcontact.com/)
|
4
|
+
|
5
|
+
Installation
|
6
|
+
------------
|
7
|
+
gem install fullcontacter
|
8
|
+
|
9
|
+
Documentation
|
10
|
+
-------------
|
11
|
+
[http://rdoc.info/gems/fullcontacter](http://rdoc.info/gems/fullcontacter)
|
12
|
+
|
13
|
+
Usage Examples
|
14
|
+
--------------
|
15
|
+
require "rubygems"
|
16
|
+
require "fullcontact"
|
17
|
+
|
18
|
+
# This could go in an initializer
|
19
|
+
FullContact.configure do |config|
|
20
|
+
config.api_key = "fullcontact_api_key_goes_here"
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get information about a email address
|
24
|
+
person = FullContact.lookup_by_email('prafulla.kiran@gmail.com')
|
25
|
+
|
26
|
+
# Get information about a twitter
|
27
|
+
person2 = FullContact.lookup_by_twitter('prafulla')
|
28
|
+
|
29
|
+
# Get person's family_name
|
30
|
+
puts person.contact_info.family_name
|
31
|
+
|
32
|
+
Copyright
|
33
|
+
---------
|
34
|
+
Copyright (c) 2012 Brandon West, Jai Pandya, Prafulla Kiran
|
35
|
+
|
36
|
+
See [LICENSE](https://github.com/jaipandya/fullcontacter/blob/master/LICENSE.md) for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :test => :spec
|
10
|
+
task :default => :spec
|
11
|
+
|
12
|
+
namespace :doc do
|
13
|
+
require 'yard'
|
14
|
+
YARD::Rake::YardocTask.new do |task|
|
15
|
+
task.files = ['HISTORY.md', 'LICENSE.md', 'lib/**/*.rb']
|
16
|
+
task.options = [
|
17
|
+
'--protected',
|
18
|
+
'--output-dir', 'doc',
|
19
|
+
'--tag', 'format:Supported formats',
|
20
|
+
'--tag', 'authenticated:Requires Authentication',
|
21
|
+
'--tag', 'rate_limited:Rate Limited',
|
22
|
+
'--markup', 'markdown',
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.2
|
data/bugs.txt
ADDED
data/fullcontact.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fullcontact/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.add_development_dependency 'maruku', '~> 0.6'
|
7
|
+
s.add_development_dependency 'nokogiri', '~> 1.4'
|
8
|
+
s.add_development_dependency 'rake', '~> 0.9'
|
9
|
+
s.add_development_dependency 'rspec', '~> 2.6'
|
10
|
+
s.add_development_dependency 'simplecov', '~> 0.4'
|
11
|
+
s.add_development_dependency 'webmock', '~> 1.6'
|
12
|
+
s.add_development_dependency 'yard', '~> 0.7'
|
13
|
+
|
14
|
+
s.add_runtime_dependency 'hashie', '~> 1.2.0'
|
15
|
+
s.add_runtime_dependency 'faraday', '~> 0.7.5'
|
16
|
+
s.add_runtime_dependency 'faraday_middleware', '~> 0.8.6'
|
17
|
+
s.add_runtime_dependency 'multi_json', '~> 1.2.0'
|
18
|
+
s.add_runtime_dependency 'multi_xml', '~> 0.4.2'
|
19
|
+
s.add_runtime_dependency 'rash', '~> 0.3.0'
|
20
|
+
|
21
|
+
s.authors = "Brandon West, Jai Pandya, Prafulla Kiran"
|
22
|
+
s.description = %q{A Ruby wrapper for the FullContact API}
|
23
|
+
s.email = ['brawest@gmail.com', 'jaipandya@gmail.com', 'prafulla.kiran@gmail.com']
|
24
|
+
|
25
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
26
|
+
s.files = `git ls-files`.split("\n")
|
27
|
+
s.homepage = 'https://github.com/jaipandya/fullcontacter'
|
28
|
+
s.name = 'fullcontacter'
|
29
|
+
s.require_paths = ['lib']
|
30
|
+
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
31
|
+
s.summary = %q{Ruby wrapper for the FullContact API}
|
32
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
33
|
+
s.version = FullContact::VERSION
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Request::Gateway < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
url = env[:url].dup
|
9
|
+
url.host = @gateway
|
10
|
+
env[:url] = url
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(app, gateway)
|
15
|
+
@app, @gateway = app, gateway
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Faraday
|
2
|
+
class Response::FullContactErrors < Response::Middleware
|
3
|
+
def on_complete(env)
|
4
|
+
case env[:status]
|
5
|
+
when 400
|
6
|
+
raise FullContact::BadRequest.new(error_message(env), env[:response_headers])
|
7
|
+
when 401
|
8
|
+
raise FullContact::Unauthorized.new(error_message(env), env[:response_headers])
|
9
|
+
when 403
|
10
|
+
raise FullContact::Forbidden.new(error_message(env), env[:response_headers])
|
11
|
+
when 404
|
12
|
+
raise FullContact::NotFound.new(error_message(env), env[:response_headers])
|
13
|
+
when 422
|
14
|
+
raise FullContact::Invalid.new(error_message(env), env[:response_headers])
|
15
|
+
when 500
|
16
|
+
raise FullContact::InternalServerError.new(error_message(env), env[:response_headers])
|
17
|
+
when 502
|
18
|
+
raise FullContact::BadGateway.new(error_message(env), env[:response_headers])
|
19
|
+
when 503
|
20
|
+
raise FullContact::ServiceUnavailable.new(error_message(env), env[:response_headers])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def error_message(env)
|
25
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(app)
|
29
|
+
super
|
30
|
+
@parser = nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp4xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 400
|
10
|
+
raise FullContact::BadRequest.new(error_message(env), env[:response_headers])
|
11
|
+
when 401
|
12
|
+
raise FullContact::Unauthorized.new(error_message(env), env[:response_headers])
|
13
|
+
when 403
|
14
|
+
raise FullContact::Forbidden.new(error_message(env), env[:response_headers])
|
15
|
+
when 404
|
16
|
+
raise FullContact::NotFound.new(error_message(env), env[:response_headers])
|
17
|
+
when 422
|
18
|
+
raise FullContact::Invalid.new(error_message(env), env[:response_headers])
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def error_message(env)
|
27
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_body(body)
|
31
|
+
if body.nil?
|
32
|
+
nil
|
33
|
+
elsif body['error']
|
34
|
+
": #{body['error']}"
|
35
|
+
elsif body['errors']
|
36
|
+
first = Array(body['errors']).first
|
37
|
+
if first.kind_of? Hash
|
38
|
+
": #{first['message'].chomp}"
|
39
|
+
else
|
40
|
+
": #{first.chomp}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module Faraday
|
5
|
+
# @private
|
6
|
+
class Response::RaiseHttp5xx < Response::Middleware
|
7
|
+
def on_complete(env)
|
8
|
+
case env[:status].to_i
|
9
|
+
when 500
|
10
|
+
raise FullContact::InternalServerError.new(error_message(env, "Internal server error."), env[:response_headers])
|
11
|
+
when 502
|
12
|
+
raise FullContact::BadGateway.new(error_message(env, "FullContact is down or being upgraded."), env[:response_headers])
|
13
|
+
when 503
|
14
|
+
raise FullContact::ServiceUnavailable.new(error_message(env, "Service unavailable."), env[:response_headers])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def error_message(env, body=nil)
|
21
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.fullcontact.cc/ for updates on the status of the FullContact service."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/fullcontact.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
require 'fullcontact/error'
|
4
|
+
require 'fullcontact/configuration'
|
5
|
+
require 'fullcontact/api'
|
6
|
+
require 'fullcontact/client'
|
7
|
+
|
8
|
+
module FullContact
|
9
|
+
extend Configuration
|
10
|
+
|
11
|
+
# Alias for FullContact::Client.new
|
12
|
+
#
|
13
|
+
# Returns [FullContact::Client]
|
14
|
+
def self.client(options={})
|
15
|
+
FullContact::Client.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Delegate to FullContact::Client
|
19
|
+
def self.method_missing(method, *args, &block)
|
20
|
+
return super unless client.respond_to?(method)
|
21
|
+
client.send(method, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.respond_to?(method, include_private = false)
|
25
|
+
client.respond_to?(method, include_private) || super(method, include_private)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'fullcontact/connection'
|
2
|
+
require 'fullcontact/request'
|
3
|
+
|
4
|
+
module FullContact
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor *Configuration::VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options={})
|
12
|
+
options = FullContact.options.merge(options)
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
include Connection
|
19
|
+
include Request
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module FullContact
|
2
|
+
# Wrapper for the FullContact REST API
|
3
|
+
|
4
|
+
class Client < API
|
5
|
+
# Require client method modules after initializing the Client class in
|
6
|
+
# order to avoid a superclass mismatch error, allowing those modules to be
|
7
|
+
# Client-namespaced.
|
8
|
+
require 'fullcontact/client/person'
|
9
|
+
require 'fullcontact/client/user'
|
10
|
+
require 'fullcontact/client/contact_list'
|
11
|
+
require 'fullcontact/client/contact'
|
12
|
+
require 'fullcontact/client/snapshot'
|
13
|
+
require 'fullcontact/client/subscription'
|
14
|
+
require 'fullcontact/client/name'
|
15
|
+
require 'fullcontact/client/icon'
|
16
|
+
require 'fullcontact/client/provisioning'
|
17
|
+
require 'fullcontact/client/batch_process'
|
18
|
+
|
19
|
+
alias :api_endpoint :endpoint
|
20
|
+
|
21
|
+
include FullContact::Client::Person
|
22
|
+
include FullContact::Client::User
|
23
|
+
include FullContact::Client::ContactList
|
24
|
+
include FullContact::Client::Contact
|
25
|
+
include FullContact::Client::Snapshot
|
26
|
+
include FullContact::Client::Subscription
|
27
|
+
include FullContact::Client::Name
|
28
|
+
include FullContact::Client::Icon
|
29
|
+
include FullContact::Client::Provisioning
|
30
|
+
include FullContact::Client::BatchProcess
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module FullContact
|
2
|
+
class Client
|
3
|
+
module BatchProcess
|
4
|
+
# Public: The Batch Process endpoint allows you to batch several API
|
5
|
+
# requests into a single request to improve performance by eliminating
|
6
|
+
# excess network overhead. This endpoint will proxy requests (up to 20
|
7
|
+
# per batch) on your behalf to any other API endpoint which accepts GET
|
8
|
+
# requests.
|
9
|
+
#
|
10
|
+
# Yields array of URLs to api endpoints
|
11
|
+
#
|
12
|
+
# Example
|
13
|
+
#
|
14
|
+
# respnose = FullContact.batch do
|
15
|
+
# [FullContact.normalize('Mr. John Michael Smith'),
|
16
|
+
# FullContact.deduce_by_email('johnsmith@gmail.com')]
|
17
|
+
# end
|
18
|
+
# 'response' contains batch response from the api
|
19
|
+
#
|
20
|
+
# Returns response from different api methods in the batch
|
21
|
+
def batch(options = {})
|
22
|
+
FullContact.configure do |config|
|
23
|
+
config.get_request_url_only = true
|
24
|
+
end
|
25
|
+
batch_method_list = yield
|
26
|
+
FullContact.configure do |config|
|
27
|
+
config.get_request_url_only = false
|
28
|
+
end
|
29
|
+
options[:content_type] = 'application/json'
|
30
|
+
options[:request_body] = {:requests => batch_method_list}.to_json
|
31
|
+
post("batch", options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|