crunchbase 0.1.0 → 0.2.0

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.
data/README.rdoc CHANGED
@@ -49,7 +49,19 @@ number of results.
49
49
  all_results = s.to_ary
50
50
  result_slice = s[3..6]
51
51
 
52
- Coming Soon: List of Entities
52
+ === List all Items
53
+
54
+ If you've gone insane and want a list of every single item for a given entity
55
+ type, you can do so with the +all+ method.
56
+
57
+ all_companies = Company.all
58
+ company = all_companies[105]
59
+
60
+ This returns an array containing objects representing each entity. Just like
61
+ Search, the full item can be grabbed with the +entity+ method. Unlike Search,
62
+ however, all of the items are pre-fetched, so iterating through the list does
63
+ not entail a delay every ten items. Of course, the list is probably enormous,
64
+ so it's little consolation.
53
65
 
54
66
  == Copyright
55
67
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/crunchbase.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crunchbase}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Tyler Cunnion}]
12
- s.date = %q{2012-02-21}
12
+ s.date = %q{2012-02-28}
13
13
  s.email = %q{tyler.cunnion@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/crunchbase/company.rb",
30
30
  "lib/crunchbase/crunch_exception.rb",
31
31
  "lib/crunchbase/date_methods.rb",
32
+ "lib/crunchbase/entity_list_item.rb",
32
33
  "lib/crunchbase/financial_organization.rb",
33
34
  "lib/crunchbase/investment.rb",
34
35
  "lib/crunchbase/person.rb",
data/lib/crunchbase.rb CHANGED
@@ -11,10 +11,11 @@ require 'crunchbase/relationship'
11
11
  require 'crunchbase/relationships/firm_relationship'
12
12
  require 'crunchbase/relationships/person_relationship'
13
13
  require 'crunchbase/relationships/provider_relationship'
14
+ require 'crunchbase/entity_list_item'
14
15
  require 'crunchbase/search'
15
16
  require 'crunchbase/search_result'
16
17
  require 'crunchbase/crunch_exception'
17
18
 
18
19
  module Crunchbase
19
- VERSION = "0.1.0"
20
+ VERSION = "0.2.0"
20
21
  end
@@ -17,31 +17,22 @@ module Crunchbase
17
17
  # methods provided on each entity class instead of calling these directly.
18
18
  class API
19
19
  CB_URL = 'http://api.crunchbase.com/v/1/'
20
+ SUPPORTED_ENTITIES = ['person', 'company', 'financial-organization', 'product', 'service-provider']
20
21
  @timeout_limit = 60
21
22
  @redirect_limit = 2
22
23
 
23
24
  class << self; attr_accessor :timeout_limit, :redirect_limit end
24
-
25
- def self.person(permalink)
26
- fetch(permalink, 'person')
27
- end
28
-
29
- def self.company(permalink)
30
- fetch(permalink, 'company')
31
- end
32
-
33
- def self.financial_organization(permalink)
34
- fetch(permalink, 'financial-organization')
35
- end
36
-
37
- def self.product(permalink)
38
- fetch(permalink, 'product')
25
+
26
+ def self.single_entity(permalink, entity_name)
27
+ raise CrunchException, "Unsupported Entity Type" unless SUPPORTED_ENTITIES.include?(entity_name)
28
+ fetch(permalink, entity_name)
39
29
  end
40
-
41
- def self.service_provider(permalink)
42
- fetch(permalink, 'service-provider')
30
+
31
+ def self.all(entity)
32
+ uri = CB_URL + entity + ".js"
33
+ get_json_response(uri)
43
34
  end
44
-
35
+
45
36
  private
46
37
 
47
38
  # Returns the JSON parser, whether that's an instance of Yajl or JSON
@@ -82,7 +73,7 @@ module Crunchbase
82
73
  get_url_following_redirects(uri, @redirect_limit)
83
74
  }
84
75
  j = parser.parse(resp)
85
- raise CrunchException, j["error"] if j["error"]
76
+ raise CrunchException, j["error"] if j.class == Hash && j["error"]
86
77
  j
