fullcontact 0.1.3

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.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.md
@@ -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
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brandon West
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.
@@ -0,0 +1,33 @@
1
+ Rainmaker Ruby Gem
2
+ ====================
3
+ A Ruby wrapper for the [FullContact API](http://www.fullcontact.com/)
4
+
5
+ Installation
6
+ ------------
7
+ gem install fullcontact
8
+
9
+ Documentation
10
+ -------------
11
+ [http://rdoc.info/gems/rainmaker](http://rdoc.info/gems/fullcontact)
12
+
13
+ Usage Examples
14
+ --------------
15
+ require "rubygems"
16
+ require "rainmaker"
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 an email address
24
+ person = FullContact.person("brawest@gmail.com")
25
+
26
+ # Get person's family_name
27
+ puts person.contact_info.family_name
28
+
29
+ Copyright
30
+ ---------
31
+ Copyright (c) 2011 Brandon West
32
+
33
+ See [LICENSE](https://github.com/brandonmwest/rainmaker/blob/master/LICENSE.md) for details.
@@ -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.0.1
@@ -0,0 +1,40 @@
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
+ s.add_runtime_dependency 'hashie', '~> 1.1.0'
14
+ s.add_runtime_dependency 'faraday', '~> 0.6.1'
15
+ s.add_runtime_dependency 'faraday_middleware', '~> 0.6.3'
16
+ s.add_runtime_dependency 'multi_json', '~> 1.0.0'
17
+ s.add_runtime_dependency 'multi_xml', '~> 0.2.0'
18
+ s.add_runtime_dependency 'rash', '~> 0.3.0'
19
+
20
+ s.author = "Brandon West"
21
+ s.description = %q{A Ruby wrapper for the FullContact API}
22
+ s.email = ['brawest@gmail.com']
23
+
24
+ s.post_install_message = '
25
+ -------------------------------------------------------------
26
+ Follow me on Twitter! http://twitter.com/brandonmwest
27
+ -------------------------------------------------------------
28
+
29
+ '
30
+
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
32
+ s.files = `git ls-files`.split("\n")
33
+ s.homepage = 'https://github.com/brandonmwest/rainmaker'
34
+ s.name = 'fullcontact'
35
+ s.require_paths = ['lib']
36
+ s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
37
+ s.summary = %q{Ruby wrapper for the FullContact API}
38
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
39
+ s.version = FullContact::VERSION
40
+ 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
@@ -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
+ # @return [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,14 @@
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
+
10
+ alias :api_endpoint :endpoint
11
+
12
+ include FullContact::Client::Person
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module FullContact
2
+ class Client
3
+ module Person
4
+ # Returns extended information for a given email
5
+ #
6
+ def person(email)
7
+ response = get('person', :email => email)
8
+ format.to_s.downcase == 'xml' ? response['person'] : response
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,80 @@
1
+ require 'faraday'
2
+
3
+ module FullContact
4
+ # Defines constants and methods related to configuration
5
+ module Configuration
6
+ # An array of valid keys in the options hash when configuring a {FullContact::API}
7
+ VALID_OPTIONS_KEYS = [
8
+ :adapter,
9
+ :api_key,
10
+ :endpoint,
11
+ :format,
12
+ :gateway,
13
+ :proxy,
14
+ :user_agent].freeze
15
+
16
+ # An array of valid request/response formats
17
+ #
18
+ # @note Not all methods support the XML format.
19
+ VALID_FORMATS = [
20
+ :json,
21
+ :xml].freeze
22
+
23
+ # The adapter that will be used to connect if none is set
24
+ #
25
+ # @note The default faraday adapter is Net::HTTP.
26
+ DEFAULT_ADAPTER = Faraday.default_adapter
27
+
28
+ # By default, don't set an application key
29
+ DEFAULT_API_KEY = nil
30
+
31
+ # The endpoint that will be used to connect if none is set
32
+ #
33
+ DEFAULT_ENDPOINT = 'https://api.fullcontact.cc/v1/'.freeze
34
+
35
+ # The response format appended to the path and sent in the 'Accept' header if none is set
36
+ #
37
+ # @note JSON is preferred over XML because it is more concise and faster to parse.
38
+ DEFAULT_FORMAT = :json
39
+
40
+ # By default, don't use a proxy server
41
+ DEFAULT_PROXY = nil
42
+
43
+ # The user agent that will be sent to the API endpoint if none is set
44
+ DEFAULT_USER_AGENT = "FullContact Ruby Gem".freeze
45
+
46
+ DEFAULT_GATEWAY = nil
47
+
48
+ # @private
49
+ attr_accessor *VALID_OPTIONS_KEYS
50
+
51
+ # When this module is extended, set all configuration options to their default values
52
+ def self.extended(base)
53
+ base.reset
54
+ end
55
+
56
+ # Convenience method to allow configuration options to be set in a block
57
+ def configure
58
+ yield self
59
+ end
60
+
61
+ # Create a hash of options and their values
62
+ def options
63
+ options = {}
64
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k) }
65
+ options
66
+ end
67
+
68
+ # Reset all configuration options to defaults
69
+ def reset
70
+ self.adapter = DEFAULT_ADAPTER
71
+ self.api_key = DEFAULT_API_KEY
72
+ self.endpoint = DEFAULT_ENDPOINT
73
+ self.format = DEFAULT_FORMAT
74
+ self.proxy = DEFAULT_PROXY
75
+ self.user_agent = DEFAULT_USER_AGENT
76
+ self.gateway = DEFAULT_GATEWAY
77
+ self
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,36 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/request/gateway'
3
+ require 'faraday/response/fullcontact_errors'
4
+
5
+
6
+ module FullContact
7
+ # @private
8
+ module Connection
9
+ private
10
+
11
+ def connection(raw=false)
12
+ options = {
13
+ :headers => {'Accept' => "application/#{format}", 'User-Agent' => user_agent},
14
+ :proxy => proxy,
15
+ :ssl => {:verify => false},
16
+ :url => api_endpoint,
17
+ }
18
+
19
+ Faraday.new(options) do |builder|
20
+ builder.use Faraday::Request::UrlEncoded
21
+ builder.use Faraday::Request::Gateway, gateway if gateway
22
+ builder.use Faraday::Response::Rashify unless raw
23
+ unless raw
24
+ case format.to_s.downcase
25
+ when 'json'
26
+ builder.use Faraday::Response::ParseJson
27
+ when 'xml'
28
+ builder.use Faraday::Response::ParseXml
29
+ end
30
+ end
31
+ builder.use Faraday::Response::FullContactErrors
32
+ builder.adapter Faraday.default_adapter
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ module FullContact
2
+ # Custom error class for rescuing from all FullContact errors
3
+ class Error < StandardError
4
+ attr_reader :http_headers
5
+
6
+ def initialize(message, http_headers)
7
+ @http_headers = Hash[http_headers]
8
+ super message
9
+ end
10
+ end
11
+
12
+ # Raised when FullContact returns the HTTP status code 400
13
+ class BadRequest < Error; end
14
+
15
+ # Raised when FullContact returns the HTTP status code 401
16
+ class Unauthorized < Error; end
17
+
18
+ # Raised when FullContact returns the HTTP status code 403
19
+ class Forbidden < Error; end
20
+
21
+ # Raised when FullContact returns the HTTP status code 404
22
+ class NotFound < Error; end
23
+
24
+ # Raised when FullContact returns the HTTP status code 422
25
+ class Invalid < Error; end
26
+
27
+ # Raised when FullContact returns the HTTP status code 500
28
+ class InternalServerError < Error; end
29
+
30
+ # Raised when FullContact returns the HTTP status code 502
31
+ class BadGateway < Error; end
32
+
33
+ # Raised when FullContact returns the HTTP status code 503
34
+ class ServiceUnavailable < Error; end
35
+ end
@@ -0,0 +1,26 @@
1
+ module FullContact
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, options={}, raw=false)
6
+ request(:get, path, options, raw)
7
+ end
8
+
9
+ private
10
+
11
+ # Perform an HTTP request
12
+ def request(method, path, options, raw=false)
13
+ options[:apiKey] = FullContact.options[:api_key]
14
+
15
+ response = connection(raw).send(method) do |request|
16
+ request.url(formatted_path(path), options)
17
+ end
18
+
19
+ raw ? response : response.body
20
+ end
21
+
22
+ def formatted_path(path)
23
+ [path, format].compact.join('.')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module FullContact
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,56 @@
1
+ require 'helper'
2
+ require 'faraday'
3
+ require 'fullcontact'
4
+
5
+ describe Faraday::Response do
6
+ before do
7
+ FullContact.configure do |config|
8
+ config.api_key = "api_key"
9
+ end
10
+ @client = FullContact::Client.new
11
+ end
12
+
13
+ {
14
+ 400 => FullContact::BadRequest,
15
+ 401 => FullContact::Unauthorized,
16
+ 403 => FullContact::Forbidden,
17
+ 404 => FullContact::NotFound,
18
+ 422 => FullContact::Invalid,
19
+ 500 => FullContact::InternalServerError,
20
+ 502 => FullContact::BadGateway,
21
+ 503 => FullContact::ServiceUnavailable,
22
+ }.each do |status, exception|
23
+ if (status >= 500)
24
+ context "when HTTP status is #{status}" do
25
+ before do
26
+ stub_get('person.json').
27
+ with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
28
+ to_return(:status => status)
29
+ end
30
+
31
+ it "should raise #{exception.name} error" do
32
+ lambda do
33
+ @client.person( 'brawest@gmail.com')
34
+ end.should raise_error(exception)
35
+ end
36
+ end
37
+ else
38
+ [nil, "error", "errors"].each do |body|
39
+ context "when HTTP status is #{status} and body is #{body||='nil'}" do
40
+ before do
41
+ body_message = '{"'+body+'":"test"}' unless body.nil?
42
+ stub_get('person.json').
43
+ with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
44
+ to_return(:status => status, :body => body_message)
45
+ end
46
+
47
+ it "should raise #{exception.name} error" do
48
+ lambda do
49
+ @client.person( 'brawest@gmail.com')
50
+ end.should raise_error(exception)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,48 @@
1
+
2
+ {
3
+ "status": 200,
4
+ "photos":
5
+ [
6
+ {
7
+ "url": "http://a0.twimg.com/profile_images/1084241539/steps_normal.jpg",
8
+ "type": "twitter"
9
+ },
10
+ {
11
+ "isPrimary": false,
12
+ "type": "gravatar",
13
+ "url": "https://secure.gravatar.com/avatar/b2f65d319b253da9cf92635d8eac808b"
14
+ },
15
+ {
16
+ "message": "More Data Available - 3rd party credentials required - contact api@fullcontact.cc for more information."
17
+ }
18
+ ],
19
+ "contactInfo": {
20
+ "familyName": "West",
21
+ "givenName": "Brandon",
22
+ "fullName": "Brandon West"
23
+ },
24
+ "demographics": {
25
+ "age": {
26
+ "message": "More Data Available - 3rd party credentials required - contact api@fullcontact.cc for more information."
27
+ },
28
+ "locationGeneral": "Littleton, Colorado",
29
+ "gender": {
30
+ "message": "More Data Available - 3rd party credentials required - contact api@fullcontact.cc for more information."
31
+ }
32
+ },
33
+ "socialProfiles":
34
+ [
35
+ {
36
+ "url": "http://twitter.com/brandonmwest",
37
+ "id": "16517063",
38
+ "type": "twitter",
39
+ "username": "brandonmwest"
40
+ },
41
+ {
42
+ "message": "More Data Available - 3rd party credentials required - contact api@fullcontact.cc for more information."
43
+ },
44
+ {
45
+ "message": "More Data Available - 3rd party credentials required - contact api@fullcontact.cc for more information."
46
+ }
47
+ ]
48
+ }
@@ -0,0 +1,110 @@
1
+ require 'helper'
2
+
3
+ describe FullContact do
4
+ after do
5
+ FullContact.reset
6
+ end
7
+
8
+ context "when delegating to a client" do
9
+
10
+ before do
11
+ FullContact.configure do |config|
12
+ config.api_key = "api_key"
13
+ end
14
+
15
+ stub_get("person.json").
16
+ with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}).
17
+ to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
18
+
19
+ end
20
+
21
+ it "should get the correct resource" do
22
+ FullContact.person("brawest@gmail.com")
23
+ a_get("person.json")
24
+ .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"})
25
+ .should have_been_made
26
+ end
27
+
28
+ it "should return the same results as a client" do
29
+ FullContact.person("brawest@gmail.com").should == FullContact::Client.new.person("brawest@gmail.com")
30
+ end
31
+
32
+ end
33
+
34
+ describe '.respond_to?' do
35
+ it 'takes an optional include private argument' do
36
+ FullContact.respond_to?(:client, true).should be_true
37
+ end
38
+ end
39
+
40
+ describe ".client" do
41
+ it "should be a FullContact::Client" do
42
+ FullContact.client.should be_a FullContact::Client
43
+ end
44
+ end
45
+
46
+ describe ".adapter" do
47
+ it "should return the default adapter" do
48
+ FullContact.adapter.should == FullContact::Configuration::DEFAULT_ADAPTER
49
+ end
50
+ end
51
+
52
+ describe ".adapter=" do
53
+ it "should set the adapter" do
54
+ FullContact.adapter = :typhoeus
55
+ FullContact.adapter.should == :typhoeus
56
+ end
57
+ end
58
+
59
+ describe ".endpoint" do
60
+ it "should return the default endpoint" do
61
+ FullContact.endpoint.should == FullContact::Configuration::DEFAULT_ENDPOINT
62
+ end
63
+ end
64
+
65
+ describe ".endpoint=" do
66
+ it "should set the endpoint" do
67
+ FullContact.endpoint = 'http://tumblr.com/'
68
+ FullContact.endpoint.should == 'http://tumblr.com/'
69
+ end
70
+ end
71
+
72
+ describe ".format" do
73
+ it "should return the default format" do
74
+ FullContact.format.should == FullContact::Configuration::DEFAULT_FORMAT
75
+ end
76
+ end
77
+
78
+ describe ".format=" do
79
+ it "should set the format" do
80
+ FullContact.format = 'xml'
81
+ FullContact.format.should == 'xml'
82
+ end
83
+ end
84
+
85
+ describe ".user_agent" do
86
+ it "should return the default user agent" do
87
+ FullContact.user_agent.should == FullContact::Configuration::DEFAULT_USER_AGENT
88
+ end
89
+ end
90
+
91
+ describe ".user_agent=" do
92
+ it "should set the user_agent" do
93
+ FullContact.user_agent = 'Custom User Agent'
94
+ FullContact.user_agent.should == 'Custom User Agent'
95
+ end
96
+ end
97
+
98
+ describe ".configure" do
99
+
100
+ FullContact::Configuration::VALID_OPTIONS_KEYS.each do |key|
101
+
102
+ it "should set the #{key}" do
103
+ FullContact.configure do |config|
104
+ config.send("#{key}=", key)
105
+ FullContact.send(key).should == key
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,22 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+ require 'simplecov'
4
+
5
+ SimpleCov.start
6
+
7
+
8
+ def a_get(path)
9
+ a_request(:get, FullContact.endpoint + path)
10
+ end
11
+
12
+ def stub_get(path)
13
+ stub_request(:get, FullContact.endpoint + path)
14
+ end
15
+
16
+ def fixture_path
17
+ File.expand_path("../fixtures", __FILE__)
18
+ end
19
+
20
+ def fixture(file)
21
+ File.new(fixture_path + '/' + file)
22
+ end
@@ -0,0 +1,65 @@
1
+ require 'helper'
2
+
3
+ describe FullContact::API do
4
+ before do
5
+ @keys = FullContact::Configuration::VALID_OPTIONS_KEYS
6
+ end
7
+
8
+ context "with module configuration" do
9
+ before do
10
+ FullContact.configure do |config|
11
+ @keys.each do |key|
12
+ config.send("#{key}=", key)
13
+ end
14
+ end
15
+ end
16
+
17
+ after do
18
+ FullContact.reset
19
+ end
20
+
21
+ it "should inherit module configuration" do
22
+ api = FullContact::API.new
23
+ @keys.each do |key|
24
+ api.send(key).should == key
25
+ end
26
+ end
27
+
28
+ context "with class configuration" do
29
+
30
+ before do
31
+ @configuration = {
32
+ :api_key => 'api_key',
33
+ :adapter => :typhoeus,
34
+ :endpoint => 'http://tumblr.com/',
35
+ :gateway => 'apigee-1111.apigee.com',
36
+ :format => :xml,
37
+ :proxy => 'http://erik:sekret@proxy.example.com:8080',
38
+ :user_agent => 'Custom User Agent',
39
+ }
40
+ end
41
+
42
+ context "during initialization"
43
+
44
+ it "should override module configuration" do
45
+ api = FullContact::API.new(@configuration)
46
+ @keys.each do |key|
47
+ api.send(key).should == @configuration[key]
48
+ end
49
+ end
50
+
51
+ context "after initilization" do
52
+
53
+ it "should override module configuration after initialization" do
54
+ api = FullContact::API.new
55
+ @configuration.each do |key, value|
56
+ api.send("#{key}=", value)
57
+ end
58
+ @keys.each do |key|
59
+ api.send(key).should == @configuration[key]
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ describe FullContact::Client do
4
+ FullContact::Configuration::VALID_FORMATS.each do |format|
5
+ context ".new(:format => '#{format}')" do
6
+ before do
7
+ @client = FullContact::Client.new(:format => format, :api_key => 'api_key')
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'helper'
2
+
3
+ describe FullContact::Client do
4
+ it "should connect using the endpoint configuration" do
5
+ client = FullContact::Client.new
6
+ endpoint = URI.parse(client.api_endpoint)
7
+ connection = client.send(:connection).build_url(nil).to_s
8
+ connection.should == endpoint.to_s
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,240 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fullcontact
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon West
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: maruku
16
+ requirement: &70317436544560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70317436544560
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70317436544060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70317436544060
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70317436543600 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.9'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70317436543600
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70317436543140 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70317436543140
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov
60
+ requirement: &70317436542680 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '0.4'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70317436542680
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: &70317436542220 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.6'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70317436542220
80
+ - !ruby/object:Gem::Dependency
81
+ name: yard
82
+ requirement: &70317436541760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: '0.7'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70317436541760
91
+ - !ruby/object:Gem::Dependency
92
+ name: hashie
93
+ requirement: &70317436541300 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.1.0
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *70317436541300
102
+ - !ruby/object:Gem::Dependency
103
+ name: faraday
104
+ requirement: &70317436529820 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.6.1
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: *70317436529820
113
+ - !ruby/object:Gem::Dependency
114
+ name: faraday_middleware
115
+ requirement: &70317436529140 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: 0.6.3
121
+ type: :runtime
122
+ prerelease: false
123
+ version_requirements: *70317436529140
124
+ - !ruby/object:Gem::Dependency
125
+ name: multi_json
126
+ requirement: &70317436528380 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: *70317436528380
135
+ - !ruby/object:Gem::Dependency
136
+ name: multi_xml
137
+ requirement: &70317436527860 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 0.2.0
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: *70317436527860
146
+ - !ruby/object:Gem::Dependency
147
+ name: rash
148
+ requirement: &70317436527400 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: 0.3.0
154
+ type: :runtime
155
+ prerelease: false
156
+ version_requirements: *70317436527400
157
+ description: A Ruby wrapper for the FullContact API
158
+ email:
159
+ - brawest@gmail.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .document
165
+ - .gitignore
166
+ - .rspec
167
+ - Gemfile
168
+ - LICENSE.md
169
+ - README.md
170
+ - Rakefile
171
+ - VERSION
172
+ - fullcontact.gemspec
173
+ - lib/faraday/request/gateway.rb
174
+ - lib/faraday/response/fullcontact_errors.rb
175
+ - lib/faraday/response/raise_http_4xx.rb
176
+ - lib/faraday/response/raise_http_5xx.rb
177
+ - lib/fullcontact.rb
178
+ - lib/fullcontact/api.rb
179
+ - lib/fullcontact/client.rb
180
+ - lib/fullcontact/client/person.rb
181
+ - lib/fullcontact/configuration.rb
182
+ - lib/fullcontact/connection.rb
183
+ - lib/fullcontact/error.rb
184
+ - lib/fullcontact/request.rb
185
+ - lib/fullcontact/version.rb
186
+ - spec/faraday/response_spec.rb
187
+ - spec/fixtures/person.json
188
+ - spec/fullcontact_spec.rb
189
+ - spec/helper.rb
190
+ - spec/ruby_fullcontact/api_spec.rb
191
+ - spec/ruby_fullcontact/client/person_spec.rb
192
+ - spec/ruby_fullcontact/client_spec.rb
193
+ - vendor/cache/addressable-2.2.6.gem
194
+ - vendor/cache/faraday-0.6.1.gem
195
+ - vendor/cache/maruku-0.6.0.gem
196
+ - vendor/cache/multi_json-1.0.3.gem
197
+ - vendor/cache/multi_xml-0.2.2.gem
198
+ - vendor/cache/syntax-1.0.0.gem
199
+ homepage: https://github.com/brandonmwest/rainmaker
200
+ licenses: []
201
+ post_install_message: ! '
202
+
203
+ -------------------------------------------------------------
204
+
205
+ Follow me on Twitter! http://twitter.com/brandonmwest
206
+
207
+ -------------------------------------------------------------
208
+
209
+
210
+ '
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ! '>='
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ! '>='
224
+ - !ruby/object:Gem::Version
225
+ version: 1.3.6
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 1.8.11
229
+ signing_key:
230
+ specification_version: 3
231
+ summary: Ruby wrapper for the FullContact API
232
+ test_files:
233
+ - spec/faraday/response_spec.rb
234
+ - spec/fixtures/person.json
235
+ - spec/fullcontact_spec.rb
236
+ - spec/helper.rb
237
+ - spec/ruby_fullcontact/api_spec.rb
238
+ - spec/ruby_fullcontact/client/person_spec.rb
239
+ - spec/ruby_fullcontact/client_spec.rb
240
+ has_rdoc: