rcarvalho-jigsaw 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem "rspec", "~> 2.3.0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.4"
7
+ gem "rcov", ">= 0"
8
+ gem "webmock"
9
+ end
10
+
11
+ gem "httparty"
12
+ gem "activesupport"
13
+ gem "i18n"
@@ -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
@@ -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.
@@ -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
+
@@ -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
@@ -0,0 +1,80 @@
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 = "rcarvalho-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_search.rb",
32
+ "lib/jigsaw/contact_search.rb",
33
+ "lib/jigsaw/company.rb",
34
+ "lib/jigsaw/request.rb",
35
+ "spec/jigsaw/client_spec.rb",
36
+ "spec/jigsaw/company_basic_spec.rb",
37
+ "spec/jigsaw/request_spec.rb",
38
+ "spec/spec_helper.rb",
39
+ "spec/support/webmock/company_search_webmock_helpers.rb"
40
+ ]
41
+ s.homepage = "http://github.com/mjbellantoni/jigsaw"
42
+ s.licenses = ["MIT"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = "1.8.10"
45
+ s.summary = "Jigsaw.com API. Incomplete coverage."
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
52
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
53
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
54
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_development_dependency(%q<rcov>, [">= 0"])
58
+ s.add_development_dependency(%q<webmock>, [">= 0"])
59
+ else
60
+ s.add_dependency(%q<httparty>, [">= 0"])
61
+ s.add_dependency(%q<activesupport>, [">= 0"])
62
+ s.add_dependency(%q<i18n>, [">= 0"])
63
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<webmock>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<httparty>, [">= 0"])
71
+ s.add_dependency(%q<activesupport>, [">= 0"])
72
+ s.add_dependency(%q<i18n>, [">= 0"])
73
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
74
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
76
+ s.add_dependency(%q<rcov>, [">= 0"])
77
+ s.add_dependency(%q<webmock>, [">= 0"])
78
+ end
79
+ end
80
+
@@ -0,0 +1,5 @@
1
+ require 'httparty'
2
+
3
+ %w(client request company_search contact_search company).each do |file|
4
+ require File.join(File.dirname(__FILE__), 'jigsaw', file)
5
+ end
@@ -0,0 +1,23 @@
1
+ module Jigsaw
2
+ class Client
3
+
4
+ attr_reader :api_key
5
+
6
+ def initialize(api_key)
7
+ @api_key = api_key
8
+ end
9
+
10
+ def company_search(options = {}, fetch_all = false)
11
+ CompanySearch.list(@api_key, options, fetch_all)
12
+ end
13
+
14
+ def contact_search(options = {}, fetch_all = false)
15
+ ContactSearch.list(@api_key, options, fetch_all)
16
+ end
17
+
18
+ def company(id, options = {})
19
+ Company.find(@api_key, id, options)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,57 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Jigsaw
4
+
5
+ class Company
6
+
7
+ attr_accessor :companyId, :name, :phone, :website, :stockSymbol, :stockExchange, :ownership, :employeeCount, :employeeRange, :revenue, :revenueRange, :industry1, :industry2, :industry3, :subIndustry1, :subIndustry2, :subIndustry3, :sicCode, :address, :city, :state, :zip, :country, :activeContact, :createdOn, :linkInJigsaw, :graveyarded, :updatedDate, :currentWiki, :currentLogo
8
+
9
+ def initialize(json_object)
10
+ @companyId = json_object['companyId']
11
+ @name = json_object['name']
12
+ @phone = json_object['phone']
13
+ @website = json_object['website']
14
+ @stockSymbol = json_object['stockSymbol']
15
+ @stockExchange = json_object['stockExchange']
16
+ @ownership = json_object['ownership']
17
+ @employeeCount = json_object['employeeCount']
18
+ @employeeRange = json_object['employeeRange']
19
+ @revenue = json_object['revenue']
20
+ @revenueRange = json_object['revenueRange']
21
+ @industry1 = json_object['industry1']
22
+ @industry2 = json_object['industry2']
23
+ @industry3 = json_object['industry3']
24
+ @subIndustry1 = json_object['subIndustry1']
25
+ @subIndustry2 = json_object['subIndustry2']
26
+ @subIndustry3 = json_object['subIndustry3']
27
+ @sicCode = json_object['sicCode']
28
+ @address = json_object['address']
29
+ @city = json_object['city']
30
+ @state = json_object['state']
31
+ @zip = json_object['zip']
32
+ @country = json_object['country']
33
+ @activeContact = json_object['activeContact']
34
+ @createdOn = json_object['createdOn']
35
+ @linkInJigsaw = json_object['linkInJigsaw']
36
+ @graveyarded = json_object['graveyarded']
37
+ @updatedDate = json_object['updatedDate']
38
+ @currentWiki = json_object['currentWiki']
39
+ @currentLogo = json_object['currentLogo']
40
+ end
41
+
42
+ def self.find(api_key, id, options)
43
+
44
+ options[:token] = api_key
45
+
46
+ response = Request.company(id, options)
47
+
48
+ company = self.new(response['companies'].first)
49
+
50
+ # Return the hits info and the list of the company
51
+ company
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,65 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Jigsaw
4
+
5
+ class CompanySearch
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,77 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Jigsaw
4
+
5
+ class ContactSearch
6
+
7
+ attr_accessor :zip, :phone, :areaCode, :updatedDate, :seoContactURL, :state, :lastname, :firstname, :companyName, :contactURL, :contactSales, :country, :owned, :city, :title, :contactId, :email, :address, :graveyardStatus, :ownedType, :companyId
8
+
9
+ def initialize(json_object)
10
+ @zip = json_object['zip']
11
+ @phone = json_object['phone']
12
+ @areaCode = json_object['areaCode']
13
+ @updatedDate = json_object['updatedDate']
14
+ @seoContactURL = json_object['seoContactUR']
15
+ @state = json_object['state']
16
+ @lastname = json_object['lastname']
17
+ @firstname = json_object['firstname']
18
+ @companyName = json_object['companyName']
19
+ @contactURL = json_object['contactURL']
20
+ @contactSales = json_object['contactSales']
21
+ @country = json_object['country']
22
+ @owned = json_object['owned']
23
+ @city = json_object['city']
24
+ @title = json_object['title']
25
+ @contactId = json_object['contactId']
26
+ @email = json_object['email']
27
+ @address = json_object['address']
28
+ @graveyardStatus = json_object['graveyardStatus']
29
+ @ownedType = json_object['ownedType']
30
+ @companyId = json_object['companyId']
31
+ end
32
+
33
+
34
+ def self.list(api_key, options, fetch_all=false)
35
+
36
+ options[:token] = api_key
37
+ options[:page_size] = options[:page_size] || 50 # 50 is the default.
38
+ options[:offset] = options[:offset] || 0 # 0 is the default.
39
+
40
+ # Camelize options
41
+ camelized_options = {}
42
+ options.each do |key, value|
43
+ camelized_options[key.to_s.camelize(:lower)] = value
44
+ end
45
+
46
+ # Send one or more requests depending on the number of results, the
47
+ # page size and the value of fetch_all
48
+ contacts = []
49
+ total_hits = nil
50
+ fetched_hits = 0
51
+ offset = options[:offset]
52
+
53
+ begin
54
+
55
+ response = Request.search_contact(camelized_options)
56
+
57
+ total_hits = response['totalHits']
58
+ fetched_hits += response['contacts'].size
59
+
60
+ contacts << response['contacts'].map do |result|
61
+ self.new(result)
62
+ end
63
+
64
+ #Calculate the next offset.
65
+ offset += options[:page_size]
66
+ camelized_options[:offset] = offset
67
+
68
+ end while fetch_all && (total_hits > offset)
69
+
70
+ # Return the hits info and the list of contacts
71
+ [total_hits, fetched_hits, contacts.flatten]
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,41 @@
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 = 'https://www.jigsaw.com/rest/searchCompany.json'
13
+ SEARCH_CONTACT_URL = 'https://www.jigsaw.com/rest/searchContact.json'
14
+ COMPANY_URL = 'https://www.jigsaw.com/rest/companies/'
15
+
16
+ def self.search_company(options = {})
17
+ request = new(SEARCH_COMPANY_URL, options)
18
+ request.parsed_response
19
+ end
20
+
21
+ def self.search_contact(options = {})
22
+ request = new(SEARCH_CONTACT_URL, options)
23
+ request.parsed_response
24
+ end
25
+
26
+ def self.company(id, options = {})
27
+ request = new(COMPANY_URL + id + ".json", options)
28
+ request.parsed_response
29
+ end
30
+
31
+ def initialize(url, options)
32
+ @response = self.class.get(url, :query => options)
33
+ end
34
+
35
+ def parsed_response
36
+ @response.parsed_response
37
+ end
38
+
39
+ end
40
+
41
+ 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
@@ -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,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcarvalho-jigsaw
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Matthew Bellantoni
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-11 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: activesupport
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: i18n
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 2
65
+ - 3
66
+ - 0
67
+ version: 2.3.0
68
+ type: :development
69
+ version_requirements: *id004
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ prerelease: false
73
+ requirement: &id005 !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 1
79
+ - 0
80
+ - 0
81
+ version: 1.0.0
82
+ type: :development
83
+ version_requirements: *id005
84
+ - !ruby/object:Gem::Dependency
85
+ name: jeweler
86
+ prerelease: false
87
+ requirement: &id006 !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 1
93
+ - 6
94
+ - 4
95
+ version: 1.6.4
96
+ type: :development
97
+ version_requirements: *id006
98
+ - !ruby/object:Gem::Dependency
99
+ name: rcov
100
+ prerelease: false
101
+ requirement: &id007 !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ type: :development
109
+ version_requirements: *id007
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ prerelease: false
113
+ requirement: &id008 !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ type: :development
121
+ version_requirements: *id008
122
+ description: Jigsaw.com API. Incomplete coverage.
123
+ email: mjbellantoni@yahoo.com
124
+ executables: []
125
+
126
+ extensions: []
127
+
128
+ extra_rdoc_files:
129
+ - LICENSE.txt
130
+ - README.md
131
+ files:
132
+ - .document
133
+ - .rspec
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - VERSION
140
+ - jigsaw.gemspec
141
+ - lib/jigsaw.rb
142
+ - lib/jigsaw/client.rb
143
+ - lib/jigsaw/company_search.rb
144
+ - lib/jigsaw/contact_search.rb
145
+ - lib/jigsaw/company.rb
146
+ - lib/jigsaw/request.rb
147
+ - spec/jigsaw/client_spec.rb
148
+ - spec/jigsaw/company_basic_spec.rb
149
+ - spec/jigsaw/request_spec.rb
150
+ - spec/spec_helper.rb
151
+ - spec/support/webmock/company_search_webmock_helpers.rb
152
+ has_rdoc: true
153
+ homepage: http://github.com/mjbellantoni/jigsaw
154
+ licenses:
155
+ - MIT
156
+ post_install_message:
157
+ rdoc_options: []
158
+
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ segments:
166
+ - 0
167
+ version: "0"
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ segments:
173
+ - 0
174
+ version: "0"
175
+ requirements: []
176
+
177
+ rubyforge_project:
178
+ rubygems_version: 1.3.6
179
+ signing_key:
180
+ specification_version: 3
181
+ summary: Jigsaw.com API. Incomplete coverage.
182
+ test_files: []
183
+