87
78
  end
88
79
 
@@ -2,7 +2,11 @@ module Crunchbase
2
2
 
3
3
  # Represents any object which can be pulled directly from the CB API.
4
4
  class CB_Object
5
-
5
+
6
+ # Must be overridden in subclasses
7
+ ENT_NAME = "undefined"
8
+ ENT_PLURAL = "undefineds"
9
+
6
10
  # Returns an array of tags
7
11
  def tags
8
12
  @tag_list.respond_to?('split') ? @tag_list.split(', ') : []
@@ -13,6 +17,24 @@ module Crunchbase
13
17
  @alias_list.respond_to?('split') ? @alias_list.split(", ") : []
14
18
  end
15
19
 
20
+ # Factory method to return an instance from a permalink
21
+ def self.get(permalink)
22
+ j = API.single_entity(permalink, self::ENT_NAME)
23
+ e = self.new(j)
24
+ return e
25
+ end
26
+
27
+ def self.find(name)
28
+ get(API.permalink({name: name}, self::ENT_PLURAL)["permalink"])
29
+ end
30
+
31
+ def self.all
32
+ all = API.all(self::ENT_PLURAL).map do |ent|
33
+ ent["namespace"] = self::ENT_NAME
34
+ EntityListItem.new(ent)
35
+ end
36
+ end
37
+
16
38
 
17
39
  # Compares two objects, returning true if they have the same permalink
18
40
  # (ie, represent the same entity). If you must ensure that the two objects
@@ -3,6 +3,9 @@ module Crunchbase
3
3
  # Represents a Company listed in the Crunchbase.
4
4
  class Company < CB_Object
5
5
 
6
+ ENT_NAME = "company"
7
+ ENT_PLURAL = "companies"
8
+
6
9
  include Crunchbase::DateMethods
7
10
 
8
11
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
@@ -13,18 +16,6 @@ module Crunchbase
13
16
  :investments, :acquisition, :acquisitions, :offices, :milestones, :ipo,
14
17
  :video_embeds, :screenshots, :external_links
15
18
 
16
- # Factory method to return a Company instance from a permalink
17
- def self.get(permalink)
18
- j = API.company(permalink)
19
- c = Company.new(j)
20
- return c
21
- end
22
-
23
- # Factory method to return a Company instance from a company name.
24
- def self.find(name)
25
- get(API.permalink({name: name}, "companies")["permalink"])
26
- end
27
-
28
19
  def initialize(json)
29
20
  @name = json["name"]
30
21
  @permalink = json["permalink"]
@@ -0,0 +1,59 @@
1
+ module Crunchbase
2
+ class EntityListItem
3
+
4
+ attr_reader :permalink, :namespace
5
+
6
+ def initialize(json)
7
+ @namespace = json["namespace"]
8
+ if @namespace == "person"
9
+ @first_name = json["first_name"]
10
+ @last_name = json["last_name"]
11
+ else
12
+ @name = json["name"]
13
+ end
14
+ @permalink = json["permalink"]
15
+ end
16
+
17
+ def first_name
18
+ raise CrunchException, "Not available for this entity" unless namespace == "person"
19
+ @first_name
20
+ end
21
+
22
+ def last_name
23
+ raise CrunchException, "Not available for this entity" unless namespace == "person"
24
+ @last_name
25
+ end
26
+
27
+ # Returns concatenation of first and last names if person, otherwise
28
+ # returns name. Thus, if you wanted to, for example, iterate over search
29
+ # results and output the name, you could do so without checking entity type
30
+ # first.
31
+ def name
32
+ if @namespace == "person"
33
+ @first_name + " " + @last_name
34
+ else
35
+ @name
36
+ end
37
+ end
38
+
39
+ # Returns the entity associated with the search result, loading from
40
+ # memory if previously fetched, unless +force_reload+ is set to true.
41
+ def entity(force_reload=false)
42
+ return @entity unless @entity.nil? || force_reload
43
+ @entity = case @namespace
44
+ when "company"
45
+ Company.get(@permalink)
46
+ when "financial-organization"
47
+ FinancialOrganization.get(@permalink)
48
+ when "person"
49
+ Person.get(@permalink)
50
+ when "product"
51
+ Product.get(@permalink)
52
+ when "service-provider"
53
+ ServiceProvider.get(@permalink)
54
+ end
55
+ return @entity
56
+ end
57
+
58
+ end
59
+ end
@@ -3,6 +3,9 @@ module Crunchbase
3
3
  # Represents a Financial Organization listed in the Crunchbase.
