jigsaw 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +20 -0
- data/README.md +113 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/jigsaw.gemspec +78 -0
- data/lib/jigsaw.rb +5 -0
- data/lib/jigsaw/client.rb +15 -0
- data/lib/jigsaw/company_basic.rb +65 -0
- data/lib/jigsaw/request.rb +29 -0
- data/spec/jigsaw/client_spec.rb +39 -0
- data/spec/jigsaw/company_basic_spec.rb +54 -0
- data/spec/jigsaw/request_spec.rb +24 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/webmock/company_search_webmock_helpers.rb +140 -0
- metadata +162 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.1.0)
|
5
|
+
multi_json (~> 1.0)
|
6
|
+
addressable (2.2.6)
|
7
|
+
crack (0.1.8)
|
8
|
+
diff-lcs (1.1.3)
|
9
|
+
git (1.2.5)
|
10
|
+
httparty (0.7.8)
|
11
|
+
crack (= 0.1.8)
|
12
|
+
i18n (0.6.0)
|
13
|
+
jeweler (1.6.4)
|
14
|
+
bundler (~> 1.0)
|
15
|
+
git (>= 1.2.5)
|
16
|
+
rake
|
17
|
+
multi_json (1.0.3)
|
18
|
+
rake (0.9.2)
|
19
|
+
rcov (0.9.10)
|
20
|
+
rspec (2.3.0)
|
21
|
+
rspec-core (~> 2.3.0)
|
22
|
+
rspec-expectations (~> 2.3.0)
|
23
|
+
rspec-mocks (~> 2.3.0)
|
24
|
+
rspec-core (2.3.1)
|
25
|
+
rspec-expectations (2.3.0)
|
26
|
+
diff-lcs (~> 1.1.2)
|
27
|
+
rspec-mocks (2.3.0)
|
28
|
+
webmock (1.7.6)
|
29
|
+
addressable (> 2.2.5, ~> 2.2)
|
30
|
+
crack (>= 0.1.7)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
activesupport
|
37
|
+
bundler (~> 1.0.0)
|
38
|
+
httparty
|
39
|
+
i18n
|
40
|
+
jeweler (~> 1.6.4)
|
41
|
+
rcov
|
42
|
+
rspec (~> 2.3.0)
|
43
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Matthew Bellantoni
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Jigsaw
|
2
|
+
|
3
|
+
This gem provides a Ruby wrapper around the Jigsaw API, using HTTParty. Currently, only Company Search is supported.
|
4
|
+
|
5
|
+
|
6
|
+
## Obtaining an API key
|
7
|
+
|
8
|
+
To be able to use this gem, you'll need a Jigsaw Developer API key. To request an API key, point your browser to
|
9
|
+
http://developer.jigsaw.com/member/register and follow the instructions there.
|
10
|
+
|
11
|
+
|
12
|
+
## Installing the gem
|
13
|
+
|
14
|
+
To use this gem, install it with <tt>gem install jigsaw</tt> or add it to your Gemfile:
|
15
|
+
|
16
|
+
gem 'jigsaw'
|
17
|
+
|
18
|
+
And install it with <tt>bundle install</tt>
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Retrieving a list of companies
|
24
|
+
|
25
|
+
You can search for companies and you'll receive three pieces of information:
|
26
|
+
|
27
|
+
1. The number of hits found by this search.
|
28
|
+
2. The number of records being returned.
|
29
|
+
3. The actual records as an array of JigSaw::CompanyBasic objects.
|
30
|
+
|
31
|
+
Searches are refined using these arguments.
|
32
|
+
|
33
|
+
* *updated_since*: The format is yyyy-MM-dd, for example 2008-10-31
|
34
|
+
* *name*:Oracle, IBM, www.jigsaw.com , AAPL
|
35
|
+
* *country*: Country name. See developer documentation for details.
|
36
|
+
* *state*: Two letter state name abbreviations. See developer documentation for details.
|
37
|
+
* *metro_area*: Major metropolitan areas by name. See developer documentation for details.
|
38
|
+
* *area_code*: The digit area code.
|
39
|
+
* *zip_code*: Five or nine digit zip code.
|
40
|
+
* *industry*: Industry value. See developer documentation for details.
|
41
|
+
* *sub_industry*: Sub-industry value. See developer documentation for details.
|
42
|
+
* *employees*: Employee size range. See developer documentation for details.
|
43
|
+
* *revenue*: Company revenue range. See developer documentation for details.
|
44
|
+
* *ownership*: public, private, government, other
|
45
|
+
* *website_type*: .com, .gov, .org, .biz, .info, .net, .edu, .mil
|
46
|
+
* *fortune_rank*: 500, 1000
|
47
|
+
* *include_graveyard*: Is this company dead? false (default), true
|
48
|
+
* *order*: ASC, DESC, the default is no order
|
49
|
+
* *order_by*: Company, City, State, updatedSince
|
50
|
+
* *offset*: The start point for records that are returned.
|
51
|
+
* *page_size*: The number of records that are returned per page. Default 50. Maximum 100.
|
52
|
+
|
53
|
+
Details for argument values can be found in the [Data Keys and Values section](http://developer.jigsaw.com/documentation/search_and_get_api_guide/6_Data_Keys_and_Values) of
|
54
|
+
the developer documentation.
|
55
|
+
|
56
|
+
First register a new Client:
|
57
|
+
|
58
|
+
@client = Jigsaw::Client.new(API_KEY)
|
59
|
+
|
60
|
+
Then retrieve a list of companies in zip code "02478":
|
61
|
+
|
62
|
+
@total_hits, @fetched_hits, @companies = @client.company_search({:zip_code => "02478"})
|
63
|
+
|
64
|
+
Search by zip code and return a single page of 10 results:
|
65
|
+
|
66
|
+
@total_hits, @fetched_hits, @companies = @client.company_search({:zip_code => "02478", :page_size => 10, :offset => 0})
|
67
|
+
|
68
|
+
Search by zip code and return all results:
|
69
|
+
|
70
|
+
@total_hits, @fetched_hits, @companies = @client.company_search({:zip_code => "02478"}, true)
|
71
|
+
|
72
|
+
Search by zip code *and* return all results:
|
73
|
+
|
74
|
+
@total_hits, @fetched_hits, @companies = @client.company_search({:zip_code => "02478", :ownership => "private"}, true)
|
75
|
+
|
76
|
+
### Retrieving company details
|
77
|
+
|
78
|
+
Not yet implemented.
|
79
|
+
|
80
|
+
### Retrieving a list of contacts
|
81
|
+
|
82
|
+
Not yet implemented.
|
83
|
+
|
84
|
+
### Retrieving contact details
|
85
|
+
|
86
|
+
Not yet implemented.
|
87
|
+
|
88
|
+
## To Do
|
89
|
+
* Add lookup of detailed company info. (Planned for 0.2.0)
|
90
|
+
* Handle errors at the Request level. (Planned for ???)
|
91
|
+
* The rest of the API! (Planned for ???)
|
92
|
+
|
93
|
+
## Acknowledgement
|
94
|
+
|
95
|
+
This gem is patterned after Marcel de Graaf's [google_pages gem](https://github.com/marceldegraaf/google_places).
|
96
|
+
|
97
|
+
## Contributing to jigsaw
|
98
|
+
|
99
|
+
You're very welcome to add functionality to this gem. To do so, follow these steps:
|
100
|
+
|
101
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
102
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
103
|
+
* Fork the project
|
104
|
+
* Start a feature/bugfix branch
|
105
|
+
* Commit and push until you are happy with your contribution
|
106
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
107
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
108
|
+
|
109
|
+
## Copyright
|
110
|
+
|
111
|
+
Copyright (c) 2011 Matthew Bellantoni. See LICENSE.txt for
|
112
|
+
further details.
|
113
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "jigsaw"
|
18
|
+
gem.homepage = "http://github.com/mjbellantoni/jigsaw"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{ Jigsaw.com API. Incomplete coverage. }
|
21
|
+
gem.description = gem.summary
|
22
|
+
gem.email = "mjbellantoni@yahoo.com"
|
23
|
+
gem.authors = ["Matthew Bellantoni"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "jigsaw #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/jigsaw.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "jigsaw"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthew Bellantoni"]
|
12
|
+
s.date = "2011-09-11"
|
13
|
+
s.description = "Jigsaw.com API. Incomplete coverage."
|
14
|
+
s.email = "mjbellantoni@yahoo.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"jigsaw.gemspec",
|
29
|
+
"lib/jigsaw.rb",
|
30
|
+
"lib/jigsaw/client.rb",
|
31
|
+
"lib/jigsaw/company_basic.rb",
|
32
|
+
"lib/jigsaw/request.rb",
|
33
|
+
"spec/jigsaw/client_spec.rb",
|
34
|
+
"spec/jigsaw/company_basic_spec.rb",
|
35
|
+
"spec/jigsaw/request_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/support/webmock/company_search_webmock_helpers.rb"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/mjbellantoni/jigsaw"
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "1.8.10"
|
43
|
+
s.summary = "Jigsaw.com API. Incomplete coverage."
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
51
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
60
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
66
|
+
end
|
67
|
+
else
|
68
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
69
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
70
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
71
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
data/lib/jigsaw.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module Jigsaw
|
4
|
+
|
5
|
+
class CompanyBasic
|
6
|
+
|
7
|
+
attr_accessor :company_id, :name, :address, :city, :state, :zip, :country, :active_contacts, :graveyarded
|
8
|
+
|
9
|
+
def initialize(json_object)
|
10
|
+
@company_id = json_object['companyId']
|
11
|
+
@name = json_object['name']
|
12
|
+
@address = json_object['address']
|
13
|
+
@city = json_object['city']
|
14
|
+
@state = json_object['state']
|
15
|
+
@zip = json_object['zip']
|
16
|
+
@country = json_object['country']
|
17
|
+
@active_contacts = json_object['activeContacts']
|
18
|
+
@graveyarded = json_object['graveyarded']
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def self.list(api_key, options, fetch_all=false)
|
23
|
+
|
24
|
+
options[:token] = api_key
|
25
|
+
options[:page_size] = options[:page_size] || 50 # 50 is the default.
|
26
|
+
options[:offset] = options[:offset] || 0 # 0 is the default.
|
27
|
+
|
28
|
+
# Camelize options
|
29
|
+
camelized_options = {}
|
30
|
+
options.each do |key, value|
|
31
|
+
camelized_options[key.to_s.camelize(:lower)] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# Send one or more requests depending on the number of results, the
|
35
|
+
# page size and the value of fetch_all
|
36
|
+
companies = []
|
37
|
+
total_hits = nil
|
38
|
+
fetched_hits = 0
|
39
|
+
offset = options[:offset]
|
40
|
+
|
41
|
+
begin
|
42
|
+
|
43
|
+
response = Request.search_company(camelized_options)
|
44
|
+
|
45
|
+
total_hits = response['totalHits']
|
46
|
+
fetched_hits += response['companies'].size
|
47
|
+
|
48
|
+
companies << response['companies'].map do |result|
|
49
|
+
self.new(result)
|
50
|
+
end
|
51
|
+
|
52
|
+
#Calculate the next offset.
|
53
|
+
offset += options[:page_size]
|
54
|
+
camelized_options[:offset] = offset
|
55
|
+
|
56
|
+
end while fetch_all && (total_hits > offset)
|
57
|
+
|
58
|
+
# Return the hits info and the list of companies
|
59
|
+
[total_hits, fetched_hits, companies.flatten]
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Jigsaw
|
4
|
+
|
5
|
+
class Request
|
6
|
+
|
7
|
+
attr_accessor :response
|
8
|
+
|
9
|
+
include ::HTTParty
|
10
|
+
format :json
|
11
|
+
|
12
|
+
SEARCH_COMPANY_URL = 'http://www.jigsaw.com/rest/searchCompany.json'
|
13
|
+
|
14
|
+
def self.search_company(options = {})
|
15
|
+
request = new(SEARCH_COMPANY_URL, options)
|
16
|
+
request.parsed_response
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(url, options)
|
20
|
+
@response = self.class.get(url, :query => options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parsed_response
|
24
|
+
@response.parsed_response
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Jigsaw::Client do
|
4
|
+
|
5
|
+
include CompanySearchWebmockHelpers
|
6
|
+
|
7
|
+
it "should not initialize without an api_key" do
|
8
|
+
lambda { Jigsaw::Client.new }.should raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should initialize with an api_key" do
|
12
|
+
@client = Jigsaw::Client.new(api_key)
|
13
|
+
@client.api_key.should == api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
context "a company search" do
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
stub_jigsaw_for_client_company_search
|
21
|
+
@client = Jigsaw::Client.new(api_key)
|
22
|
+
@total_hits, @fetched_hits, @companies = @client.company_search({:zip_code => "02478"}, false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "tells how many hits it found " do
|
26
|
+
@total_hits.should == 3
|
27
|
+
end
|
28
|
+
|
29
|
+
it "tells how many hits it returns " do
|
30
|
+
@fetched_hits.should == 3
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns those hits " do
|
34
|
+
@companies.should have(3).items
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
describe Jigsaw::CompanyBasic do
|
6
|
+
|
7
|
+
include CompanySearchWebmockHelpers
|
8
|
+
|
9
|
+
context "with 9 hits and 5 hits per page" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
stub_jigsaw_for_page_test
|
13
|
+
@options = { :page_size => 5 }
|
14
|
+
end
|
15
|
+
|
16
|
+
context "when 'fetch_all' is true" do
|
17
|
+
before(:each) do
|
18
|
+
@total_hits, @fetched_hits, @companies = Jigsaw::CompanyBasic.list(api_key, @options, true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "finds 9 hits" do
|
22
|
+
@total_hits.should == 9
|
23
|
+
end
|
24
|
+
|
25
|
+
it "fetches 9 hits" do
|
26
|
+
@fetched_hits.should == 9
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns 9 companies" do
|
30
|
+
@companies.should have(9).items
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when 'fetch_all' is false" do
|
35
|
+
before(:each) do
|
36
|
+
@total_hits, @fetched_hits, @companies = Jigsaw::CompanyBasic.list(api_key, @options, false)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "finds 9 hits" do
|
40
|
+
@total_hits.should == 9
|
41
|
+
end
|
42
|
+
|
43
|
+
it "fetches 5 hits" do
|
44
|
+
@fetched_hits.should == 5
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns 5 companies" do
|
48
|
+
@companies.should have(5).items
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Jigsaw::Request do
|
4
|
+
|
5
|
+
include CompanySearchWebmockHelpers
|
6
|
+
|
7
|
+
context 'Listing companies' do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
stub_jigsaw_for_request
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should retrieve a list of companies' do
|
14
|
+
response = Jigsaw::Request.search_company(:token => api_key)
|
15
|
+
response['companies'].should_not be_empty
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should retrieve the number of matching companies' do
|
19
|
+
response = Jigsaw::Request.search_company(:token => api_key)
|
20
|
+
response['totalHits'].should_not be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'jigsaw'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
JIGSAW_API_KEY = "abc123"
|
8
|
+
def api_key
|
9
|
+
JIGSAW_API_KEY
|
10
|
+
end
|
11
|
+
|
12
|
+
# Requires supporting files with custom matchers and macros, etc,
|
13
|
+
# in ./support/ and its subdirectories.
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
15
|
+
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'active_support/json'
|
2
|
+
|
3
|
+
|
4
|
+
module CompanySearchWebmockHelpers
|
5
|
+
|
6
|
+
BASIC_COMPANIES = [
|
7
|
+
{
|
8
|
+
"zip" => "02142-1108",
|
9
|
+
"address" => "500 Kendall St",
|
10
|
+
"name" => "Genzyme Corporation",
|
11
|
+
"activeContacts" => 3514,
|
12
|
+
"state" => "MA",
|
13
|
+
"companyId" => 211909,
|
14
|
+
"graveyarded" => false,
|
15
|
+
"city" => "Cambridge",
|
16
|
+
"country" => "United States"},
|
17
|
+
{
|
18
|
+
"zip" => "02142-1453",
|
19
|
+
"address" => "14 Cambridge Ctr",
|
20
|
+
"name" => "Biogen Idec Inc.",
|
21
|
+
"activeContacts" => 1991,
|
22
|
+
"state" => "MA",
|
23
|
+
"companyId" => 213499,
|
24
|
+
"graveyarded" => false,
|
25
|
+
"city" => "Cambridge",
|
26
|
+
"country" => "United States"},
|
27
|
+
{
|
28
|
+
"zip" => "02142-1100",
|
29
|
+
"address" => "1 Broadway",
|
30
|
+
"name" => "Patni Americas, Inc.",
|
31
|
+
"activeContacts" => 867,
|
32
|
+
"state" => "MA",
|
33
|
+
"companyId" => 50666,
|
34
|
+
"graveyarded" => false,
|
35
|
+
"city" => "Cambridge",
|
36
|
+
"country" => "United States"},
|
37
|
+
{
|
38
|
+
"zip" => "02142-1413",
|
39
|
+
"address" => "8 Cambridge Ctr",
|
40
|
+
"name" => "Akamai Technologies, Inc.",
|
41
|
+
"activeContacts" => 535,
|
42
|
+
"state" => "MA",
|
43
|
+
"companyId" => 36097,
|
44
|
+
"graveyarded" => false,
|
45
|
+
"city" => "Cambridge",
|
46
|
+
"country" => "United States"},
|
47
|
+
{
|
48
|
+
"zip" => "02142-1519",
|
49
|
+
"address" => "101 Main St",
|
50
|
+
"name" => "Pegasystems Inc.",
|
51
|
+
"activeContacts" => 517,
|
52
|
+
"state" => "MA",
|
53
|
+
"companyId" => 42602,
|
54
|
+
"graveyarded" => false,
|
55
|
+
"city" => "Cambridge",
|
56
|
+
"country" => "United States"},
|
57
|
+
{
|
58
|
+
"zip" => "02142-1519",
|
59
|
+
"address" => "101 Main St",
|
60
|
+
"name" => "Endeca Technologies, Inc.",
|
61
|
+
"activeContacts" => 230,
|
62
|
+
"state" => "MA",
|
63
|
+
"companyId" => 143901,
|
64
|
+
"graveyarded" => false,
|
65
|
+
"city" => "Cambridge",
|
66
|
+
"country" => "United States"},
|
67
|
+
{
|
68
|
+
"zip" => "02142-1531",
|
69
|
+
"address" => "1 Main St",
|
70
|
+
"name" => "Art Technology Group, Inc. (ATG Group)",
|
71
|
+
"activeContacts" => 200,
|
72
|
+
"state" => "MA",
|
73
|
+
"companyId" => 90312,
|
74
|
+
"graveyarded" => false,
|
75
|
+
"city" => "Cambridge",
|
76
|
+
"country" => "United States"},
|
77
|
+
{
|
78
|
+
"zip" => "02142-1313",
|
79
|
+
"address" => "1 Memorial Dr",
|
80
|
+
"name" => "InterSystems Corp.",
|
81
|
+
"activeContacts" => 190,
|
82
|
+
"state" => "MA",
|
83
|
+
"companyId" => 24687,
|
84
|
+
"graveyarded" => false,
|
85
|
+
"city" => "Cambridge",
|
86
|
+
"country" => "United States"},
|
87
|
+
{
|
88
|
+
"zip" => "02142-1605",
|
89
|
+
"address" => "1 Cambridge Ctr",
|
90
|
+
"name" => "Brightcove, Inc.",
|
91
|
+
"activeContacts" => 144,
|
92
|
+
"state" => "MA",
|
93
|
+
"companyId" => 65820,
|
94
|
+
"graveyarded" => false,
|
95
|
+
"city" => "Cambridge",
|
96
|
+
"country" => "United States"},
|
97
|
+
{
|
98
|
+
"zip" => "02142-1401",
|
99
|
+
"address" => "9 Cambridge Ctr",
|
100
|
+
"name" => "Whitehead Institute for Biomedical Research",
|
101
|
+
"activeContacts" => 129,
|
102
|
+
"state" => "MA",
|
103
|
+
"companyId" => 68825,
|
104
|
+
"graveyarded" => false,
|
105
|
+
"city" => "Cambridge",
|
106
|
+
"country" => "United States"} ]
|
107
|
+
|
108
|
+
|
109
|
+
def stub_jigsaw_for_request
|
110
|
+
stub_request(:get, "http://www.jigsaw.com/rest/searchCompany.json?token=abc123").to_return(
|
111
|
+
:status => 200,
|
112
|
+
:body => ActiveSupport::JSON.encode({"totalHits" => BASIC_COMPANIES.size, "companies" => BASIC_COMPANIES }),
|
113
|
+
:headers => { :content_type => 'application/json' })
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def stub_jigsaw_for_client_company_search
|
118
|
+
stub_request(:get, "http://www.jigsaw.com/rest/searchCompany.json?offset=0&pageSize=50&token=abc123&zipCode=02478").
|
119
|
+
to_return(
|
120
|
+
:status => 200,
|
121
|
+
:body => ActiveSupport::JSON.encode({"totalHits" => 3, "companies" => BASIC_COMPANIES[0..2] }),
|
122
|
+
:headers => { :content_type => 'application/json' })
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
def stub_jigsaw_for_page_test
|
127
|
+
# 9 hits, return the first 5
|
128
|
+
stub_request(:get, "http://www.jigsaw.com/rest/searchCompany.json?offset=0&pageSize=5&token=abc123").to_return(
|
129
|
+
:status => 200,
|
130
|
+
:body => ActiveSupport::JSON.encode({"totalHits" => 9, "companies" => BASIC_COMPANIES[0..4] }),
|
131
|
+
:headers => { :content_type => 'application/json' })
|
132
|
+
|
133
|
+
# 9 hits, return the last 4
|
134
|
+
stub_request(:get, "http://www.jigsaw.com/rest/searchCompany.json?offset=5&pageSize=5&token=abc123").to_return(
|
135
|
+
:status => 200,
|
136
|
+
:body => ActiveSupport::JSON.encode({"totalHits" => 9, "companies" => BASIC_COMPANIES[5..8] }),
|
137
|
+
:headers => { :content_type => 'application/json' })
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jigsaw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew Bellantoni
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: activesupport
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: i18n
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.4
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rcov
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: webmock
|
94
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *id008
|
103
|
+
description: Jigsaw.com API. Incomplete coverage.
|
104
|
+
email: mjbellantoni@yahoo.com
|
105
|
+
executables: []
|
106
|
+
|
107
|
+
extensions: []
|
108
|
+
|
109
|
+
extra_rdoc_files:
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
files:
|
113
|
+
- .document
|
114
|
+
- .rspec
|
115
|
+
- Gemfile
|
116
|
+
- Gemfile.lock
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- VERSION
|
121
|
+
- jigsaw.gemspec
|
122
|
+
- lib/jigsaw.rb
|
123
|
+
- lib/jigsaw/client.rb
|
124
|
+
- lib/jigsaw/company_basic.rb
|
125
|
+
- lib/jigsaw/request.rb
|
126
|
+
- spec/jigsaw/client_spec.rb
|
127
|
+
- spec/jigsaw/company_basic_spec.rb
|
128
|
+
- spec/jigsaw/request_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/support/webmock/company_search_webmock_helpers.rb
|
131
|
+
homepage: http://github.com/mjbellantoni/jigsaw
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3400750207922112708
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.10
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Jigsaw.com API. Incomplete coverage.
|
161
|
+
test_files: []
|
162
|
+
|