apollo-client 1.0.4
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.
- checksums.yaml +7 -0
- data/apollo-client.gemspec +16 -0
- data/lib/apollo-client.rb +185 -0
- metadata +64 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 5b290a27cca870cf8bbc810f511b93d306d744bc0400263afb5b8892c636c168
         | 
| 4 | 
            +
              data.tar.gz: c54892abd0086c32e30d86494b2fb6bf56298b7effe5985b8d0cc554d8839177
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 050d4d8ad3eeb064ce56c574cf93bc1ecb734ebbfea9f84d531a25af108dd5926be3b39142df6a17c8ee9ce74652f94020a738713a3d90a495a04005b08bc997
         | 
| 7 | 
            +
              data.tar.gz: 5c74af95fd89c66242898fd0c1c7998c44d13518300de342472caed5f41b0d3c16f93f00409f92a916082df641aeeb0d1513f1274e3bed0f133cf884b480727e
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            Gem::Specification.new do |s|
         | 
| 2 | 
            +
                s.name        = 'apollo-client'
         | 
| 3 | 
            +
                s.version     = '1.0.4'
         | 
| 4 | 
            +
                s.date        = '2025-01-08'
         | 
| 5 | 
            +
                s.summary     = "Ruby library for connecting some enrichment services like Apillo."
         | 
| 6 | 
            +
                s.description = "Ruby library for connecting some enrichment services like Apillo."
         | 
| 7 | 
            +
                s.authors     = ["Leandro Daniel Sardi"]
         | 
| 8 | 
            +
                s.email       = 'leandro@connectionsphere.com'
         | 
| 9 | 
            +
                s.files       = [
         | 
| 10 | 
            +
                  'lib/apollo-client.rb',
         | 
| 11 | 
            +
                  'apollo-client.gemspec'
         | 
| 12 | 
            +
                ]
         | 
| 13 | 
            +
                s.homepage    = 'https://github.com/leandrosardi/blackstack-enrichment'
         | 
| 14 | 
            +
                s.license     = 'MIT'
         | 
| 15 | 
            +
                s.add_runtime_dependency 'json', '~> 2.6.3', '>= 2.6.3'
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1,185 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            #module BlackStack
         | 
| 4 | 
            +
                class ApolloClient
         | 
| 5 | 
            +
                    @@apollo_apikey = nil
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                    def initialize(h={})
         | 
| 8 | 
            +
                        @apollo_apikey = h[:apollo_apikey]
         | 
| 9 | 
            +
                        @findymail_apikey = h[:findymail_apikey]
         | 
| 10 | 
            +
                    end # def initialize
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    # Retrieve the email of a person from a LinkedIn URL
         | 
| 13 | 
            +
                    #
         | 
| 14 | 
            +
                    # Reference: https://apolloio.github.io/apollo-api-docs/?shell#enrichment-api
         | 
| 15 | 
            +
                    #
         | 
| 16 | 
            +
                    # 
         | 
| 17 | 
            +
                    def find_person_from_linkedin_url(url:)
         | 
| 18 | 
            +
                        raise 'Error: apollo_apikey is required for find_person_from_linkedin_url operation.' if @apollo_apikey.nil?
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                        ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
         | 
| 21 | 
            +
                            "api_key": "#{@apollo_apikey}",
         | 
| 22 | 
            +
                            "reveal_personal_emails": true,
         | 
| 23 | 
            +
                            "details": [
         | 
| 24 | 
            +
                                {
         | 
| 25 | 
            +
                                    "linkedin_url": "#{url}"
         | 
| 26 | 
            +
                                }
         | 
| 27 | 
            +
                            ]
         | 
| 28 | 
            +
                        }' "https://api.apollo.io/api/v1/people/bulk_match"`
         | 
| 29 | 
            +
                        j = JSON.parse(ret)
         | 
| 30 | 
            +
                        raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 31 | 
            +
                        raise "Error: #{j['error_code']}" if j['error_code']
         | 
| 32 | 
            +
                        raise "Error: #{j['error']}" if j['error']
         | 