4
4
  class FinancialOrganization < CB_Object
5
5
 
6
+ ENT_NAME = "financial-organization"
7
+ ENT_PLURAL = "financial-organizations"
8
+
6
9
  include Crunchbase::DateMethods
7
10
 
8
11
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
@@ -11,17 +14,6 @@ module Crunchbase
11
14
  :overview, :image, :offices, :relationships, :investments, :milestones,
12
15
  :providerships, :funds, :video_embeds, :external_links
13
16
 
14
- # Factory method to return a FinancialOrganization instance from a permalink
15
- def self.get(permalink)
16
- j = API.financial_organization(permalink)
17
- f = FinancialOrganization.new(j)
18
- return f
19
- end
20
-
21
- def self.find(name)
22
- get(API.permalink({name: name}, "financial-organizations")["permalink"])
23
- end
24
-
25
17
  def initialize(json)
26
18
  @name = json['name']
27
19
  @permalink = json['permalink']
@@ -2,6 +2,9 @@ require 'date'
2
2
  module Crunchbase
3
3
  class Person < CB_Object
4
4
 
5
+ ENT_NAME = "person"
6
+ ENT_PLURAL = "people"
7
+
5
8
  include Crunchbase::DateMethods
6
9
 
7
10
  attr_reader :first_name, :last_name, :permalink, :crunchbase_url,
@@ -9,13 +12,6 @@ module Crunchbase
9
12
  :affiliation_name, :created_at, :updated_at, :overview, :created_at,
10
13
  :updated_at, :overview, :relationships, :investments, :milestones,
11
14
  :video_embeds, :external_links, :web_presences
12
-
13
- # Factory method to return a Person instance from a permalink
14
- def self.get(permalink)
15
- j = API.person(permalink)
16
- p = Person.new(j)
17
- return p
18
- end
19
15
 
20
16
  def self.find(first_name, last_name)
21
17
  get(API.permalink({first_name: first_name, last_name: last_name}, "people")["permalink"])
@@ -2,6 +2,9 @@ require 'date'
2
2
  module Crunchbase
3
3
  class Product < CB_Object
4
4
 
5
+ ENT_NAME = "product"
6
+ ENT_PLURAL = "products"
7
+
5
8
  include Crunchbase::DateMethods
6
9
 
7
10
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
@@ -9,15 +12,6 @@ module Crunchbase
9
12
  :invite_share_url, :created_at, :updated_at, :overview, :image,
10
13
  :company_permalink, :company_name, :milestones, :video_embeds,
11
14
  :external_links
12
-
13
- def self.get(permalink)
14
- j = API.product(permalink)
15
- return Product.new(j)
16
- end
17
-
18
- def self.find(name)
19
- get(API.permalink({name: name}, "products")["permalink"])
20
- end
21
15
 
22
16
  def initialize(json)
23
17
  @name = json['name']
@@ -3,61 +3,14 @@ module Crunchbase
3
3
  # returned from a search includes the name, namespace (i.e. entity type),
4
4
  # permalink, and an overview. You may also choose to retrieve the full
5
5
  # entity with the entity method.
