crunchbase 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "json"
4
+
5
+ group :development do
6
+ gem "rspec"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "rcov", ">= 0"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ json (1.5.4)
11
+ rake (0.9.2)
12
+ rcov (0.9.10)
13
+ rspec (2.6.0)
14
+ rspec-core (~> 2.6.0)
15
+ rspec-expectations (~> 2.6.0)
16
+ rspec-mocks (~> 2.6.0)
17
+ rspec-core (2.6.4)
18
+ rspec-expectations (2.6.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.6.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.4)
28
+ json
29
+ rcov
30
+ rspec
data/README.rdoc CHANGED
@@ -4,10 +4,15 @@ Library for pulling data from the CrunchBase API.
4
4
 
5
5
  == Usage
6
6
 
7
- require 'crunchbase'
7
+ require 'crunchbase'
8
+ steve = Crunchbase::Person.get("steve-jobs")
9
+ facebook = Crunchbase::Company.get("facebook")
10
+
8
11
 
9
12
  == Copyright
10
13
 
11
14
  Copyright (c) 2011 Tyler Cunnion. See LICENSE.txt for
12
15
  further details.
13
16
 
17
+ I am not affiliated with AOL, Crunchbase, or anyone really.
18
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
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 = "crunchbase"
18
+ gem.homepage = "http://github.com/tylercunnion/crunchbase"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby wrapper for CrunchBase API}
21
+ gem.email = "tyler.cunnion@gmail.com"
22
+ gem.authors = ["Tyler Cunnion"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ test.rcov_opts << '--exclude "gems/*"'
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "crunchbase #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
@@ -0,0 +1,73 @@
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 = %q{crunchbase}
8
+ s.version = "0.0.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Tyler Cunnion}]
12
+ s.date = %q{2011-09-18}
13
+ s.email = %q{tyler.cunnion@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "LICENSE.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "crunchbase.gemspec",
26
+ "lib/crunchbase.rb",
27
+ "lib/crunchbase/api.rb",
28
+ "lib/crunchbase/cb_object.rb",
29
+ "lib/crunchbase/company.rb",
30
+ "lib/crunchbase/crunch_exception.rb",
31
+ "lib/crunchbase/investment.rb",
32
+ "lib/crunchbase/person.rb",
33
+ "lib/crunchbase/relationship.rb",
34
+ "lib/crunchbase/relationships/firm_relationship.rb",
35
+ "lib/crunchbase/relationships/person_relationship.rb",
36
+ "spec/crunchbase/api_spec.rb",
37
+ "spec/crunchbase/company_spec.rb",
38
+ "spec/crunchbase/person_spec.rb",
39
+ "spec/fixtures/brad-fitzpatrick.js",
40
+ "spec/fixtures/steve-jobs.js",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/tylercunnion/crunchbase}
44
+ s.licenses = [%q{MIT}]
45
+ s.require_paths = [%q{lib}]
46
+ s.rubygems_version = %q{1.8.6}
47
+ s.summary = %q{Ruby wrapper for CrunchBase API}
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<json>, [">= 0"])
54
+ s.add_development_dependency(%q<rspec>, [">= 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
+ else
59
+ s.add_dependency(%q<json>, [">= 0"])
60
+ s.add_dependency(%q<rspec>, [">= 0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<json>, [">= 0"])
67
+ s.add_dependency(%q<rspec>, [">= 0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ end
72
+ end
73
+
data/lib/crunchbase.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'crunchbase/api'
2
2
  require 'crunchbase/cb_object'
3
3
  require 'crunchbase/company'
4
+ require 'crunchbase/investment'
4
5
  require 'crunchbase/person'
6
+ require 'crunchbase/relationship'
7
+ require 'crunchbase/relationships/firm_relationship'
8
+ require 'crunchbase/relationships/person_relationship'
5
9
  require 'crunchbase/crunch_exception'
6
10
 
7
11
  module Crunchbase
@@ -7,18 +7,29 @@ module Crunchbase
7
7
  CB_URL = 'http://api.crunchbase.com/v/1/'
8
8
 
9
9
  def self.person(permalink)
10
- fetch_uri = URI.parse(CB_URL + "person/#{permalink}.js")
11
- fetch(fetch_uri)
10
+ fetch(permalink, 'person')
12
11
  end
13
12
 
14
13
  def self.company(permalink)
15
- fetch_uri = URI.parse(CB_URL + "company/#{permalink}.js")
16
- fetch(fetch_uri)
14
+ fetch(permalink, 'company')
15
+ end
16
+
17
+ def self.financial_organization(permalink)
18
+ fetch(permalink, 'financial-organization')
19
+ end
20
+
21
+ def self.product(permalink)
22
+ fetch(permalink, 'product')
23
+ end
24
+
25
+ def self.service_provider(permalink)
26
+ fetch(permalink, 'service-provider')
17
27
  end
18
28
 
19
29
  # Fetches URI and parses JSON. Raises Timeout::Error if fetching times out.
20
30
  # Raises CrunchException if the returned JSON indicates an error.
21
- def self.fetch(uri)
31
+ def self.fetch(permalink, object_name)
32
+ uri = URI.parse(CB_URL + "#{object_name}/#{permalink}.js")
22
33
  resp = Timeout::timeout(5) {
23
34
  Net::HTTP.get(uri)
24
35
  }
@@ -10,8 +10,13 @@ module Crunchbase
10
10
  @alias_list.respond_to?('split') ? @alias_list.split(", ") : []
11
11
  end
12
12
 
13
+
14
+ # Compares two objects, returning true if they have the same permalink
15
+ # (ie, represent the same entity). If you must ensure that the two objects
16
+ # also contain the same data, you should also compare the updated_at
17
+ # attributes.
13
18
  def ===(other)
14
- @permalink == other.permalink && @updated_at == other.updated_at
19
+ @permalink == other.permalink
15
20
  end
16
21
 
17
22
  end
@@ -45,7 +45,7 @@ module Crunchbase
45
45
  @overview = json["overview"]
46
46
  @image = json["image"]
47
47
  @products = json["products"]
48
- @relationships = json["relationships"]
48
+ @relationships = Relationship.array_from_relationship_list(json["relationships"]) if json["relationships"]
49
49
  @competitions = json["competitions"]
50
50
  @providerships = json["providerships"]
51
51
  @total_money_raised = json["total_money_raised"]
@@ -0,0 +1,44 @@
1
+ module Crunchbase
2
+ class Investment
3
+
4
+ attr_reader :funding_round_code, :funding_source_url,
5
+ :funding_source_description, :raised_amount, :raised_currency_code,
6
+ :company_name, :company_permalink
7
+
8
+ def self.array_from_investment_list(list)
9
+ list.map{|l| self.new(l)}
10
+ end
11
+
12
+ def initialize(hash)
13
+ hash = hash["funding_round"]
14
+ @funding_round_code = hash["round_code"]
15
+ @funding_source_url = hash["source_url"]
16
+ @funding_source_description = hash["source_description"]
17
+ @raised_amount = hash["raised_amount"]
18
+ @raised_currency_code = hash["raised_currency_code"]
19
+ @funded_year = hash["funded_year"]
20
+ @funded_month = hash["funded_month"]
21
+ @funded_day = hash["funded_day"]
22
+ @company_name = hash["company"]["name"]
23
+ @company_permalink = hash["company"]["permalink"]
24
+ end
25
+
26
+ # Retrieves associated Company object, storing it for future use.
27
+ # If +force_reload+ is set to true, it will bypass the stored version.
28
+ def company(force_reload=false)
29
+ return @company unless @company.nil? || force_reload
30
+ @company = Company.get(@company_permalink)
31
+ return @company
32
+ end
33
+
34
+ def funded_date
35
+ begin
36
+ date = Date.new(@funded_year, @funded_month, @funded_day)
37
+ rescue
38
+ nil
39
+ end
40
+ date
41
+ end
42
+
43
+ end
44
+ end
@@ -5,7 +5,9 @@ module Crunchbase
5
5
  attr_reader :first_name, :last_name, :permalink, :crunchbase_url,
6
6
  :homepage_url, :birthplace, :twitter_username, :blog_url, :blog_feed_url,
7
7
  :affiliation_name, :born_year, :born_month, :born_day, :created_at,
8
- :updated_at, :overview, :tag_list
8
+ :updated_at, :overview, :tag_list, :alias_list, :created_at, :updated_at,
9
+ :overview, :relationships, :investments, :milestones, :video_embeds,
10
+ :external_links, :web_presences
9
11
 
10
12
  def self.get(permalink)
11
13
  j = API.person(permalink)
@@ -33,8 +35,8 @@ module Crunchbase
33
35
  @updated_at = DateTime.parse(json["updated_at"])
34
36
  @overview = json["overview"]
35
37
 
36
- @relationships = json["relationships"]
37
- @investments = json["investments"]
38
+ @relationships = Relationship.array_from_relationship_list(json["relationships"]) if json["relationships"]
39
+ @investments = Investment.array_from_investment_list(json["investments"]) if json["investments"]
38
40
  @milestones = json["milestones"]
39
41
  @video_embeds = json["video_embeds"]
40
42
  @external_links = json["external_links"]
@@ -0,0 +1,35 @@
1
+ module Crunchbase
2
+ class Relationship
3
+
4
+ attr_reader :title
5
+
6
+ # Takes a relationship list (directly from the JSON hash) and returns an
7
+ # array of instances of Relationship subclasses. Raises CrunchException if
8
+ # the relationship is not one of the recognized types.
9
+ def self.array_from_relationship_list(list)
10
+ list.map do |l|
11
+ if l["person"]
12
+ PersonRelationship.new(l)
13
+ elsif l["firm"]
14
+ FirmRelationship.new(l)
15
+ else
16
+ raise CrunchException, "Relationship type not recognized"
17
+ end
18
+ end
19
+ end
20
+
21
+ def initialize(hash)
22
+ @is_past = hash["is_past"]
23
+ @title = hash["title"]
24
+ end
25
+
26
+ # Convenience method, returns opposite of is_past?
27
+ def current?
28
+ !@is_past
29
+ end
30
+
31
+ def is_past?
32
+ @is_past
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ module Crunchbase
2
+ class FirmRelationship < Relationship
3
+
4
+ attr_reader :firm_name, :firm_permalink, :firm_type
5
+
6
+ def self.array_from_relationship_list
7
+ raise CrunchException, "Method must be called from superclass Relationship"
8
+ end
9
+
10
+ def initialize(hash)
11
+ super(hash)
12
+ @firm_name = hash["firm"]["name"]
13
+ @firm_permalink = hash["firm"]["permalink"]
14
+ @firm_type = hash["firm"]["type_of_entity"]
15
+ end
16
+
17
+ # Returns a representation of the associated firm, loading from memory
18
+ # if previously fetched, unless force_reload is set to true.
19
+ def firm(force_reload=false)
20
+ return @firm unless @firm.nil? || force_reload
21
+ @firm = case @firm_type
22
+ when "company"
23
+ Company.get(@firm_permalink)
24
+ when "financial_org"
25
+ raise CrunchException, "Not implemented"
26
+ else
27
+ raise CrunchException, "Not implemented"
28
+ end
29
+ return @firm
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Crunchbase
2
+ class PersonRelationship < Relationship
3
+
4
+ attr_reader :person_first_name, :person_last_name, :person_permalink
5
+
6
+ def self.array_from_relationship_list
7
+ raise CrunchException, "Method must be called from superclass Relationship"
8
+ end
9
+
10
+ def initialize(hash)
11
+ super(hash)
12
+ @person_first_name = hash["person"]["first_name"]
13
+ @person_last_name = hash["person"]["last_name"]
14
+ @person_permalink = hash["person"]["permalink"]
15
+ end
16
+
17
+ # Returns a representation of the associated person, loading from memory
18
+ # if previously fetched, unless force_reload is set to true.
19
+ def person(force_reload=false)
20
+ return @person unless @person.nil? || force_reload
21
+ @person = Person.get(@person_permalink)
22
+ end
23
+
24
+ end
25
+ end
@@ -5,7 +5,7 @@ module Crunchbase
5
5
  describe API do
6
6
 
7
7
  it "should return a JSON hash" do
8
- j = API.fetch(URI.parse(API::CB_URL + "person/steve-jobs.js"))
8
+ j = API.fetch('steve-jobs', 'person')
9
9
  j.class.should == Hash
10
10
  end
11
11
 
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.0.1
4
+ version: 0.0.3
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: 2011-09-12 00:00:00.000000000Z
12
+ date: 2011-09-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70283755317100 !ruby/object:Gem::Requirement
16
+ requirement: &70340165019820 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *70283755317100
24
+ version_requirements: *70340165019820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70283755316060 !ruby/object:Gem::Requirement
27
+ requirement: &70340165403900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70283755316060
35
+ version_requirements: *70340165403900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70283755314920 !ruby/object:Gem::Requirement
38
+ requirement: &70340165568620 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70283755314920
46
+ version_requirements: *70340165568620
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70283755313820 !ruby/object:Gem::Requirement
49
+ requirement: &70340165737320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70283755313820
57
+ version_requirements: *70340165737320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70283755312820 !ruby/object:Gem::Requirement
60
+ requirement: &70340165735940 !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: *70283755312820
68
+ version_requirements: *70340165735940
69
69
  description:
70
70
  email: tyler.cunnion@gmail.com
71
71
  executables: []
@@ -74,21 +74,29 @@ extra_rdoc_files:
74
74
  - LICENSE.txt
75
75
  - README.rdoc
76
76
  files:
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE.txt
80
+ - README.rdoc
81
+ - Rakefile
77
82
  - VERSION
83
+ - crunchbase.gemspec
78
84
  - lib/crunchbase.rb
79
85
  - lib/crunchbase/api.rb
80
86
  - lib/crunchbase/cb_object.rb
81
87
  - lib/crunchbase/company.rb
82
88
  - lib/crunchbase/crunch_exception.rb
89
+ - lib/crunchbase/investment.rb
83
90
  - lib/crunchbase/person.rb
91
+ - lib/crunchbase/relationship.rb
92
+ - lib/crunchbase/relationships/firm_relationship.rb
93
+ - lib/crunchbase/relationships/person_relationship.rb
84
94
  - spec/crunchbase/api_spec.rb
85
95
  - spec/crunchbase/company_spec.rb
86
96
  - spec/crunchbase/person_spec.rb
87
97
  - spec/fixtures/brad-fitzpatrick.js
88
98
  - spec/fixtures/steve-jobs.js
89
99
  - spec/spec_helper.rb
90
- - LICENSE.txt
91
- - README.rdoc
92
100
  homepage: http://github.com/tylercunnion/crunchbase
93
101
  licenses:
94
102
  - MIT
@@ -104,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
112
  version: '0'
105
113
  segments:
106
114
  - 0
107
- hash: 4570443541107244094
115
+ hash: -784236536464122673
108
116
  required_rubygems_version: !ruby/object:Gem::Requirement
109
117
  none: false
110
118
  requirements: