Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add GetProfileByEmail #4

Merged
merged 2 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/snov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
103 changes: 103 additions & 0 deletions lib/snov/fake_client/post_v1_get-profile-by-email.json
Original file line number Diff line number Diff line change
@@ -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"
}
84 changes: 84 additions & 0 deletions lib/snov/get_profile_by_email.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/snov/get_prospects_by_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
6 changes: 6 additions & 0 deletions spec/snov/fake_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
103 changes: 103 additions & 0 deletions spec/snov/get_profile_by_email_spec.json
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions spec/snov/get_profile_by_email_spec.rb
Original file line number Diff line number Diff line change
@@ -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