6
- class SearchResult
7
- attr_reader :permalink, :crunchbase_url, :namespace, :overview
8
-
9
- def first_name
10
- raise CrunchException, "Not available for this entity" unless namespace == "person"
11
- @first_name
12
- end
13
-
14
- def last_name
15
- raise CrunchException, "Not available for this entity" unless namespace == "person"
16
- @last_name
17
- end
18
-
19
- # Returns concatenation of first and last names if person, otherwise
20
- # returns name. Thus, if you wanted to, for example, iterate over search
21
- # results and output the name, you could do so without checking entity type
22
- # first.
23
- def name
24
- if @namespace == "person"
25
- @first_name + " " + @last_name
26
- else
27
- @name
28
- end
29
- end
6
+ class SearchResult < EntityListItem
7
+ attr_reader :crunchbase_url, :overview
30
8
 
31
9
  def initialize(json)
32
- @namespace = json["namespace"]
33
- if @namespace == "person"
34
- @first_name = json["first_name"]
35
- @last_name = json["last_name"]
36
- else
37
- @name = json["name"]
38
- end
39
- @permalink = json["permalink"]
10
+ super
40
11
  @crunchbase_url = json["crunchbase_url"]
41
12
  @overview = json["overview"]
42
13
  end
43
-
44
- # Returns the entity associated with the search result, loading from
45
- # memory if previously fetched, unless +force_reload+ is set to true.
46
- def entity(force_reload=false)
47
- return @entity unless @entity.nil? || force_reload
48
- @entity = case @namespace
49
- when "company"
50
- Company.get(@permalink)
51
- when "financial-organization"
52
- FinancialOrganization.get(@permalink)
53
- when "person"
54
- Person.get(@permalink)
55
- when "product"
56
- Product.get(@permalink)
57
- when "service-provider"
58
- ServiceProvider.get(@permalink)
59
- end
60
- return @entity
61
- end
14
+
62
15
  end
63
16
  end
@@ -2,20 +2,12 @@ require 'date'
2
2
  module Crunchbase
3
3
  class ServiceProvider < CB_Object
4
4
 
5
+ ENT_NAME = "service-provider"
6
+ ENT_PLURAL = "service-providers"
7
+
5
8
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url,
6
9
  :phone_number, :created_at, :updated_at, :overview, :image, :offices,
7
10
  :providerships, :external_links
8
-
9
- # Factory method to return a ServiceProvider instance from a permalink
10
- def self.get(permalink)
11
- j = API.service_provider(permalink)
12
- s = ServiceProvider.new(j)
13
- return s
14
- end
15
-
16
- def self.find(name)
17
- get(API.permalink({name: name}, "service-providers")["permalink"])
18
- end
19
11
 
20
12
  def initialize(json)
21
13
  @name = json["name"]
@@ -10,12 +10,16 @@ module Crunchbase
10
10
  end
11
11
 
12
12
  it "should return JSON from person permalink" do
13
- j = API.person("steve-jobs")
13
+ j = API.single_entity("steve-jobs", "person")
14
14
  j.class.should == Hash
15
15
  end
16
16
 
17
17
  it "should raise exception on unfound person" do
18
- expect { API.person("not-real") }.to raise_error
18
+ expect { API.single_entity("not-real", "person") }.to raise_error, "Sorry, we could not find the record you were looking for."
19
+ end
20
+
21
+ it "should raise exception for incorrect entity name" do
22
+ expect { API.single_entity("whatever", "wrong") }.to raise_error, "Unsupported Entity Type"
19
23
  end
20
24
 
21
25
  it "should follow redirects" do
@@ -26,6 +26,11 @@ module Crunchbase
26
26
  "updated_at" => "Sat Dec 22 08:42:28 UTC 2007"})
27
27
  company.deadpooled.should === Date.new(2004, 2, 1)
28
28
  end
29
+
30
+ it "should get a complete list" do
31
+ all_companies = Company.all
32
+ all_companies[0].entity.name.should == all_companies[0].name
33
+ end
29
34
 
30
35
 
31
36
  end
@@ -20,5 +20,10 @@ module Crunchbase
20
20
  finorg.founded.should === Date.new(2004, 2, 1)
21
21
  end
22
22
 
23
+ it "should get a complete list" do
24
+ all_fins = FinancialOrganization.all
25
+ all_fins[0].entity.name.should == all_fins[0].name
26
+ end
27
+
23
28
  end
24
29
  end