| 33 | 
            +
                        match = j['matches'].first
         | 
| 34 | 
            +
                        return nil if match.nil?
         | 
| 35 | 
            +
                        match['email']
         | 
| 36 | 
            +
                    end # def find_person_email_from_linkedin_url
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                    # Retrieve the email of a person from his name and company.
         | 
| 39 | 
            +
                    #
         | 
| 40 | 
            +
                    # Reference: https://apolloio.github.io/apollo-api-docs/?shell#enrichment-api
         | 
| 41 | 
            +
                    #
         | 
| 42 | 
            +
                    # 
         | 
| 43 | 
            +
                    def find_person_from_name_and_company(name:, company:)
         | 
| 44 | 
            +
                        raise 'Error: apollo_apikey is required for find_person_from_name_and_company operation.' if @apollo_apikey.nil?
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                        ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
         | 
| 47 | 
            +
                            "api_key": "#{@apollo_apikey}",
         | 
| 48 | 
            +
                            "reveal_personal_emails": true,
         | 
| 49 | 
            +
                            "details": [
         | 
| 50 | 
            +
                                {
         | 
| 51 | 
            +
                                    "name": "#{name}",
         | 
| 52 | 
            +
                                    "organization_name": "#{company}"
         | 
| 53 | 
            +
                                }
         | 
| 54 | 
            +
                            ]
         | 
| 55 | 
            +
                        }' "https://api.apollo.io/api/v1/people/bulk_match"`
         | 
| 56 | 
            +
                        j = JSON.parse(ret)
         | 
| 57 | 
            +
                        raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 58 | 
            +
                        raise "Error: #{j['error_code']}" if j['error_code']
         | 
| 59 | 
            +
                        raise "Error: #{j['error']}" if j['error']
         | 
| 60 | 
            +
                        match = j['matches'].first
         | 
| 61 | 
            +
                        return nil if match.nil?
         | 
| 62 | 
            +
                        match['email']
         | 
| 63 | 
            +
                    end # def find_person_from_name_and_company
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    # Retrieve the email of a person from his name and company.
         | 
| 66 | 
            +
                    #
         | 
| 67 | 
            +
                    # Reference: https://apolloio.github.io/apollo-api-docs/?shell#enrichment-api
         | 
| 68 | 
            +
                    #
         | 
| 69 | 
            +
                    # 
         | 
| 70 | 
            +
                    def find_person_from_name_and_domain(name:, domain:)
         | 
| 71 | 
            +
                        raise 'Error: apollo_apikey or findymail_apikey are required for find_person_from_name_and_domain operation.' if @apollo_apikey.nil? && @findymail_apikey.nil?
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                        if @findymail_apikey
         | 
| 74 | 
            +
                            ret = `curl --request POST \
         | 
| 75 | 
            +
                                "https://app.findymail.com/api/search/name" \
         | 
| 76 | 
            +
                                --header "Authorization: Bearer #{@findymail_apikey}" \
         | 
| 77 | 
            +
                                --header "Content-Type: application/json" \
         | 
| 78 | 
            +
                                --header "Accept: application/json" \
         | 
| 79 | 
            +
                                --data "{
         | 
| 80 | 
            +
                                    \\"name\\": \\"#{name}\\",
         | 
| 81 | 
            +
                                    \\"domain\\": \\"#{domain}\\"
         | 
| 82 | 
            +
                                }"`
         | 
| 83 | 
            +
                            j = JSON.parse(ret)
         | 
| 84 | 
            +
                            raise "Error: #{j['error']}" if j['error']
         | 
| 85 | 
            +
                            return nil if j['contact'].nil?
         | 
| 86 | 
            +
                            return j['contact']['email']
         | 
| 87 | 
            +
                        elsif @apollo_apikey
         | 
