diff --git a/README.md b/README.md index 8e8385a..6de76f4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Changes ------- 0.6.0 - Removal of timeoutSeconds parameter. This parameter is automatically stripped from your request if included. +0.7.0 - Added support for cardReader API Installation ------------ @@ -43,6 +44,15 @@ Usage Examples # Get person's family_name puts person.contact_info.family_name + + # Gets a list of all the cards a user has scanned + cards = FullContact.card_reader + + # cards.total_pages will give you the number of pages you can request. + # cards.total_records will give you the total number of cards FullContact has on your account. + + # Gets 2nd page of cards (note: pagination starts at 0) + cards = FullContact.card_reader(page:1) Contributions ------------- diff --git a/lib/fullcontact/client.rb b/lib/fullcontact/client.rb index a5f7b66..b5e1952 100644 --- a/lib/fullcontact/client.rb +++ b/lib/fullcontact/client.rb @@ -6,9 +6,11 @@ class Client < API # order to avoid a superclass mismatch error, allowing those modules to be # Client-namespaced. require 'fullcontact/client/person' + require 'fullcontact/client/card_reader' alias :api_endpoint :endpoint include FullContact::Client::Person + include FullContact::Client::CardReader end end diff --git a/lib/fullcontact/client/card_reader.rb b/lib/fullcontact/client/card_reader.rb new file mode 100644 index 0000000..c21d9bf --- /dev/null +++ b/lib/fullcontact/client/card_reader.rb @@ -0,0 +1,13 @@ +module FullContact + class Client + module CardReader + # Returns extended information for a given person (email, phone, twitter or facebook) + # + def card_reader(options={}, faraday_options={}) + response = get('cardReader', options, false, faraday_options) + format.to_s.downcase == 'xml' ? response['response'] : response + end + + end + end +end diff --git a/lib/fullcontact/version.rb b/lib/fullcontact/version.rb index f511061..3cc4553 100644 --- a/lib/fullcontact/version.rb +++ b/lib/fullcontact/version.rb @@ -1,3 +1,3 @@ module FullContact - VERSION = "0.6.1" + VERSION = "0.7.0" end diff --git a/spec/fixtures/card_reader.json b/spec/fixtures/card_reader.json new file mode 100644 index 0000000..eb19c3a --- /dev/null +++ b/spec/fixtures/card_reader.json @@ -0,0 +1,256 @@ + { + "count": 2, + "results": [ + { + "vCardUrl": "https://d1h3f0foa0xzdz.cloudfront.net/85272/38DCH97KHH977EFG620F5TGH5VAQJG_c.vcf", + "lastWebhookAttempt": "2014-03-31T23:18:29.000Z", + "URID": "59760208-BF9A-468D-A0A6-E4FEAD1EECA1", + "status": "CALLBACK_MADE", + "webhookUrl": "https://sfdc-api.fullcontact.com/sfdc-api/cardReader/webhook", + "submitted": "2014-03-31T22:12:12.000Z", + "unverifiedFields": [ + "organizations[0]", + "urls[1]" + ], + "params": { + "apns": "c452031e60f21637058aa9ceeb34e4410ff5d71037f64b9d08e523fc769a0fef", + "longitude": "-104.872340", + "sf": "{\n\n}", + "latitude": "39.757752", + "notes": "", + "recordType": "0", + "version": "2.4" + }, + "contact": { + "photos": [{ + "primary": false, + "value": "https://example.net/123456-front.jpeg", + "type": "BusinessCard" + }], + "urls": [{ + "value": "http://example.com", + "type": "Company" + }], + "organizations": [{ + "title": null, + "isPrimary": true, + "name": "Example Corp." + }], + "name": { + "middleName": null, + "honorificPrefix": null, + "familyName": "Sample", + "givenName": "Joan", + "honorificSuffix": null + }, + "phoneNumbers": [ + { + "value": "+1 303-555-1212", + "type": "Work Fax" + }, + { + "value": "+1 720-555-1212", + "type": "Work" + } + ], + "addresses": [{ + "streetAddress": "123 Main Ave #304", + "region": "CO", + "formatted": null, + "postalCode": "80202", + "extendedAddress": null, + "locality": "Denver", + "type": "Work", + "country": "United States" + }] + }, + "id": "f191f5afc917d794fb8844f1f955ecc99bfca10f", + "contactId": "4LFKyufMSU", + "webhookAttempts": 1, + "addressBookId": "c977be6bf27a6c660cd4a8c1293e4ab1be81c03a", + "quality": "MEDIUM", + "unverifiedContact": { + "photos": [{ + "primary": false, + "value": "https://example.net/123456-front.jpeg", + "type": "BusinessCard" + }], + "urls": [{ + "value": "http://example.com", + "type": "Company" + }], + "organizations": [{ + "title": null, + "isPrimary": true, + "name": "Example Corp." + }], + "name": { + "middleName": null, + "honorificPrefix": null, + "familyName": "Sample", + "givenName": "Joan", + "honorificSuffix": null + }, + "phoneNumbers": [ + { + "value": "+1 303-555-1212", + "type": "Work Fax" + }, + { + "value": "+1 720-555-1212", + "type": "Work" + } + ], + "addresses": [{ + "streetAddress": "123 Main Ave #304", + "region": "CO", + "formatted": null, + "postalCode": "80202", + "extendedAddress": null, + "locality": "Denver", + "type": "Work", + "country": "United States" + }] + }, + "unverifiedVCardUrl": "https://d1h3f0foa0xzdz.cloudfront.net/85272/38DCH97KHH797EFG620F5TGH5VAQJG.vcf" + }, + { + "vCardUrl": "https://d1h3f0foa0xzdz.cloudfront.net/85272/2Y6VR14IXKO6PY019TNAFX3YSAMA9E_c.vcf", + "lastWebhookAttempt": "2014-03-20T00:53:12.000Z", + "URID": "05E93102-BA85-4369-9B98-9EAB814CABB0", + "status": "CALLBACK_MADE", + "webhookUrl": "https://sfdc-api.fullcontact.com/sfdc-api/cardReader/webhook", + "submitted": "2014-03-19T20:38:58.000Z", + "unverifiedFields": [ + "urls[1]", + "name[2]" + ], + "params": { + "apns": "c452031e60f21637058aa9ceeb34e4410ff5d71037f64b9d08e523fc769a0fef", + "longitude": "-105.016022", + "sf": "{\n\n}", + "latitude": "39.753488", + "notes": "", + "recordType": "0", + "version": "2.4" + }, + "contact": { + "photos": [ + { + "primary": false, + "value": "https://d1h3f0foa0xzdz.cloudfront.net/85272/dd587b781e539b98411d626360a10c251e76d2df-front.jpeg", + "type": "BusinessCard" + }, + { + "primary": false, + "value": "https://d1h3f0foa0xzdz.cloudfront.net/85272/dd587b781e539b98411d626360a10c251e76d2df-back.jpeg", + "type": "BusinessCard" + } + ], + "urls": [{ + "value": "http://sweetcowicecream.com", + "type": "Company" + }], + "organizations": [{ + "title": null, + "isPrimary": true, + "name": "Sweet Cow" + }], + "emails": [{ + "value": "info@sweetcowicecream.com", + "type": "Work" + }], + "phoneNumbers": [ + { + "value": "+1 303-666-4269", + "type": "Work" + }, + { + "value": "+1 303-477-3269", + "type": "Work" + } + ], + "addresses": [{ + "streetAddress": "3475 W 32nd Ave", + "region": "CO", + "formatted": null, + "postalCode": "80027", + "extendedAddress": null, + "locality": "Louisville", + "type": "Work", + "country": "United States" + }] + }, + "id": "dd587b781e539b98411d626360a10c251e76d2df", + "contactId": "2qMB12rhRG", + "webhookAttempts": 2, + "addressBookId": "c977be6bf72a6c660cd4a8c1293e4ab1be81c03a", + "quality": "MEDIUM", + "unverifiedContact": { + "photos": [ + { + "primary": false, + "value": "https://d1h3f0foa0xzdz.cloudfront.net/85272/dd587b781e539b98411d626360a10c251e76d2df-front.jpeg", + "type": "BusinessCard" + }, + { + "primary": false, + "value": "https://d1h3f0foa0xzdz.cloudfront.net/85272/dd587b781e539b98411d626360a10c251e76d2df-back.jpeg", + "type": "BusinessCard" + } + ], + "urls": [ + { + "value": "http://sweetcowicecream.com", + "type": "Company" + }, + { + "value": "www.sweetcowicwstram.com", + "type": "Company" + } + ], + "organizations": [{ + "title": null, + "isPrimary": true, + "name": "Sweet Cow" + }], + "name": { + "middleName": null, + "honorificPrefix": null, + "familyName": "Barn", + "givenName": "Denver", + "honorificSuffix": null + }, + "emails": [{ + "value": "info@sweetcowicecream.com", + "type": "Work" + }], + "phoneNumbers": [ + { + "value": "+1 303-666-4269", + "type": "Work" + }, + { + "value": "+1 303-477-3269", + "type": "Work" + } + ], + "addresses": [{ + "streetAddress": "3475 W 32nd Ave", + "region": "CO", + "formatted": null, + "postalCode": "80027", + "extendedAddress": null, + "locality": "Louisville", + "type": "Work", + "country": "United States" + }] + }, + "unverifiedVCardUrl": "https://d1h3f0foa0xzdz.cloudfront.net/85272/2Y6VR14IXKO6PY019TNAFX3YSAMA9E.vcf" + } + ], + "status": 200, + "totalRecords": 2, + "currentPage": 0, + "totalPages": 1 +} \ No newline at end of file diff --git a/spec/fullcontact_spec.rb b/spec/fullcontact_spec.rb index 61ad325..fd47fa3 100644 --- a/spec/fullcontact_spec.rb +++ b/spec/fullcontact_spec.rb @@ -9,31 +9,39 @@ context "when delegating to a client" do before do - FullContact.configure do |config| - config.api_key = "api_key" - end + FullContact.configure do |config| + config.api_key = "api_key" + end + + stub_get("person.json"). + with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}). + to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("person.json"). - with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}). - to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("person.json"). + with(:query => {:apiKey => "api_key", :twitter => "brawtest"}). + to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("person.json"). - with(:query => {:apiKey => "api_key", :twitter => "brawtest"}). - to_return(:body => fixture("person.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("cardReader.json"). + with(:query => {:apiKey => "api_key"}). + to_return(:body => fixture("card_reader.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + + stub_get("cardReader.json"). + with(:query => {:apiKey => "api_key", :page => 2}). + to_return(:body => fixture("card_reader.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "should get the correct resource" do FullContact.person(email: "brawest@gmail.com") a_get("person.json") - .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}) - .should have_been_made + .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}) + .should have_been_made end it "should strip the timeoutSeconds parameter" do FullContact.person(email: "brawest@gmail.com", timeoutSeconds: 30) a_get("person.json") - .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}) - .should have_been_made + .with(:query => {:apiKey => "api_key", :email => "brawest@gmail.com"}) + .should have_been_made end it "should return the same results as a client by email" do @@ -43,6 +51,14 @@ it "should return the same results as a client by twitter" do FullContact.person(:twitter => "brawtest").should == FullContact::Client.new.person(:twitter => "brawtest") end + + it "should return cardReader results to a client" do + FullContact.card_reader.should == FullContact::Client.new.card_reader + end + + it "should return the specified page of cardReader results to a client" do + FullContact.card_reader(:page => 2).should == FullContact::Client.new.card_reader(:page => 2 ) + end end describe '.respond_to?' do diff --git a/spec/ruby_fullcontact/client/card_reader_spec.rb b/spec/ruby_fullcontact/client/card_reader_spec.rb new file mode 100644 index 0000000..c011ed2 --- /dev/null +++ b/spec/ruby_fullcontact/client/card_reader_spec.rb @@ -0,0 +1,12 @@ +require 'helper' + +describe FullContact::Client do + FullContact::Configuration::VALID_FORMATS.each do |format| + context ".new(:format => '#{format}')" do + before do + @client = FullContact::Client.new(:format => format, :api_key => 'api_key') + end + + end + end +end