@@ -15,16 +15,16 @@ module Crunchbase
15
15
  end
16
16
 
17
17
  it "should ask for JSON object" do
18
- API.should_receive(:person).with("brad-fitzpatrick").and_return(JSON.parse(@brad.read))
18
+ API.should_receive(:single_entity).with("brad-fitzpatrick", "person").and_return(JSON.parse(@brad.read))
19
19
  person = Person.get("brad-fitzpatrick")
20
20
  end
21
21
 
22
22
  it "should get information from supplied file" do
23
- API.should_receive(:person).with("steve-jobs").and_return(JSON.parse(@steve.read))
23
+ API.should_receive(:single_entity).with("steve-jobs", "person").and_return(JSON.parse(@steve.read))
24
24
  person = Person.get("steve-jobs")
25
25
  person.first_name.should == "Steve"
26
26
 
27
- API.should_receive(:person).with("brad-fitzpatrick").and_return(JSON.parse(@brad.read))
27
+ API.should_receive(:single_entity).with("brad-fitzpatrick", "person").and_return(JSON.parse(@brad.read))
28
28
  person = Person.get("brad-fitzpatrick")
29
29
  person.first_name.should == "Brad"
30
30
  end
@@ -72,5 +72,11 @@ module Crunchbase
72
72
  person.should === person2
73
73
  end
74
74
 
75
+ it "should get a complete list" do
76
+ all_people = Person.all
77
+ all_people[0].entity.first_name.should == all_people[0].first_name
78
+ all_people[0].entity.last_name.should == all_people[0].last_name
79
+ end
80
+
75
81
  end
76
82
  end
@@ -26,5 +26,10 @@ module Crunchbase
26
26
  "updated_at" => "Sat Dec 22 08:42:28 UTC 2007", "company" => {}})
27
27
  product.deadpooled.should === Date.new(2004, 2, 1)
28
28
  end
29
+
30
+ it "should get a complete list" do
31
+ all_products = Product.all
32
+ all_products[0].entity.name.should == all_products[0].name
33
+ end
29
34
  end
30
35
  end
@@ -13,5 +13,10 @@ module Crunchbase
13
13
  sp.permalink.should == "fox-rothschild"
14
14
  end
15
15
 
16
+ it "should get a complete list" do
17
+ all_sps = ServiceProvider.all
18
+ all_sps[0].entity.name.should == all_sps[0].name
19
+ end
20
+
16
21
  end
17
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crunchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-21 00:00:00.000000000Z
12
+ date: 2012-02-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70265569207100 !ruby/object:Gem::Requirement
16
+ requirement: &70327968354500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70265569207100
24
+ version_requirements: *70327968354500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70265569206160 !ruby/object:Gem::Requirement
27
+ requirement: &70327968353340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70265569206160
35
+ version_requirements: *70327968353340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70265569205140 !ruby/object:Gem::Requirement
38
+ requirement: &70327968352400 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70265569205140
46
+ version_requirements: *70327968352400
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &70265569204040 !ruby/object:Gem::Requirement
49
+ requirement: &70327968350960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70265569204040
57
+ version_requirements: *70327968350960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rdoc
60
- requirement: &70265569202940 !ruby/object:Gem::Requirement
60
+ requirement: &70327968349800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70265569202940
68
+ version_requirements: *70327968349800
69
69
  description:
70
70
  email: tyler.cunnion@gmail.com
71
71
  executables: []
@@ -87,6 +87,7 @@ files:
87
87
  - lib/crunchbase/company.rb
88
88
  - lib/crunchbase/crunch_exception.rb
89
89
  - lib/crunchbase/date_methods.rb
90
+ - lib/crunchbase/entity_list_item.rb
90
91
  - lib/crunchbase/financial_organization.rb
91
92
  - lib/crunchbase/investment.rb
92
93
  - lib/crunchbase/person.rb
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  segments:
126
127
  - 0
127
- hash: 4487821890368483707
128
+ hash: 2248363577786522930
128
129
  required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  none: false
130
131
  requirements: