diff --git a/README.md b/README.md index 40a0992..ccac01c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,34 @@ Or install it yourself as: set `SNOV_USER_ID` and `SNOV_SECRET` environment variables + +### GetProfileByEmail + +see https://snov.io/api#GetProfileByEmail + +```ruby + prospect = Snov::GetProfileByEmail.new(email: "gavin.vanrooyen@octagon.com") + + puts prospect.success + puts prospect.id + puts prospect.name + puts prospect.first_name + puts prospect.last_name + puts prospect.industry + puts prospect.country + puts prospect.locality + prospect.social.each do |social_info| + puts social.link + puts social.type + end + prospect.current_jobs.each do |social_info| + puts social.company_name + puts social.position + # etc + end + # etc +``` + ### GetProspectList see https://snov.io/api#FindProspectbyEmail diff --git a/lib/snov.rb b/lib/snov.rb index 2eb51f4..d5aba9d 100644 --- a/lib/snov.rb +++ b/lib/snov.rb @@ -19,6 +19,7 @@ def self.use_fake? require 'active_model' require 'snov/client' require 'snov/fake_client' +require 'snov/get_profile_by_email' require 'snov/get_all_prospects_from_list' require 'snov/get_prospects_by_email' require 'snov/get_prospect_list' diff --git a/lib/snov/fake_client/post_v1_get-profile-by-email.json b/lib/snov/fake_client/post_v1_get-profile-by-email.json new file mode 100644 index 0000000..f42857b --- /dev/null +++ b/lib/snov/fake_client/post_v1_get-profile-by-email.json @@ -0,0 +1,103 @@ +{ + "success": true, + "id": 301592, + "source": "linkedIn", + "name": "Lizi Hamer", + "firstName": "Lizi", + "lastName": "Hamer", + "logo": "https://app.snov.io/img/peoples/010fcf23c70dfa68d880545ec89a9215.jpg", + "industry": null, + "country": "Singapore", + "locality": "Singapore", + "social": [ + { + "link": "https://www.linkedin.com/in/lizihamer/", + "type": "linkedIn" + }, + { + "link": "https://twitter.com/LiziHamer", + "type": "twitter" + } + ], + "currentJobs": [ + { + "companyName": "Octagon", + "position": "Regional Creative Director", + "socialLink": "https://www.linkedin.com/company/165282", + "site": "www.octagon.com", + "locality": "Greater New York City Area", + "state": "Connecticut", + "city": "Stamford", + "street": "290 Harbor Dr", + "street2": "2nd Floor", + "postal": "06902", + "founded": "1983", + "startDate": "2016-01-31", + "endDate": null, + "size": "1-10", + "industry": "Marketing and Advertising", + "companyType": "Public Company", + "country": "United States" + }, + { + "companyName": "SisuGirls", + "position": "Co Founder", + "socialLink": "https://www.linkedin.com/company/3841118", + "site": "http://www.sisugirls.org", + "locality": null, + "state": "SG", + "city": "Singapore", + "street": "33-03 Hong Leong Building", + "street2": null, + "postal": null, + "founded": "2014", + "startDate": "2015-07-31", + "endDate": null, + "size": "1-10", + "industry": "Health, Wellness and Fitness", + "companyType": null, + "country": "Singapore" + } + ], + "previousJobs": [ + { + "companyName": "Fusion Co-innovation Labs", + "position": "Creative Entrepreneur", + "socialLink": null, + "site": null, + "locality": null, + "state": null, + "city": null, + "street": null, + "street2": null, + "postal": null, + "founded": null, + "startDate": "2013-05-31", + "endDate": "2013-10-31", + "size": null, + "industry": null, + "companyType": null, + "country": null + }, + { + "companyName": "Russell Commission", + "position": "Youth Advisory Board Member", + "socialLink": null, + "site": null, + "locality": null, + "state": null, + "city": null, + "street": null, + "street2": null, + "postal": null, + "founded": null, + "startDate": "2004-06-30", + "endDate": "2006-06-30", + "size": null, + "industry": null, + "companyType": null, + "country": null + } + ], + "lastUpdateDate": "2018-02-07 10:12:28" + } \ No newline at end of file diff --git a/lib/snov/get_profile_by_email.rb b/lib/snov/get_profile_by_email.rb new file mode 100644 index 0000000..a3eb900 --- /dev/null +++ b/lib/snov/get_profile_by_email.rb @@ -0,0 +1,84 @@ +require 'active_support/core_ext/array' + +module Snov + class GetProfileByEmail + attr_reader :client, :email + + def initialize(email:, client: Snov.client) + @client = client + @email = email.to_str + end + + def each(&block) + prospects.each(&block) + end + + def prospect + @prospect ||= ProspectResult.new(raw_result) + end + + def method_missing(method_name, *arguments, &block) + if prospect.respond_to?(method_name) + prospect.public_send(method_name, *arguments, &block) + else + super + end + end + + def respond_to_missing?(method_name, include_private = false) + prospect.respond_to?(method_name) || super + end + + def raw_result + @raw_result ||= client.post("/v1/get-profile-by-email", + 'email' => email) + .deep_transform_keys! { |key| key.underscore } + end + + class Job + include ActiveModel::Model + + attr_accessor :company_name, :position, :social_link, :site, :locality, :state, :city + attr_accessor :street, :street2, :postal, :founded, :start_date, :end_date, :size + attr_accessor :industry, :company_type, :country + end + + class Social + include ActiveModel::Model + + attr_accessor :link, :type + end + + class List + include ActiveModel::Model + + attr_accessor :id, :name + end + + class ProspectResult + include ActiveModel::Model + + attr_accessor :id, :name, :first_name, :last_name, :industry, :country, :locality, :success, :source + attr_accessor :logo, :last_update_date, :message + attr_reader :social, :current_jobs, :previous_jobs + + def social=(val) + @social = Array.wrap(val).map do |rel| + Social.new(rel) + end + end + + def current_jobs=(val) + @current_jobs = Array.wrap(val).map do |rel| + Job.new(rel) + end + end + + def previous_jobs=(val) + @previous_jobs = Array.wrap(val).map do |rel| + Job.new(rel) + end + end + end + end +end diff --git a/lib/snov/get_prospects_by_email.rb b/lib/snov/get_prospects_by_email.rb index 088287e..df56de7 100644 --- a/lib/snov/get_prospects_by_email.rb +++ b/lib/snov/get_prospects_by_email.rb @@ -52,7 +52,7 @@ class ProspectResult include ActiveModel::Model attr_accessor :id, :name, :first_name, :last_name, :industry, :country, :locality - attr_reader :social + attr_reader :social, :current_job, :previous_job, :lists, :campaigns, :last_update_date def social=(val) @social = Array.wrap(val).map do |rel| diff --git a/spec/snov/fake_client_spec.rb b/spec/snov/fake_client_spec.rb index f9b7675..485ec49 100644 --- a/spec/snov/fake_client_spec.rb +++ b/spec/snov/fake_client_spec.rb @@ -17,6 +17,12 @@ module Snov expect(result).to be_present end + it '/v1/get-profile-by-email' do + result = subject.post("/v1/get-profile-by-email") + + expect(result).to be_present + end + it 'when /v1/get-prospects-by-email' do result = subject.post("/v1/get-prospects-by-email") diff --git a/spec/snov/get_profile_by_email_spec.json b/spec/snov/get_profile_by_email_spec.json new file mode 100644 index 0000000..c08668d --- /dev/null +++ b/spec/snov/get_profile_by_email_spec.json @@ -0,0 +1,103 @@ +{ + "success": true, + "id": 301592, + "source": "linkedIn", + "name": "Lizi Hamer", + "firstName": "Lizi", + "lastName": "Hamer", + "logo": "https://app.snov.io/img/peoples/010fcf23c70dfa68d880545ec89a9215.jpg", + "industry": null, + "country": "Singapore", + "locality": "Singapore", + "social": [ + { + "link": "https://www.linkedin.com/in/lizihamer/", + "type": "linkedIn" + }, + { + "link": "https://twitter.com/LiziHamer", + "type": "twitter" + } + ], + "currentJobs": [ + { + "companyName": "Octagon", + "position": "Regional Creative Director", + "socialLink": "https://www.linkedin.com/company/165282", + "site": "www.octagon.com", + "locality": "Greater New York City Area", + "state": "Connecticut", + "city": "Stamford", + "street": "290 Harbor Dr", + "street2": "2nd Floor", + "postal": "06902", + "founded": "1983", + "startDate": "2016-01-31", + "endDate": null, + "size": "1-10", + "industry": "Marketing and Advertising", + "companyType": "Public Company", + "country": "United States" + }, + { + "companyName": "SisuGirls", + "position": "Co Founder", + "socialLink": "https://www.linkedin.com/company/3841118", + "site": "http://www.sisugirls.org", + "locality": null, + "state": "SG", + "city": "Singapore", + "street": "33-03 Hong Leong Building", + "street2": null, + "postal": null, + "founded": "2014", + "startDate": "2015-07-31", + "endDate": null, + "size": "1-10", + "industry": "Health, Wellness and Fitness", + "companyType": null, + "country": "Singapore" + } + ], + "previousJobs": [ + { + "companyName": "Fusion Co-innovation Labs", + "position": "Creative Entrepreneur", + "socialLink": null, + "site": null, + "locality": null, + "state": null, + "city": null, + "street": null, + "street2": null, + "postal": null, + "founded": null, + "startDate": "2013-05-31", + "endDate": "2013-10-31", + "size": null, + "industry": null, + "companyType": null, + "country": null + }, + { + "companyName": "Russell Commission", + "position": "Youth Advisory Board Member", + "socialLink": null, + "site": null, + "locality": null, + "state": null, + "city": null, + "street": null, + "street2": null, + "postal": null, + "founded": null, + "startDate": "2004-06-30", + "endDate": "2006-06-30", + "size": null, + "industry": null, + "companyType": null, + "country": null + } + ], + "lastUpdateDate": "2018-02-07 10:12:28" + } \ No newline at end of file diff --git a/spec/snov/get_profile_by_email_spec.rb b/spec/snov/get_profile_by_email_spec.rb new file mode 100644 index 0000000..fdde888 --- /dev/null +++ b/spec/snov/get_profile_by_email_spec.rb @@ -0,0 +1,18 @@ +module Snov + RSpec.describe GetProfileByEmail do + subject { described_class.new(client: client, email: "gavin.vanrooyen@octagon.com") } + + let(:client) { instance_double(Client) } + + before do + json = File.read(__dir__ + "/get_profile_by_email_spec.json") + allow(client).to receive(:post).with("/v1/get-profile-by-email", "email" => "gavin.vanrooyen@octagon.com") + .and_return(MultiJson.load(json)) + end + + it 'returns all' do + expect(subject).to have_attributes(name: 'Lizi Hamer') + expect(subject.social.first).to have_attributes(link: 'https://www.linkedin.com/in/lizihamer/') + end + end +end