fullcontact-api-ruby 0.1.0

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,41 @@
1
+ # Hash.to_snake_keys
2
+ class Hash
3
+ # Recursively converts CamelCase and camelBack JSON-style hash keys to
4
+ # Rubyish snake_case, suitable for use during instantiation of Ruby
5
+ # model attributes.
6
+ #
7
+ def to_snake_keys(value = self)
8
+ case value
9
+ when Array
10
+ value.map { |v| to_snake_keys(v) }
11
+ when Hash
12
+ snake_hash(value)
13
+ else
14
+ value
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def snake_hash(value)
21
+ Hash[value.map { |k, v| [underscore_key(k).to_sym, to_snake_keys(v)] }]
22
+ end
23
+
24
+ def underscore_key(k)
25
+ if k.is_a? Symbol
26
+ underscore(k.to_s).to_sym
27
+ elsif k.is_a? String
28
+ underscore(k)
29
+ else
30
+ k # Plissken can't snakify anything except strings and symbols
31
+ end
32
+ end
33
+
34
+ def underscore(string)
35
+ string.gsub(/::/, '/')
36
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
37
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
38
+ .tr('-', '_')
39
+ .downcase
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ module FullContact
2
+ # Defines HTTP request methods
3
+ module Request
4
+ # Perform an HTTP GET request
5
+ def get(path, options={}, raw=false, faraday_options={})
6
+ request(:get, path, options, raw, faraday_options)
7
+ end
8
+
9
+ private
10
+
11
+ # Perform an HTTP request
12
+ def request(method, path, options, raw=false, faraday_options={})
13
+ response = connection(raw, faraday_options).send(method) do |request|
14
+ if FullContact.options[:auth_type] == :query
15
+ options[:apiKey] = FullContact.options[:api_key]
16
+ end
17
+ request.url(formatted_path(path), options)
18
+ request.headers[FullContact::Configuration::AUTH_HEADER_NAME] = FullContact.options[:api_key]
19
+ end
20
+
21
+ raw ? response : response.body
22
+ end
23
+
24
+ def formatted_path(path)
25
+ [path, format].compact.join('.')
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module FullContact
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'fullcontact/ext/hash/to_snake_keys'
4
+ require 'fullcontact/error'
5
+ require 'fullcontact/configuration'
6
+ require 'fullcontact/api'
7
+ require 'fullcontact/client'
8
+ require 'fullcontact/version'
9
+
10
+ module FullContact
11
+ extend Configuration
12
+
13
+ # Alias for FullContact::Client.new
14
+ #
15
+ # @return [FullContact::Client]
16
+ def self.client(options={})
17
+ FullContact::Client.new(options)
18
+ end
19
+
20
+ # Delegate to FullContact::Client
21
+ def self.method_missing(method, *args, &block)
22
+ return super unless client.respond_to?(method)
23
+ client.send(method, *args, &block)
24
+ end
25
+
26
+ def self.respond_to?(method, include_private = false)
27
+ client.respond_to?(method, include_private) || super(method, include_private)
28
+ end
29
+ end
@@ -0,0 +1,57 @@
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
+ 429 => FullContact::RateLimited,
20
+ 500 => FullContact::InternalServerError,
21
+ 502 => FullContact::BadGateway,
22
+ 503 => FullContact::ServiceUnavailable,
23
+ }.each do |status, exception|
24
+ if (status >= 500)
25
+ context "when HTTP status is #{status}" do
26
+ before do
27
+ stub_get('person.json').
28
+ with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
29
+ to_return(:status => status)
30
+ end
31
+
32
+ it "should raise #{exception.name} error" do
33
+ lambda do
34
+ @client.person(:email => 'brawest@gmail.com')
35
+ end.should raise_error(exception)
36
+ end
37
+ end
38
+ else
39
+ [nil, "error", "errors"].each do |body|
40
+ context "when HTTP status is #{status} and body is #{body||='nil'}" do
41
+ before do
42
+ body_message = '{"'+body+'":"test"}' unless body.nil?
43
+ stub_get('person.json').
44
+ with(:query => {:apiKey => "api_key", :email => 'brawest@gmail.com'}).
45
+ to_return(:status => status, :body => body_message)
46
+ end
47
+
48
+ it "should raise #{exception.name} error" do
49
+ lambda do
50
+ @client.person(:email => 'brawest@gmail.com')
51
+ end.should raise_error(exception)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,191 @@
1
+
2
+ {
3
+ "status" : 200,
4
+ "requestId" : "92d5908a-8de4-4294-85d2-774051c33ef3",
5
+ "category" : [ {
6
+ "name" : "Other",
7
+ "code" : "OTHER"
8
+ } ],
9
+ "logo" : "https://d2ojpxxtu63wzl.cloudfront.net/static/e9f3aeb8965684906efa7ae514988ffb_0837a93ef09a70f8b9ff73efac18176225fd0b9cb8bf84a60c5926701b4c5033",
10
+ "website" : "https://www.fullcontact.com",
11
+ "languageLocale" : "en",
12
+ "organization" : {
13
+ "name" : "FullContact Inc.",
14
+ "approxEmployees" : 50,
15
+ "founded" : "2010",
16
+ "overview" : "Solving the world's contact information problem!",
17
+ "contactInfo" : {
18
+ "emailAddresses" : [ {
19
+ "value" : "support@fullcontact.com",
20
+ "label" : "support"
21
+ }, {
22
+ "value" : "sales@fullcontact.com",
23
+ "label" : "sales"
24
+ } ],
25
+ "phoneNumbers" : [ {
26
+ "number" : "+1 (888) 330-6943",
27
+ "label" : "other"
28
+ } ],
29
+ "addresses" : [ {
30
+ "addressLine1" : "1755 Blake Street",
31
+ "addressLine2" : "Suite 450",
32
+ "locality" : "Denver",
33
+ "region" : {
34
+ "name" : "Colorado",
35
+ "code" : "CO"
36
+ },
37
+ "country" : {
38
+ "name" : "United States",
39
+ "code" : "US"
40
+ },
41
+ "postalCode" : "80202",
42
+ "label" : "work"
43
+ } ]
44
+ },
45
+ "links" : [ {
46
+ "url" : "https://www.fullcontact.com/comments/feed",
47
+ "label" : "rss"
48
+ }, {
49
+ "url" : "https://www.fullcontact.com/home/feed",
50
+ "label" : "rss"
51
+ }, {
52
+ "url" : "https://www.fullcontact.com/developer",
53
+ "label" : "other"
54
+ }, {
55
+ "url" : "https://www.fullcontact.com/feed",
56
+ "label" : "rss"
57
+ }, {
58
+ "url" : "https://fullcontact.com/blog",
59
+ "label" : "blog"
60
+ }, {
61
+ "url" : "https://www.youtube.com/watch?v=koFtyUDbYak",
62
+ "label" : "youtube"
63
+ } ],
64
+ "images" : [ {
65
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/1c390465c39c998a59c8717034982dfc_ff8af9a9f14da29ee687053e65d2ed103b8ab6f95b1f4d0147b9077ea04a3d6c",
66
+ "label" : "facebook"
67
+ }, {
68
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/edaa53d9a080aea37ddfb85d775620a9_98a2d7beef6a5b4a53f43da4dd1a90bda21dc18f755394fdbf9b6cf3283853a0",
69
+ "label" : "twitter"
70
+ }, {
71
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/1bacd7306731a30d2a9f024eeb1dcff1_94d77dcdedbfe40707ac4a75ca4f4d2978bffc20b2e33a3288ea9e4d47f5af6c",
72
+ "label" : "twitter"
73
+ }, {
74
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/3f64db7ba9331fbd1e4cc11655e2d3d4_a2477a83cafc8a98d5533f3617f0b1db2796ad0826482e2eabdc8d3345d70c17",
75
+ "label" : "twitter"
76
+ }, {
77
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/ee07ac81180408fde663426d3b0afb3f_3a1154347631c037b9bd2b2f33d4cbc8511d58f5c11ad3cbbc319957d1a5149b",
78
+ "label" : "pinterest"
79
+ }, {
80
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/80885c5e8b570e69bdc55d29aad115cd_a1ce9fb51ea43971d861e452034056d807422a391ac8e27f76ee4a9e803698d1",
81
+ "label" : "googleplus"
82
+ }, {
83
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/4be5211e4b0129d1c8d41e84f257f343_3d84b3de68d6060243972af12a8ca67c4a595fd86a4419d50bf429e6d778ce2d",
84
+ "label" : "other"
85
+ }, {
86
+ "url" : "https://d2ojpxxtu63wzl.cloudfront.net/static/7e9aa6402ff2975e297a01243c358619_c0b8d4a63a52f4a47106494561c0332b79f848b40fcbe92336a0a17b843f44f8",
87
+ "label" : "other"
88
+ } ],
89
+ "keywords" : [ "APIs", "Boulder", "Business", "Colorado", "Contact Management", "Denver", "Developer APIs", "Marketing", "Social Media", "Software", "Techstars", "Venture Capital" ]
90
+ },
91
+ "socialProfiles" : [ {
92
+ "bio" : "FullContact automatically cleans your contacts, enriches them with social profile data, and continually syncs them with all your contact sources.\n\nFor developers, we offer a suite of contact management APIs to normalize, de-duplicate, and enrich contact data with social profiles.\n\nAs Dropbox did for files and Evernote did for notes, FullContact is doing for contacts. And we’re providing it to individuals, businesses, and developers.",
93
+ "typeId" : "facebook",
94
+ "typeName" : "Facebook",
95
+ "url" : "https://www.facebook.com/FullContactAPI",
96
+ "username" : "FullContactAPI",
97
+ "id" : "159926450745554"
98
+ }, {
99
+ "bio" : "We're solving the world's contact information problem. Get your contacts under control with @FullContactApp & check out @FullContactAPI for our APIs.",
100
+ "followers" : 6279,
101
+ "following" : 1756,
102
+ "typeId" : "twitter",
103
+ "typeName" : "Twitter",
104
+ "url" : "https://twitter.com/FullContactInc",
105
+ "username" : "FullContactInc",
106
+ "id" : "142954090"
107
+ }, {
108
+ "bio" : "The API that turns partial contact information into full contact information. We provide data enrichment, de-duplication, normalization, and much more.",
109
+ "followers" : 5032,
110
+ "following" : 2444,
111
+ "typeId" : "twitter",
112
+ "typeName" : "Twitter",
113
+ "url" : "https://twitter.com/FullContactAPI",
114
+ "username" : "FullContactAPI",
115
+ "id" : "340611236"
116
+ }, {
117
+ "bio" : "Keep your contact information clean, complete & current across all your address books.",
118
+ "followers" : 3395,
119
+ "following" : 1561,
120
+ "typeId" : "twitter",
121
+ "typeName" : "Twitter",
122
+ "url" : "https://twitter.com/FullContactApp",
123
+ "username" : "FullContactApp",
124
+ "id" : "451688048"
125
+ }, {
126
+ "bio" : "FullContact's address book brings all of your contacts into one place and keeps them automatically up to date on the web, as well as on your iPhone and iPad. \n\nAdd photos to your contacts. Find them on social networks like Twitter, Facebook, LinkedIn and of course AngelList. It's the address book that busy professionals from any walk of life can appreciate, and best of all it's free. \n\nFor developers, the suite of FullContact APIs builds powerful, complete profiles of contacts that can be included in any application.",
127
+ "followers" : 259,
128
+ "typeId" : "angellist",
129
+ "typeName" : "AngelList",
130
+ "url" : "https://angel.co/fullcontact",
131
+ "username" : "fullcontact"
132
+ }, {
133
+ "bio" : "FullContact provides a suite of cloud-based contact management solutions for businesses, developers, and individuals.",
134
+ "typeId" : "crunchbasecompany",
135
+ "typeName" : "CrunchBase",
136
+ "url" : "http://www.crunchbase.com/organization/fullcontact",
137
+ "username" : "fullcontact"
138
+ }, {
139
+ "bio" : "FullContact is the API that keeps contact information current. We build APIs that developers can integrate into their applications using any language.",
140
+ "followers" : 28,
141
+ "following" : 55,
142
+ "typeId" : "pinterest",
143
+ "typeName" : "Pinterest",
144
+ "url" : "http://www.pinterest.com/fullcontact/",
145
+ "username" : "fullcontact"
146
+ }, {
147
+ "bio" : "All your contacts in one place and automatically up-to-date. Learn more about how we're solving the world's contact information problem at https://www.fullcontact.com.",
148
+ "typeId" : "google",
149
+ "typeName" : "GooglePlus",
150
+ "url" : "https://plus.google.com/u/0/107620035082673219790",
151
+ "id" : "107620035082673219790"
152
+ }, {
153
+ "typeId" : "klout",
154
+ "typeName" : "Klout",
155
+ "url" : "http://klout.com/FullContactApp",
156
+ "username" : "FullContactApp",
157
+ "id" : "85568398087860504"
158
+ }, {
159
+ "typeId" : "klout",
160
+ "typeName" : "Klout",
161
+ "url" : "http://klout.com/FullContactAPI",
162
+ "username" : "FullContactAPI",
163
+ "id" : "33777001971317895"
164
+ }, {
165
+ "bio" : "FullContact is solving the world's contact information problem by providing APIs to software developers to keep contact information clean, complete and current. FullContact provides identity resolution for all of the disparate pieces of contact information out there on the web. We do this by aggregating billions of contact records, all with numerous attributes, including quality, freshness and frequency. Our patent pending algorithms process all of this data and automatically produce clean, accurate full contact records. As a final step, we then check each data element to make sure that it's publicly available before providing it to our customers. FullContact is a TechStars Boulder 2011 Company.",
166
+ "typeId" : "linkedincompany",
167
+ "typeName" : "LinkedIn",
168
+ "url" : "https://www.linkedin.com/company/fullcontact-inc-",
169
+ "username" : "fullcontact-inc-",
170
+ "id" : "2431118"
171
+ } ],
172
+ "traffic" : {
173
+ "topCountryRanking" : [ {
174
+ "rank" : 7914,
175
+ "locale" : "us"
176
+ }, {
177
+ "rank" : 14756,
178
+ "locale" : "in"
179
+ }, {
180
+ "rank" : 10628,
181
+ "locale" : "gb"
182
+ } ],
183
+ "ranking" : [ {
184
+ "rank" : 19254,
185
+ "locale" : "global"
186
+ }, {
187
+ "rank" : 7914,
188
+ "locale" : "us"
189
+ } ]
190
+ }
191
+ }
@@ -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,145 @@
1
+ require 'fullcontact'
2
+ require 'helper'
3
+
4
+ describe FullContact do
5
+ after do
6
+ FullContact.reset
7
+ end
8
+
9
+ context "when delegating to a client" do
10
+
11
+ before do
12
+ FullContact.configure do |config|
13
+ config.api_key = "api_key"
14
+ end
15
+
16
+ stub_get("person.json").
17
+ with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}).
18
+ to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
19
+
20
+ stub_get("person.json").
21
+ with(:query => {:apiKey => "api_key", :twitter => "brawtest"}).
22
+ to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"})
23
+
24
+ stub_get("person.json").
25
+ with(:query => {:email => "brawest@gmail.com"})
26
+ end
27
+
28
+ context "when using query auth type" do
29
+
30
+ before do
31
+ FullContact.configure do |config|
32
+ config.auth_type = :query
33
+ end
34
+ end
35
+
36
+ it "should get the correct resource" do
37
+ FullContact.person(email: "brawest@gmail.com")
38
+ a_get("person.json")
39
+ .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"})
40
+ .should have_been_made
41
+ end
42
+ end
43
+
44
+ context "when using header auth type" do
45
+
46
+ before do
47
+ FullContact.configure do |config|
48
+ config.auth_type = :header
49
+ end
50
+ end
51
+
52
+ it "should get the correct resource" do
53
+ FullContact.person(email: "brawest@gmail.com")
54
+ a_get("person.json")
55
+ .with(:query => {:email => "brawest@gmail.com"}, :headers => {:'X-Fullcontact-Apikey'=>'api_key'})
56
+ .should have_been_made
57
+ end
58
+ end
59
+
60
+ it "should return the same results as a client by email" do
61
+ FullContact.person(:email => "brawest@gmail.com").should == FullContact::Client.new.person(:email => "brawest@gmail.com")
62
+ end
63
+
64
+ it "should return the same results as a client by twitter" do
65
+ FullContact.person(:twitter => "brawtest").should == FullContact::Client.new.person(:twitter => "brawtest")
66
+ end
67
+ end
68
+
69
+ describe ".client" do
70
+ it "should be a FullContact::Client" do
71
+ FullContact.client.should be_a FullContact::Client
72
+ end
73
+ end
74
+
75
+ describe ".adapter" do
76
+ it "should return the default adapter" do
77
+ FullContact.adapter.should == FullContact::Configuration::DEFAULT_ADAPTER
78
+ end
79
+ end
80
+
81
+ describe ".adapter=" do
82
+ it "should set the adapter" do
83
+ FullContact.adapter = :typhoeus
84
+ FullContact.adapter.should == :typhoeus
85
+ end
86
+ end
87
+
88
+ describe ".endpoint" do
89
+ it "should return the default endpoint" do
90
+ FullContact.endpoint.should == FullContact::Configuration::DEFAULT_ENDPOINT
91
+ end
92
+ end
93
+
94
+ describe ".endpoint=" do
95
+ it "should set the endpoint" do
96
+ FullContact.endpoint = 'http://tumblr.com/'
97
+ FullContact.endpoint.should == 'http://tumblr.com/'
98
+ end
99
+ end
100
+
101
+ describe ".format" do
102
+ it "should return the default format" do
103
+ FullContact.format.should == FullContact::Configuration::DEFAULT_FORMAT
104
+ end
105
+ end
106
+
107
+ describe ".format=" do
108
+ it "should set the format" do
109
+ FullContact.format = 'xml'
110
+ FullContact.format.should == 'xml'
111
+ end
112
+ end
113
+
114
+ describe ".user_agent" do
115
+ it "should return the default user agent" do
116
+ FullContact.user_agent.should == FullContact::Configuration::DEFAULT_USER_AGENT
117
+ end
118
+ end
119
+
120
+ describe ".user_agent" do
121
+ it "should return the default user agent" do
122
+ expect(FullContact.user_agent).to satisfy { |ua| ua.start_with? 'FullContact Ruby Client/' }
123
+ end
124
+ end
125
+
126
+ describe ".user_agent=" do
127
+ it "should set the user_agent" do
128
+ FullContact.user_agent = 'Custom User Agent'
129
+ FullContact.user_agent.should == 'Custom User Agent'
130
+ end
131
+ end
132
+
133
+ describe ".configure" do
134
+
135
+ FullContact::Configuration::VALID_OPTIONS_KEYS.each do |key|
136
+
137
+ it "should set the #{key}" do
138
+ FullContact.configure do |config|
139
+ config.send("#{key}=", key)
140
+ FullContact.send(key).should == key
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+ require 'simplecov'
4
+
5
+ WebMock.disable_net_connect!(:allow => 'codeclimate.com')
6
+
7
+ SimpleCov.start
8
+
9
+ def a_get(path)
10
+ a_request(:get, FullContact.endpoint + path)
11
+ end
12
+
13
+ def stub_get(path)
14
+ stub_request(:get, FullContact.endpoint + path)
15
+ end
16
+
17
+ def fixture_path
18
+ File.expand_path("../fixtures", __FILE__)
19
+ end
20
+
21
+ def fixture(file)
22
+ File.new(fixture_path + '/' + file)
23
+ end
@@ -0,0 +1,68 @@
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
+ :auth_type => :headers,
34
+ :adapter => :typhoeus,
35
+ :endpoint => 'http://tumblr.com/',
36
+ :gateway => 'apigee-1111.apigee.com',
37
+ :format => :xml,
38
+ :proxy => 'http://erik:sekret@proxy.example.com:8080',
39
+ :user_agent => 'Custom User Agent',
40
+ :skip_rubyize => true,
41
+ :include_headers_in_response => true
42
+ }
43
+ end
44
+
45
+ context "during initialization"
46
+
47
+ it "should override module configuration" do
48
+ api = FullContact::API.new(@configuration)
49
+ @keys.each do |key|
50
+ api.send(key).should == @configuration[key]
51
+ end
52
+ end
53
+
54
+ context "after initilization" do
55
+
56
+ it "should override module configuration after initialization" do
57
+ api = FullContact::API.new
58
+ @configuration.each do |key, value|
59
+ api.send("#{key}=", value)
60
+ end
61
+ @keys.each do |key|
62
+ api.send(key).should == @configuration[key]
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ describe FullContact::Client::Company 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
+
13
+ context "when parsing a response" do
14
+
15
+ before do
16
+ FullContact.configure do |config|
17
+ config.api_key = "api_key"
18
+ end
19
+
20
+ stub_get("company/lookup.json").
21
+ with(:query => {:apiKey => "api_key", :domain => "fullcontact.com"}).
22
+ to_return(:body => fixture("company.json"), :headers => {:content_type => "application/json; charset=utf-8"})
23
+
24
+ stub_get("company/lookup.json").
25
+ with(:query => {:apiKey => "api_key", :domain => "fullcontact.com"}).
26
+ to_return(:body => fixture("company.json"), :headers => {:content_type => "application/json; charset=utf-8"})
27
+ end
28
+
29
+ it 'should rubyize keys' do
30
+ expect(FullContact.company(domain: "fullcontact.com").organization.name).to(eq("FullContact Inc."))
31
+
32
+ expect(FullContact.company(domain: "fullcontact.com")).to satisfy do |v|
33
+ v.keys.all? { |k| !k.match(/[A-Z]/) }
34
+ end
35
+ end
36
+ end
37
+ end