| 88 | 
            +
                            ret = `curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
         | 
| 89 | 
            +
                                "api_key": "#{@apollo_apikey}",
         | 
| 90 | 
            +
                                "reveal_personal_emails": true,
         | 
| 91 | 
            +
                                "details": [
         | 
| 92 | 
            +
                                    {
         | 
| 93 | 
            +
                                        "name": "#{name}",
         | 
| 94 | 
            +
                                        "domain": "#{domain}"
         | 
| 95 | 
            +
                                    }
         | 
| 96 | 
            +
                                ]
         | 
| 97 | 
            +
                            }' "https://api.apollo.io/api/v1/people/bulk_match"`
         | 
| 98 | 
            +
                            j = JSON.parse(ret)
         | 
| 99 | 
            +
                            raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 100 | 
            +
                            raise "Error: #{j['error_code']}" if j['error_code']
         | 
| 101 | 
            +
                            raise "Error: #{j['error']}" if j['error']
         | 
| 102 | 
            +
                            match = j['matches'].first
         | 
| 103 | 
            +
                            return nil if match.nil?
         | 
| 104 | 
            +
                            return match['email']
         | 
| 105 | 
            +
                        end
         | 
| 106 | 
            +
                    end # def find_person_from_name_and_domain
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                    # Retrieve the name, job position and email of a person from a list of allowed titles and company domain.
         | 
| 109 | 
            +
                    #
         | 
| 110 | 
            +
                    # Reference: https://apolloio.github.io/apollo-api-docs/?shell#people-api
         | 
| 111 | 
            +
                    #
         | 
| 112 | 
            +
                    # 
         | 
| 113 | 
            +
                    def find_persons_from_title_and_domain(titles:, domain:, limit: 1, calls_delay: 1)
         | 
| 114 | 
            +
                        raise 'Error: apollo_apikey is required for find_persons_from_title_and_domain operation.' if @apollo_apikey.nil?
         | 
| 115 | 
            +
                        b = []
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                        # search leads
         | 
| 118 | 
            +
                        s = "curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -d '{
         | 
| 119 | 
            +
                            \"api_key\": \"#{@apollo_apikey}\",
         | 
| 120 | 
            +
                            \"page\" : 1,
         | 
| 121 | 
            +
                            \"per_page\": #{limit.to_s},
         | 
| 122 | 
            +
                            \"person_titles\": [\"#{titles.join('", "')}\"],
         | 
| 123 | 
            +
                            \"q_organization_domains\": \"#{domain}\",
         | 
| 124 | 
            +
                            \"contact_email_status\": [\"verified\"]
         | 
| 125 | 
            +
                        }' \"https://api.apollo.io/v1/mixed_people/search\""
         | 
| 126 | 
            +
                        ret = `#{s}`
         | 
| 127 | 
            +
                        j = JSON.parse(ret)
         | 
| 128 | 
            +
                        
         | 
| 129 | 
            +
                        raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 130 | 
            +
                        raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 131 | 
            +
                        raise "Error: #{j['error']}" if j['error']
         | 
| 132 | 
            +
                        
         | 
| 133 | 
            +
                        a = j['people']
         | 
| 134 | 
            +
                        return ret if a.nil?
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                        a.each { |h|
         | 
| 137 | 
            +
                            # add delay to don't oberload the API
         | 
| 138 | 
            +
                            sleep calls_delay
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                            i = {}
         | 
| 141 | 
            +
                            i['id'] = h['id']
         | 
| 142 | 
            +
                            i['first_name'] = h['first_name']
         | 
| 143 | 
            +
                            i['last_name'] = h['last_name']
         | 
| 144 | 
            +
                            i['title'] = h['title']
         | 
| 145 | 
            +
                            i['linkedin_url'] = h['linkedin_url']
         | 
| 146 | 
            +
                            i['facebook_url'] = h['facebook_url']
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                            # find the email of the lead
         | 
| 149 | 
            +
                            s = "curl -X POST -H \"Content-Type: application/json\" -H \"Cache-Control: no-cache\" -d '{
         | 
| 150 | 
            +
                                \"api_key\": \"#{@apollo_apikey}\",
         | 
| 151 | 
            +
                                \"reveal_personal_emails\": true,
         | 
| 152 | 
            +
                                \"id\": \"#{i['id']}\"
         | 
| 153 | 
            +
                            }' \"https://api.apollo.io/v1/people/match\""
         | 
