fullcontacter 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.document +5 -0
  2. data/.gitignore +53 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.md +20 -0
  6. data/README.md +36 -0
  7. data/Rakefile +25 -0
  8. data/VERSION +1 -0
  9. data/bugs.txt +2 -0
  10. data/fullcontact.gemspec +34 -0
  11. data/lib/faraday/request/gateway.rb +18 -0
  12. data/lib/faraday/response/fullcontact_errors.rb +33 -0
  13. data/lib/faraday/response/raise_http_4xx.rb +45 -0
  14. data/lib/faraday/response/raise_http_5xx.rb +24 -0
  15. data/lib/fullcontact.rb +27 -0
  16. data/lib/fullcontact/api.rb +21 -0
  17. data/lib/fullcontact/client.rb +32 -0
  18. data/lib/fullcontact/client/batch_process.rb +35 -0
  19. data/lib/fullcontact/client/contact.rb +119 -0
  20. data/lib/fullcontact/client/contact_list.rb +84 -0
  21. data/lib/fullcontact/client/icon.rb +35 -0
  22. data/lib/fullcontact/client/name.rb +167 -0
  23. data/lib/fullcontact/client/person.rb +94 -0
  24. data/lib/fullcontact/client/provisioning.rb +28 -0
  25. data/lib/fullcontact/client/snapshot.rb +31 -0
  26. data/lib/fullcontact/client/subscription.rb +45 -0
  27. data/lib/fullcontact/client/user.rb +28 -0
  28. data/lib/fullcontact/configuration.rb +95 -0
  29. data/lib/fullcontact/connection.rb +36 -0
  30. data/lib/fullcontact/error.rb +35 -0
  31. data/lib/fullcontact/request.rb +43 -0
  32. data/lib/fullcontact/version.rb +3 -0
  33. data/spec/faraday/response_spec.rb +56 -0
  34. data/spec/fixtures/clear_contact_list.json +3 -0
  35. data/spec/fixtures/contact_history.json +16 -0
  36. data/spec/fixtures/create_contact_list.json +4 -0
  37. data/spec/fixtures/create_snapshot.json +7 -0
  38. data/spec/fixtures/create_subscription.json +4 -0
  39. data/spec/fixtures/deduce_by_email.json +13 -0
  40. data/spec/fixtures/deduce_by_username.json +13 -0
  41. data/spec/fixtures/delete_contact.json +4 -0
  42. data/spec/fixtures/delete_contact_list.json +3 -0
  43. data/spec/fixtures/delete_subscription.json +3 -0
  44. data/spec/fixtures/get_contact.json +20 -0
  45. data/spec/fixtures/get_contact_lists.json +11 -0
  46. data/spec/fixtures/get_contacts_in_a_list.json +41 -0
  47. data/spec/fixtures/get_enriched_contact.json +261 -0
  48. data/spec/fixtures/get_updates.json +252 -0
  49. data/spec/fixtures/has_enriched_updates.json +4 -0
  50. data/spec/fixtures/list_snapshots.json +7 -0
  51. data/spec/fixtures/list_subscriptions.json +10 -0
  52. data/spec/fixtures/normalize.json +27 -0
  53. data/spec/fixtures/parse.json +10 -0
  54. data/spec/fixtures/person.json +47 -0
  55. data/spec/fixtures/queue_contact_list_for_enrichment.json +3 -0
  56. data/spec/fixtures/save_enriched_contact.json +261 -0
  57. data/spec/fixtures/similarity.json +45 -0
  58. data/spec/fixtures/stats_by_family_name.json +12 -0
  59. data/spec/fixtures/stats_by_given_and_family_name.json +62 -0
  60. data/spec/fixtures/stats_by_given_name.json +57 -0
  61. data/spec/fixtures/stats_by_name.json +64 -0
  62. data/spec/fixtures/update_contact.json +9 -0
  63. data/spec/fullcontact/api_spec.rb +68 -0
  64. data/spec/fullcontact/client/contact_list_spec.rb +89 -0
  65. data/spec/fullcontact/client/contact_spec.rb +108 -0
  66. data/spec/fullcontact/client/icon_spec.rb +24 -0
  67. data/spec/fullcontact/client/name_spec.rb +121 -0
  68. data/spec/fullcontact/client/person_spec.rb +77 -0
  69. data/spec/fullcontact/client/snapshot_spec.rb +35 -0
  70. data/spec/fullcontact/client/subscription_spec.rb +47 -0
  71. data/spec/fullcontact/client_spec.rb +10 -0
  72. data/spec/fullcontact_spec.rb +114 -0
  73. data/spec/helper.rb +39 -0
  74. metadata +384 -0
