igsearch 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24fb34f4f3914f863ac70aedad7c6a966e792e04
4
+ data.tar.gz: 1c91f81d712a43a999d0fb5065b7d02f2339afd6
5
+ SHA512:
6
+ metadata.gz: 864c9483df219229282e1a24fcc22124b29c6c081d6d3d6a6a90974be68b3c650afb7b53084073bd22296aec3498afcba3f2bc8a1251fe0a79f28bc8f9b0c10b
7
+ data.tar.gz: 1bb30b216a165f1a44c092b7a5bf8d69df28fff8b98e10d4af1121e424b2f323c98b2a6c8ce8ef2b1572553da747db309766a185638851d08f0278cc73390e6d
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ test.rb
24
+ *.env
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in igsearch.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ # gem 'webmock'
8
+ gem 'vcr'
9
+ gem 'turn'
10
+ gem 'rake'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Hayk Saakian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Igsearch
2
+
3
+ This is a Ruby gem that makes it easier to talk to the [Infogroup API](http://developer.infoconnect.com/).
4
+
5
+ The Infogroup API lets you search for people or businesess based on criteria that would be useful for conducting sales activity.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'igsearch'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install igsearch
21
+
22
+ ## Usage
23
+
24
+ 1. Configure an API Key
25
+
26
+ Igsearch.configure do |config|
27
+ config.apikey = ENV["INFOCONNECT_API_KEY"]
28
+ end
29
+
30
+ 2. Use the API
31
+
32
+ person = Igsearch::Person.search({
33
+ :FirstName => "William",
34
+ :LastName => "Gates",
35
+ :City => "Redmond",
36
+ :StateProvince => "WA"
37
+ }).first # .search returns an array
38
+ # => {"ETag"=>"bd62003e", "Id"=>"601223668643", "Links"=>[{"Href"=>"/v1/people/601223668643", "Rel"=>"self"}], "Address"=>"1 Microsoft Way Bldg 3", "AddressParsed"=>{"Name"=>"Microsoft", "Number"=>"1", "Suffix"=>"Way", "UnitNumber"=>"3", "UnitType"=>"Bldg"}, "City"=>"Redmond", "FirstName"=>"William", "LastName"=>"Gates", "Location"=>{"Latitude"=>47.639661, "Longitude"=>-122.130606}, "MiddleInitial"=>"H", "PostalCode"=>"98052", "StateProvince"=>"WA"}
39
+
40
+ 3. There is no step 3
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/hayksaakian/igsearch/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+
8
+ t.libs << 'lib/igsearch'
9
+ t.test_files = FileList['test/lib/igsearch/*_test.rb']
10
+ t.verbose = true
11
+ end
12
+
13
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'igsearch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "igsearch"
8
+ spec.version = Igsearch::VERSION
9
+ spec.authors = ["hayksaakian"]
10
+ spec.email = ["hayk@skyrealre.com"]
11
+ spec.summary = %q{Wrapper for Infoconnect API. (Unofficial)}
12
+ spec.description = %q{Search through groups of people and businesses with this API.}
13
+ spec.homepage = "https://www.github.com/hayksaakian/igsearch"
14
+ spec.license = "MIT"
15
+
16
+ # files must be commited before they're included in the build
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "httparty", "~> 0"
23
+ spec.add_dependency "StreetAddress", "~> 1.0.5"
24
+ spec.add_development_dependency "dotenv", "~> 0"
25
+ spec.add_development_dependency "bundler", "~> 1.6"
26
+ spec.add_development_dependency "rake", "~> 0"
27
+ end
28
+
@@ -0,0 +1,38 @@
1
+ require 'igsearch/version'
2
+ require 'igsearch/person'
3
+
4
+ module Igsearch
5
+ # Public: Set global options.
6
+ #
7
+ # Yields the Igsearch module so you can set options on it.
8
+ #
9
+ # Returns self.
10
+ def self.configure
11
+ yield self
12
+ # TODO: find a better way to do this
13
+ self::Person.default_params :apikey => self.apikey
14
+ self
15
+ end
16
+ # Public: Reset the configuration to the defaults. Useful for testing.
17
+ #
18
+ # Returns nil.
19
+ def self.reset!
20
+ @apikey = nil
21
+ end
22
+ class << self
23
+ # Public: Your Infogroup API key.
24
+ attr_accessor :apikey
25
+ end
26
+ end
27
+
28
+ ####################################
29
+ ##
30
+ ## Punting to next major version:
31
+ ##
32
+ ########
33
+ # class Company
34
+ # end
35
+ # class SIC
36
+ # end
37
+ # class Match
38
+ # end
@@ -0,0 +1,93 @@
1
+ require 'httparty'
2
+ require 'street_address'
3
+ require 'json'
4
+
5
+ module Igsearch
6
+
7
+ def self.live_api?
8
+ HTTParty.get('http://api.infoconnect.com/v1/').code == 200
9
+ end
10
+
11
+ # docs: http://developer.infoconnect.com/post-search-0
12
+ class Person
13
+ include HTTParty
14
+
15
+ base_uri "api.infoconnect.com/v1/people"
16
+ headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
17
+ format :json
18
+ # debug_output $stdout
19
+
20
+ # BUG/PROBLEM:
21
+ # still need to .to_json to send json...
22
+
23
+ def initialize(apikey=Igsearch.apikey)
24
+ # this changes it for all instances
25
+ self.class.default_params :apikey => apikey
26
+ end
27
+
28
+ def self.hi
29
+ return "success #{Igsearch.apikey}"
30
+ end
31
+
32
+ def self.find(id, options={})
33
+
34
+ response = get("/#{id}", options)
35
+
36
+ return response.parsed_response if response.success?
37
+ handle_error response
38
+ end
39
+
40
+ def self.search(criteria, options={})
41
+ response = post('/search', :body => criteria.to_json)
42
+
43
+ return response.parsed_response if response.success?
44
+ handle_error response
45
+ end
46
+
47
+ def self.search_raw_address(raw_address, options={})
48
+ p_address = StreetAddress::US.parse(raw_address)
49
+
50
+ return [] if p_address.nil?
51
+
52
+ address = self.render_parsed_address_to_api_format(p_address)
53
+ self.search(address, options)
54
+ end
55
+
56
+ def self.count(criteria, options={})
57
+ response = post('/count', body: criteria.to_json)
58
+
59
+ return response.parsed_response["MatchCount"] if response.success?
60
+ handle_error response
61
+ end
62
+
63
+ private
64
+ def self.handle_error(response)
65
+ raise response.response.code + ' ' + response.response.message # fix this to show resp. code and message
66
+ end
67
+
68
+ def self.render_parsed_address_to_api_format(address)
69
+ ap = {} # address, parsed and rendered for infogroup API
70
+ ap["Number"] = address.number
71
+ ap["PreDirectional"] = address.prefix
72
+ ap["Name"] = address.street
73
+ # the infoconnect api has different names than
74
+ # those used by the street_address gem
75
+ ap["Suffix"] = address.street_type # this is not a mistake
76
+ ap["PostDirectional"] = address.suffix # this is not a mistake
77
+ # for buildings
78
+ ap["UnitNumber"] = address.unit
79
+ ap["UnitType"] = address.unit_prefix
80
+ # clean up null keys/values
81
+ ap.delete_if { |k, v| v.nil? }
82
+ qap = {}
83
+ qap["AddressParsed"] = ap
84
+ qap["City"] = address.city
85
+ qap["StateProvince"] = address.state
86
+ qap["PostalCode"] = address.postal_code
87
+
88
+ qap.delete_if { |k, v| v.nil? }
89
+
90
+ return qap
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,3 @@
1
+ module Igsearch
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,56 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Igsearch do
4
+
5
+ before do
6
+ Igsearch.configure do |config|
7
+ config.apikey = ENV["INFOCONNECT_API_KEY"]
8
+ end
9
+ end
10
+
11
+ it "must say hi" do
12
+ assert Igsearch::Person.hi.is_a?(String), "something weird is messed up"
13
+ end
14
+
15
+ it "must access a live API" do
16
+ assert Igsearch.live_api?, "API is not live!"
17
+ end
18
+
19
+ it "must find person by id" do
20
+ person = Igsearch::Person.find('601223668643')
21
+ assert !person.nil?, "No person found by id"
22
+ assert person['FirstName'] == "William", "Did not find Bill Gates!"
23
+ end
24
+
25
+ it "must find bill gates by search" do
26
+ person = Igsearch::Person.search({
27
+ :FirstName => "William",
28
+ :LastName => "Gates",
29
+ :City => "Redmond",
30
+ :StateProvince => "WA"
31
+ }).first
32
+ assert !person.nil?, "No person found by search"
33
+ assert person['Id'] == '601223668643', "This is not the right Bill Gates!"
34
+ end
35
+
36
+ it "must find bill gates by raw address" do
37
+ person = Igsearch::Person.search_raw_address("1 Microsoft Way, Redmond, WA").first
38
+ assert !person.nil?, "No person found by raw address"
39
+ assert person['Id'] == '601223668643', "This is not Bill Gates' Address!"
40
+ end
41
+
42
+ it "must handle bad raw address" do
43
+ person = Igsearch::Person.search_raw_address("123 Any Street").first
44
+
45
+ assert person.nil?, "Did not handle errors properly"
46
+ end
47
+
48
+ it "must count rich people named paul allen" do
49
+ num_people = Igsearch::Person.count({
50
+ :FirstName => "Paul",
51
+ :LastName => "Allen",
52
+ :ActualIncome => ["400000", "500000"]
53
+ })
54
+ assert num_people > 0, "Bill Gates either isnt very rich or couldnt be found"
55
+ end
56
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Igsearch do
4
+
5
+ it "must be defined" do
6
+ Igsearch::VERSION.wont_be_nil
7
+ end
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'dotenv'
4
+ require File.expand_path('../../lib/igsearch.rb', __FILE__)
5
+
6
+ Dotenv.load
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: igsearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - hayksaakian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: StreetAddress
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Search through groups of people and businesses with this API.
84
+ email:
85
+ - hayk@skyrealre.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - igsearch.gemspec
96
+ - lib/igsearch.rb
97
+ - lib/igsearch/person.rb
98
+ - lib/igsearch/version.rb
99
+ - test/lib/igsearch/person_test.rb
100
+ - test/lib/igsearch/version_test.rb
101
+ - test/test_helper.rb
102
+ homepage: https://www.github.com/hayksaakian/igsearch
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.2.2
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Wrapper for Infoconnect API. (Unofficial)
126
+ test_files:
127
+ - test/lib/igsearch/person_test.rb
128
+ - test/lib/igsearch/version_test.rb
129
+ - test/test_helper.rb