| 154 | 
            +
                            ret = `#{s}`
         | 
| 155 | 
            +
                            j = JSON.parse(ret)
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                            raise "Error: #{j['error_message']}" if j['error_message']
         | 
| 158 | 
            +
                            raise "Error: #{j['error_code']}" if j['error_code']
         | 
| 159 | 
            +
                            raise "Error: #{j['error']}" if j['error']
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                            next if j['person'].nil?
         | 
| 162 | 
            +
                            k = j['person'] if j['person']
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                            # append emails and phone numbers to the hash
         | 
| 165 | 
            +
                            i['emails'] = []
         | 
| 166 | 
            +
                            i['emails'] << k['email'] if k['email']
         | 
| 167 | 
            +
                            i['emails'] += k['personal_emails'] if k['personal_emails']
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                            i['phone_numbers'] = []
         | 
| 170 | 
            +
                            i['phone_numbers'] = k['phone_numbers'].map { |o| {
         | 
| 171 | 
            +
                                'value' => o['raw_number'],
         | 
| 172 | 
            +
                                'type' => o['type']
         | 
| 173 | 
            +
                            } } if k['phone_numbers']
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                            i['raw'] = k
         | 
| 176 | 
            +
             | 
| 177 | 
            +
                            b << i
         | 
| 178 | 
            +
                        }
         | 
| 179 | 
            +
             | 
| 180 | 
            +
                        # return
         | 
| 181 | 
            +
                        b
         | 
| 182 | 
            +
                    end # def find_persons_from_title_and_domain
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                end # class ApolloClient
         | 
| 185 | 
            +
            #end # module BlackStack
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,64 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: apollo-client
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.4
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Leandro Daniel Sardi
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2025-01-08 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: json
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: 2.6.3
         | 
| 20 | 
            +
                - - ">="
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: 2.6.3
         | 
| 23 | 
            +
              type: :runtime
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - "~>"
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: 2.6.3
         | 
| 30 | 
            +
                - - ">="
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: 2.6.3
         | 
| 33 | 
            +
            description: Ruby library for connecting some enrichment services like Apillo.
         | 
| 34 | 
            +
            email: leandro@connectionsphere.com
         | 
| 35 | 
            +
            executables: []
         | 
| 36 | 
            +
            extensions: []
         | 
| 37 | 
            +
            extra_rdoc_files: []
         | 
| 38 | 
            +
            files:
         | 
| 39 | 
            +
            - apollo-client.gemspec
         | 
| 40 | 
            +
            - lib/apollo-client.rb
         | 
| 41 | 
            +
            homepage: https://github.com/leandrosardi/blackstack-enrichment
         | 
| 42 | 
            +
            licenses:
         | 
| 43 | 
            +
            - MIT
         | 
| 44 | 
            +
            metadata: {}
         | 
| 45 | 
            +
            post_install_message: 
         | 
| 46 | 
            +
            rdoc_options: []
         | 
| 47 | 
            +
            require_paths:
         | 
| 48 | 
            +
            - lib
         | 
| 49 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
              requirements:
         | 
| 51 | 
            +
              - - ">="
         | 
| 52 | 
            +
                - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                  version: '0'
         | 
| 54 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 55 | 
            +
              requirements:
         | 
| 56 | 
            +
              - - ">="
         | 
| 57 | 
            +
                - !ruby/object:Gem::Version
         | 
| 58 | 
            +
                  version: '0'
         | 
| 59 | 
            +
            requirements: []
         | 
| 60 | 
            +
            rubygems_version: 3.3.7
         | 
| 61 | 
            +
            signing_key: 
         | 
| 62 | 
            +
            specification_version: 4
         | 
| 63 | 
            +
            summary: Ruby library for connecting some enrichment services like Apillo.
         | 
| 64 | 
            +
            test_files: []
         |