@@ -0,0 +1,119 @@
1
+ module FullContact
2
+ class Client
3
+ module Contact
4
+ # Public: Creates/Modifies a contact
5
+ #
6
+ # list_id - id of the contact list to which this contact is to be added
7
+ # options - Hash containing contact data and other options
8
+ # :contact_data - Hash representing the contact information in POCO format
9
+ # :generateIds(0|1) - Whether or not ids need to be generated by the system (optional) (default: 0)
10
+ # :queue(true|false) - Check for updates on creation if true (optional) (default: false)
11
+ #
12
+ # Example
13
+ #
14
+ # contact = FullContact.update_contact(list_id, { :contact_data => data , :generateIds => 1 })
15
+ # # 'contact' contains the newly created contact
16
+ def update_contact(list_id, options)
17
+ options[:content_type] = 'application/json'
18
+ options[:request_body] = options[:contact_data]
19
+ options.delete(:contact_data)
20
+ contacts = post("contactLists/#{list_id}", options)
21
+ end
22
+
23
+ # Public: Retrieves a contact
24
+ #
25
+ # list_id - id of the contact list from which this contact is to be retrieved
26
+ # contact_id - id of the contact which is to be retrieved
27
+ # options - Hash containing additonal arguments (optional) (default: {})
28
+ # :eTag - represents a unique version of the contact. Retrieves latest version if not specified (optional)
29
+ #
30
+ # Example
31
+ #
32
+ # contact = FullContact.get_contact(list_id, contact_id)
33
+ # # contact now contains details about this contact
34
+ def get_contact(list_id, contact_id, options = {})
35
+ get("contactLists/#{list_id}/#{contact_id}", options)
36
+ end
37
+
38
+ # Public: Delete contact
39
+ #
40
+ # list_id - id of the contact list from which this contact is to be deleted
41
+ # contact_id - id of the contact which is to be deleted
42
+ #
43
+ # Example
44
+ #
45
+ # FullContact.delete_contact(list_id, contact_id)
46
+ def delete_contact(list_id, contact_id)
47
+ delete("contactLists/#{list_id}/#{contact_id}")
48
+ end
49
+
50
+ # Public: Checks if a contact has new enrichment updates available
51
+ #
52
+ # list_id - id of the contact list to which this contact belongs
53
+ # contact_id - id of the contact which needs to be checked for enrichment updates
54
+ # options - Hash containing additonal arguments (optional) (default: {})
55
+ # :eTag - represents a unique version of the contact. Retrieves latest version if not specified (optional)
56
+ #
57
+ # Example
58
+ #
59
+ # response = FullContact.has_enriched_updates?(list_id, contact_id)
60
+ # response.hasUpdates is now either true/false
61
+ def has_enriched_updates?(list_id, contact_id, options = {})
62
+ get("contactLists/#{list_id}/#{contact_id}/hasUpdates", options)
63
+ end
64
+
65
+ # Public: Gets latest updates for this contact
66
+ #
67
+ # list_id - id of the contact list to which this contact belongs
68
+ # contact_id - id of the contact whose updates are needed
69
+ #
70
+ # Example
71
+ #
72
+ # response = FullContact.get_updates(list_id, contact_id)
73
+ # response.updates now contains the hash denoting the updates for this user
74
+ def get_updates(list_id, contact_id)
75
+ get("contactLists/#{list_id}/#{contact_id}/updates")
76
+ end
77
+
78
+ # Public: Gets fully enriched version of the contact
79
+ #
80
+ # list_id - id of the contact list to which this contact belongs
81
+ # contact_id - id of the contact whose enriched version is needed
82
+ #
83
+ # Example
84
+ #
85
+ # response = FullContact.get_enriched_contact(list_id, contact_id)
86
+ # response.data now contains the hash denoting the enriched information for this contact
87
+ def get_enriched_contact(list_id, contact_id)
88
+ get("contactLists/#{list_id}/#{contact_id}/enriched")
89
+ end
90
+
91
+ # Public: Saves fully enriched version of the contact
92
+ #
93
+ # list_id - id of the contact list to which this contact belongs
94
+ # contact_id - id of the contact whose enriched version is to be saved
95
+ #
96
+ # Example
97
+ #
98
+ # response = FullContact.save_enriched_contact(list_id, contact_id)
99
+ def save_enriched_contact(list_id, contact_id)
100
+ post("contactLists/#{list_id}/#{contact_id}/enriched")
101
+ end
102
+
103
+ # Public: Retrieves a list of eTags representing the history of a contact
104
+ #
105
+ # list_id - id of the contact list to which this contact belongs
106
+ # contact_id - id of the contact whose history is needed
107
+ # options - Hash containing additional arguments (optional) (default: {})
108
+ # :actionType("Added"|"Updated"|"Deleted"|"Enriched") - filters list based on the given action type
109
+ #
110
+ # Example
111
+ #
112
+ # response = FullContact.history(list_id, contact_id, "Updated")
113
+ # response.history now contains a list of 'Update' actions, with corresponding eTags for this contact
114
+ def contact_history(list_id, contact_id, options = {})
115
+ get("contactLists/#{list_id}/#{contact_id}/history", options)
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,84 @@
1
+ module FullContact
2
+ class Client
3
+ module ContactList
4
+ # Public: Creates a contact list for the authenticating user
5
+ #
6
+ # options - a Hash containing the alias(optional) for the new list
7
+ #
8
+ # Example
9
+ #
10
+ # list = FullContact.create_contact_list(:alias => 'dummy')
11
+ # # 'list' contains the newly created contact list
12
+ def create_contact_list(options = {})
13
+ post('contactLists', options)
14
+ end
15
+
16
+ # Public: Deletes a contact list of the authenticating user
17
+ #
18
+ # list_id - id of the list object to be deleted
19
+ #
20
+ # Example
21
+ #
22
+ # list = FullContact.create_contact_list(:alias => 'dummy')
23
+ # # Delete this list now...
24
+ # FullContact.delete_contact_list(list.list_id)
25
+ def delete_contact_list(list_id)
26
+ delete("contactLists/#{list_id}")
27
+ end
28
+
29
+ # Public: Retrieves all the contact lists for the authenticating user
30
+ #
31
+ # Example
32
+ #
33
+ # lists = FullContact.get_contact_lists
34
+ # # Iterate over this list now..
35
+ # lists.each { |list| puts list.inspect }
36
+ def get_contact_lists
37
+ contact_lists = get('contactLists').lists
38
+ contact_lists.map do |list|
39
+ list.list_id = list.id
40
+ end
41
+ contact_lists
42
+ end
43
+
44
+ # Public: Gets the contacts within a contact list
45
+ #
46
+ # list_id - Id of the list from which contacts need to be retrieved
47
+ #
48
+ # Example
49
+ #
50
+ # lists = FullContact.get_contact_lists
51
+ # # Get contacts in first list now
52
+ # FullContacts.get_contacts_in_a_list(lists[0].list_id)
53
+ def get_contacts_in_a_list(list_id, options={})
54
+ get("contactLists/#{list_id}", options)
55
+ end
56
+
57
+ # Public: Queues a contact list for enrichment to search for new contact information
58
+ #
59
+ # list_id - Id of the list which needs to be queued for enrichment
60
+ #
61
+ # Example
62
+ #
63
+ # lists = FullContact.get_contact_lists
64
+ # # Enrich the contacts in first list
65
+ # FullContacts.queue_contact_list_for_enrichment(lists[0].list_id)
66
+ def queue_contact_list_for_enrichment(list_id)
67
+ post("contactLists/#{list_id}/queue")
68
+ end
69
+
70
+ # Public: Removes all contacts in a contact list
71
+ #
72
+ # list_id - Id of the list from which contacts need to be cleared
73
+ #
74
+ # Example
75
+ #
76
+ # lists = FullContact.get_contact_lists
77
+ # # Clear contacts in first list
78
+ # FullContacts.clear_contact_list(lists[0].list_id)
79
+ def clear_contact_list(list_id)
80
+ post("contactLists/#{list_id}/clear")
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,35 @@
1
+ module FullContact
2
+ class Client
3
+ # Public: Methods for interacting with icon endpoint
4
+ module Icon
5
+ # Public: Provies url to different social media icons. All icons are
6
+ # 24 bit PNG and come in 4 different sizes. Allows you to quickly
7
+ # incorporate social network icons into FullContact powered your apps.
8
+ # see http://www.fullcontact.com/docs/?category=icon for list of
9
+ # available icons
10
+ #
11
+ # type_id - String name of the icon you want. (default: 'facebook')
12
+ # size - The size parameter allows you to specify the size of icon
13
+ # that you want. Icons are available in 16, 24, 32 and 64
14
+ # pixels square. (default: '32')
15
+ # style - Allows to pick from available styles of icon
16
+ # (default: 'default')
17
+ #
18
+ # Example
19
+ #
20
+ # angel_list_icon = FullContact.get_social_icon_url('angellist','16','default')
21
+ # # 'angel_list_icon' contains url of the icon
22
+ #
23
+ # Returns url to the specified social media icon
24
+ def get_social_icon_url(type_id = 'facebook', size = '32', style = 'default')
25
+ self.format = ''
26
+ url = '/' + type_id + '/' + size + '/' + style
27
+ response = get('icon' + url, {}, true)
28
+ response.env[:response_headers]['location']
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,167 @@
1
+ module FullContact
2
+ class Client
3
+ # Public: Various methods related to name of the person
4
+ module Name
5
+ # Public: Takes quasi structured name data provided as a string and
6
+ # outputs the data in a structured manner.
7
+ #
8
+ # query - Query parameter allows you to pass a quasi-structured full
9
+ # name String which can include standard prefix, first name,
10
+ # nickname, middle name, last name and suffix.
11
+ #
12
+ # Example
13
+ #
14
+ # normalized = FullContact.normalize('John Smith')
15
+ # # 'normalized' contains normalized contact
16
+ #
17
+ # Returns normalized contact
18
+ def normalize(query)
19
+ options = {:q => query}
20
+ get('name/normalizer', options)
21
+ end
22
+
23
+ # Public: Attempts to deduce a structured name from email address. It
24
+ # also returns a likelihood based on US population data. This method is
25
+ # ideal for business email addresses due to the use of standard
26
+ # convention in corporate email address formats.
27
+ #
28
+ # email - email parameter allows to pass an email address as String
29
+ #
30
+ # Example
31
+ #
32
+ # deduced = FullContact.deduce_by_email('johndsmith79@business.com')
33
+ # # 'deduced' contains deduced contact
34
+ #
35
+ # Returns deduced contact
36
+ def deduce_by_email(email)
37
+ options = {:email => email}
38
+ get('name/deducer', options)
39
+ end
40
+
41
+ # Public: Attempts to deduce a structured name from username. It
42
+ # also returns a likelihood based on US population data.
43
+ #
44
+ # email - username parameter allows to pass username as String
45
+ #
46
+ # Example
47
+ #
48
+ # deduced = FullContact.deduce_by_username('johndsmith79')
49
+ # # 'deduced' contains deduced contact
50
+ #
51
+ # Returns deduced contact
52
+ def deduce_by_username(username)
53
+ options = {:username => username}
54
+ get('name/deducer', options)
55
+ end
56
+
57
+ # Public: The Name Similarity endpoint compares two names, given as the
58
+ # parameters q1 and q2, and returns a score indicating how similar they
59
+ # are. As the performance of different similarity algorithms can vary
60
+ # over different data sets, the endpoint provides 3 separate choices.
61
+ #
62
+ # name_one - String first name to compare
63
+ # name_two - String second name to compare
64
+ #
65
+ # Example
66
+ #
67
+ # similarity = FullContact.similarity('john','johnathan')
68
+ # # 'normalized' contains similarity of contact
69
+ #
70
+ # Returns similarity in the contact
71
+ def similarity(name_one, name_two)
72
+ options = {
73
+ :q1 => name_one,
74
+ :q2 => name_two
75
+ }
76
+ get('name/similarity', options)
77
+ end
78
+
79
+ # Public: The method can be used when you only know a single name and
80
+ # you are uncertain whether it is the given name or family name.
81
+ #
82
+ # name - String first name or last name of person about which you are
83
+ # uncertain.
84
+ #
85
+ # Example
86
+ #
87
+ # stats = FullContact.stats_by_name('John')
88
+ # # 'stats' contains stats about the contact
89
+ #
90
+ # Returns stats about the contact
91
+ def stats_by_name(name)
92
+ options = {:name => name}
93
+ get('name/stats', options)
94
+ end
95
+
96
+
97
+ # Public: The method can be used when you know that the name is a given name (first name).
98
+ #
99
+ # given_name - String parameter allows to pass given_name of the person
100
+ #
101
+ # Example
102
+ #
103
+ # stats = FullContact.stats_by_given_name('john')
104
+ # # 'stats' contains stats about the contact
105
+ #
106
+ # Returns stats about the contact
107
+ def stats_by_given_name(given_name)
108
+ options = {:givenName => given_name}
109
+ get('name/stats', options)
110
+ end
111
+
112
+ # Public: The method can be used when you know that the name is a family
113
+ # name (last name).
114
+ #
115
+ # family_name - String family name of the person
116
+ #
117
+ # Example
118
+ #
119
+ # stats = FullContact.stats_by_family_name('smith')
120
+ # # 'stats' contains stats about the contact
121
+ #
122
+ # Returns stats about the contact
123
+ def stats_by_family_name(family_name)
124
+ options = {:familyName => family_name}
125
+ get('name/stats', options)
126
+ end
127
+
128
+ # Public: The method can be use when you know both first name and last
129
+ # name of the person
130
+ #
131
+ # given_name - String first name of the person
132
+ # family_name - String last name of the person
133
+ #
134
+ # Example
135
+ #
136
+ # stats = FullContact.stats_by_given_and_family_name('john', 'smith')
137
+ # # 'stats' contains stats about the contact
138
+ #
139
+ # Returns stats about the contact
140
+ def stats_by_given_and_family_name(given_name, family_name)
141
+ options = {
142
+ :givenName => given_name,
143
+ :familyName => family_name
144
+ }
145
+ get('name/stats', options)
146
+ end
147
+
148
+ # Public: The Name Parser method can be used when you have two names but
149
+ # don't know which one is the first name and which is the last name.
150
+ #
151
+ # name - String name parameter allows you to pass an ambiguious name and
152
+ # determine what the given name and family name is.
153
+ #
154
+ # Example
155
+ #
156
+ # parsed = FullContact.parse('Smith Jon')
157
+ # # 'parsed' contains parsed contact
158
+ #
159
+ # Returns parsed contact
160
+ def parse(name)
161
+ options = {:q => name}
162
+ get('name/parser', options)
163
+ end
164
+
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,94 @@
1
+ module FullContact
2
+ class Client
3
+ module Person
4
+ # Public: Uses the person method to request more information about a specific person by email
5
+ #
6
+ # email - The email address of the person being looked up.
7
+ # options - Hash containing additional arguments (optional) (default: {})
8
+ # :timeOutSeconds - Wait for specified time, before returning a 202 (optional)
9
+ # :queue - Enqueue this email for indexing (optional)
10
+ # :callback - If specified, the response will be wrapped as JSONP in a function call. (optional)
11
+ # :webhookUrl - Delivers lookup response at specified url (required for webhook calls)
12
+ # :webhookId - Id for tracking the webhook
13
+ #
14
+ # Example
15
+ #
16
+ # response = FullContact.lookup_by_email('prafulla.kiran@gmail.com')
17
+ def lookup_by_email(email, options = {})
18
+ options[:email] = email
19
+ get('person', options)
20
+ end
21
+
22
+ # Public: Uses the person method to request more information about a specific person by phone
23
+ #
24
+ # phone - The phone number of the person being looked up.
25
+ # options - Hash containing additional arguments (optional) (default: {})
26
+ # :timeOutSeconds - Wait for specified time, before returning a 202 (optional)
27
+ # :queue - Enqueue this email for indexing (optional)
28
+ # :callback - If specified, the response will be wrapped as JSONP in a function call. (optional)
29
+ # :webhookUrl - Delivers lookup response at specified url (required for webhook calls)
30
+ # :webhookId - Id for tracking the webhook
31
+ #
32
+ # Example
33
+ #
34
+ # response = FullContact.lookup_by_phone('+910020000200')
35
+ def lookup_by_phone(phone, options = {})
36
+ options[:phone] = phone
37
+ get('person', options)
38
+ end
39
+
40
+ # Public: Uses the person method to request more information about a specific person by twitter
41
+ #
42
+ # twitter - The twitter handle of the person being looked up.
43
+ # options - Hash containing additional arguments (optional) (default: {})
44
+ # :timeOutSeconds - Wait for specified time, before returning a 202 (optional)
45
+ # :queue - Enqueue this email for indexing (optional)
46
+ # :callback - If specified, the response will be wrapped as JSONP in a function call. (optional)
47
+ # :webhookUrl - Delivers lookup response at specified url (required for webhook calls)
48
+ # :webhookId - Id for tracking the webhook
49
+ #
50
+ # Example
51
+ #
52
+ # response = FullContact.lookup_by_twitter('prafulla')
53
+ def lookup_by_twitter(twitter, options = {})
54
+ options[:twitter] = twitter
55
+ get('person', options)
56
+ end
57
+
58
+ # Public: Uses the person method to request more information about a specific person by facebook
59
+ #
60
+ # facebookUsername - The facebook username of the person being looked up.
61
+ # options - Hash containing additional arguments (optional) (default: {})
62
+ # :timeOutSeconds - Wait for specified time, before returning a 202 (optional)
63
+ # :queue - Enqueue this email for indexing (optional)
64
+ # :callback - If specified, the response will be wrapped as JSONP in a function call. (optional)
65
+ # :webhookUrl - Delivers lookup response at specified url (required for webhook calls)
66
+ # :webhookId - Id for tracking the webhook
67
+ #
68
+ # Example
69
+ #
70
+ # response = FullContact.lookup_by_facebook('prafullakiran')
71
+ def lookup_by_facebook(facebookUsername, options = {})
72
+ options[:facebookUsername] = facebookUsername
73
+ get('person', options)
74
+ end
75
+
76
+ # Public: Uses the person method to request more information about a specific person by vCard
77
+ #
78
+ # vcard_data - vcard information of the user being looked up (as a string)
79
+ # options - Hash containing additional arguments (optional) (default: {})
80
+ # :queue - Enqueue this email for indexing (optional)
81
+ #
82
+ # Example
83
+ #
84
+ # response = FullContact.lookup_by_vcard(vcard_data)
85
+ def lookup_by_vcard(vcard_data, options = {})
86
+ self.format = 'vcf'
87
+ options[:content_type] = 'text/x-vcard'
88
+ options[:request_body] = vcard_data
89
+ post('person', options)
90
+ end
91
+
92
+ end
93
+ end
94
+ end