crunchbase_v2 0.0.1

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.
Files changed (68) hide show
  1. data/.gitignore +25 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.rdoc +88 -0
  5. data/Rakefile +7 -0
  6. data/crunchbase.gemspec +24 -0
  7. data/lib/crunchbase.rb +36 -0
  8. data/lib/crunchbase/acquisition.rb +66 -0
  9. data/lib/crunchbase/api.rb +153 -0
  10. data/lib/crunchbase/board_members_and_advisor.rb +23 -0
  11. data/lib/crunchbase/category.rb +22 -0
  12. data/lib/crunchbase/cb_entity.rb +70 -0
  13. data/lib/crunchbase/competitor.rb +25 -0
  14. data/lib/crunchbase/crunch_exception.rb +6 -0
  15. data/lib/crunchbase/current_team.rb +26 -0
  16. data/lib/crunchbase/customer.rb +21 -0
  17. data/lib/crunchbase/founder.rb +21 -0
  18. data/lib/crunchbase/funding_round.rb +69 -0
  19. data/lib/crunchbase/headquarter.rb +27 -0
  20. data/lib/crunchbase/image.rb +21 -0
  21. data/lib/crunchbase/investment.rb +33 -0
  22. data/lib/crunchbase/ipo.rb +57 -0
  23. data/lib/crunchbase/location.rb +24 -0
  24. data/lib/crunchbase/new_item.rb +22 -0
  25. data/lib/crunchbase/office.rb +28 -0
  26. data/lib/crunchbase/organization.rb +246 -0
  27. data/lib/crunchbase/past_team.rb +29 -0
  28. data/lib/crunchbase/person.rb +31 -0
  29. data/lib/crunchbase/primary_image.rb +21 -0
  30. data/lib/crunchbase/product.rb +78 -0
  31. data/lib/crunchbase/relationship.rb +17 -0
  32. data/lib/crunchbase/search.rb +45 -0
  33. data/lib/crunchbase/search_result.rb +11 -0
  34. data/lib/crunchbase/sub_organization.rb +21 -0
  35. data/lib/crunchbase/version.rb +3 -0
  36. data/lib/crunchbase/website.rb +20 -0
  37. data/spec/apikey.example.yml +2 -0
  38. data/spec/bootstrap.rb +9 -0
  39. data/spec/crunchbase/acquisition_spec.rb +26 -0
  40. data/spec/crunchbase/api_spec.rb +8 -0
  41. data/spec/crunchbase/board_members_and_advisor_spec.rb +16 -0
  42. data/spec/crunchbase/category_spec.rb +25 -0
  43. data/spec/crunchbase/competitor_spec.rb +19 -0
  44. data/spec/crunchbase/current_team_spec.rb +17 -0
  45. data/spec/crunchbase/customer_spec.rb +20 -0
  46. data/spec/crunchbase/founder_spec.rb +20 -0
  47. data/spec/crunchbase/funding_round_spec.rb +26 -0
  48. data/spec/crunchbase/headquarter_spec.rb +17 -0
  49. data/spec/crunchbase/investment_spec.rb +20 -0
  50. data/spec/crunchbase/ipo_spec.rb +29 -0
  51. data/spec/crunchbase/location_spec.rb +16 -0
  52. data/spec/crunchbase/new_item_spec.rb +33 -0
  53. data/spec/crunchbase/office_spec.rb +19 -0
  54. data/spec/crunchbase/organization_spec.rb +62 -0
  55. data/spec/crunchbase/past_team_spec.rb +16 -0
  56. data/spec/crunchbase/person_spec.rb +23 -0
  57. data/spec/crunchbase/primary_image_spec.rb +21 -0
  58. data/spec/crunchbase/product_spec.rb +28 -0
  59. data/spec/crunchbase/search_result_spec.rb +16 -0
  60. data/spec/crunchbase/search_spec.rb +17 -0
  61. data/spec/crunchbase/sub_organization_spec.rb +21 -0
  62. data/spec/crunchbase/website_spec.rb +25 -0
  63. data/spec/fixtures/facebook-acquisition.js +82 -0
  64. data/spec/fixtures/facebook-funding-round.js +96 -0
  65. data/spec/fixtures/organization-facebook.js +1023 -0
  66. data/spec/fixtures/person-randi-zuckerberg.js +233 -0
  67. data/spec/spec_helper.rb +10 -0
  68. metadata +192 -0
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/categories?user_key=key
4
+ module Crunchbase
5
+ class Category < CBEntity
6
+ RESOURCE_NAME = 'category'
7
+ RESOURCE_LIST = 'categories'
8
+
9
+ attr_reader :type_name, :name, :uuid, :path, :created_at, :updated_at
10
+
11
+ def initialize(json)
12
+ @type_name = json['type']
13
+ @name = json['name']
14
+ @uuid = json['uuid']
15
+ @path = json['path']
16
+ @created_at = Time.at(json['created_at']).utc
17
+ @updated_at = Time.at(json['updated_at']).utc
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ module Crunchbase
4
+ class CBEntity
5
+
6
+ RELATIONSHIPS = %w[ Crunchbase::Ipo Crunchbase::Product Crunchbase::SubOrganization Crunchbase::FundingRound Crunchbase::Founder Crunchbase::Customer Crunchbase::Competitor Crunchbase::Acquisition ]
7
+
8
+ # Factory method to return an instance from a permalink
9
+ def self.get(permalink)
10
+ return self.new( API.single_entity(permalink, self::RESOURCE_NAME) )
11
+ end
12
+
13
+ # Finds an entity by its name. Uses two HTTP requests; one to find the
14
+ # permalink, and another to request the actual entity.
15
+ # http://api.crunchbase.com/v/2/organizations?name=ekohe&organization_types=company&user_key=key&page=1"
16
+ def self.search(options)
17
+ return [] unless self == Crunchbase::Organization
18
+
19
+ return Search.new options, API.search( options, self::RESOURCE_LIST )
20
+ end
21
+
22
+ def self.lists_for_permalink(permalink, options={})
23
+ options[:model_name] = (RELATIONSHIPS.include?(self.name) ? Relationship : self)
24
+
25
+ return API.lists_for_permalink(permalink, self::RESOURCE_LIST, options)
26
+ end
27
+
28
+ def fetch
29
+ fetch_object = get_fetch_object
30
+ return [] if fetch_object.empty?
31
+
32
+ return fetch_object[0].new API.fetch(self.permalink, fetch_object[1])
33
+ end
34
+
35
+ def self.list(page=nil)
36
+ options = { page: page, model_name: self }
37
+
38
+ return API.list( options, self::RESOURCE_LIST )
39
+ end
40
+
41
+ def self.array_from_list(list)
42
+ list['items'].map do |l|
43
+ self.new l
44
+ end
45
+ end
46
+
47
+ def self.total_items_from_list(list)
48
+ list['paging']['total_items']
49
+ end
50
+
51
+ private
52
+ def get_fetch_object
53
+ case self.type_name
54
+ when 'Organization' then [Crunchbase::Organization, 'organization']
55
+ when 'Ipo' then [Crunchbase::Ipo, 'ipo']
56
+ when 'Person' then [Crunchbase::Person, 'person']
57
+ when 'Product' then [Crunchbase::Product, 'product']
58
+ when 'SubOrganization' then [Crunchbase::SubOrganization, 'organization']
59
+ when 'FundingRound' then [Crunchbase::FundingRound, 'funding-round']
60
+ when 'Founder' then [Crunchbase::Founder, 'organization']
61
+ when 'Customer' then [Crunchbase::Customer, 'organization']
62
+ when 'Competitor' then [Crunchbase::Competitor, 'organization']
63
+ when 'Acquisition' then [Crunchbase::Acquisition, 'acquisition']
64
+ else
65
+ []
66
+ end
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/competitors
4
+
5
+ module Crunchbase
6
+ class Competitor < CBEntity
7
+ RESOURCE_LIST = 'competitors'
8
+
9
+ attr_reader :type_name, :name, :last_name, :permalink, :title, :started_on, :ended_on,
10
+ :created_at, :updated_at
11
+
12
+ def initialize(json)
13
+ @type_name = json['type']
14
+ @name = (json['name'] || (json['first_name'] + ' ' + json['last_name']))
15
+ @permalink = (json['permalink'] || (json['path'] || json['path'].gsub('organization/', '')))
16
+ @title = json['title']
17
+ @started_on = json['started_on']
18
+ @ended_on = json['ended_on']
19
+ @created_at = Time.at(json['created_at']).utc
20
+ @updated_at = Time.at(json['updated_at']).utc
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+
3
+ module Crunchbase
4
+ class CrunchException < StandardError
5
+ end
6
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/current_team
4
+
5
+ module Crunchbase
6
+ class CurrentTeam < CBEntity
7
+ RESOURCE_LIST = 'current_team'
8
+
9
+ attr_reader :type_name, :first_name, :last_name, :permalink, :title, :started_on, :ended_on,
10
+ :created_at, :updated_at
11
+
12
+ def initialize(json)
13
+ @type_name = json['type']
14
+ @first_name = json['first_name']
15
+ @last_name = json['last_name']
16
+ @permalink = (json['permalink'] || json['path'].gsub('person/', ''))
17
+ @title = json['title']
18
+ @started_on = json['started_on']
19
+ @ended_on = json['ended_on']
20
+ @created_at = Time.at(json['created_at']).utc
21
+ @updated_at = Time.at(json['updated_at']).utc
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/customers
4
+
5
+ module Crunchbase
6
+ class Customer < CBEntity
7
+ RESOURCE_LIST = 'customers'
8
+
9
+ attr_reader :type_name, :name, :path, :created_at, :updated_at
10
+
11
+ def initialize(json)
12
+ @type_name = json['type']
13
+ @name = json['name']
14
+ @path = json['path']
15
+ @created_at = Time.at(json['created_at']).utc
16
+ @updated_at = Time.at(json['updated_at']).utc
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/founders?user_key=key
4
+
5
+ module Crunchbase
6
+ class Founder < CBEntity
7
+ RESOURCE_LIST = 'founders'
8
+
9
+ attr_reader :type_name, :name, :path, :permalink, :created_at, :updated_at
10
+
11
+ def initialize(json)
12
+ @type_name = json['type']
13
+ @name = json['name']
14
+ @path = json['path']
15
+ @permalink = (json['path'] && json['path'].gsub('person/', ''))
16
+ @created_at = Time.at(json['created_at']).utc
17
+ @updated_at = Time.at(json['updated_at']).utc
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/funding_rounds
4
+
5
+ module Crunchbase
6
+ class FundingRound < CBEntity
7
+ RESOURCE_NAME = 'funding-round'
8
+ RESOURCE_LIST = 'funding_rounds'
9
+
10
+ attr_reader :type_name, :name, :post_money_valuation_currency_code, :permalink, :funding_type,
11
+ :money_raised_usd, :announced_on_trust_code, :money_raised,
12
+ :money_raised_currency_code, :announced_on, :canonical_currency_code,
13
+ :created_at, :updated_at
14
+
15
+ attr_reader :investments, :funded_organizations, :new_items
16
+
17
+ attr_reader :investments_total_items, :funded_organizations_total_items, :new_items_total_items
18
+
19
+ def initialize(json)
20
+ @type_name = json['type']
21
+ properties = json['properties']
22
+ relationships = json['relationships']
23
+
24
+ @name = properties['name']
25
+ @funding_type = properties['funding_type']
26
+ @permalink = properties['permalink']
27
+ @money_raised_usd = properties['money_raised_usd']
28
+ @announced_on = properties['announced_on'] && DateTime.parse(properties['announced_on'])
29
+ @announced_on_trust_code = properties['announced_on_trust_code']
30
+ @canonical_currency_code = properties['canonical_currency_code']
31
+ @money_raised = properties['money_raised']
32
+ @created_at = Time.at(properties['created_at']).utc
33
+ @updated_at = Time.at(properties['updated_at']).utc
34
+ @money_raised_currency_code = properties['money_raised_currency_code']
35
+ @post_money_valuation_currency_code = properties['post_money_valuation_currency_code']
36
+
37
+ @investments_list = relationships['investments']
38
+ @funded_organizations_list = relationships['funded_organization']
39
+ @new_items_list = relationships['news']
40
+ end
41
+
42
+
43
+ def investments
44
+ @investments ||= Investment.array_from_list(@investments_list)
45
+ end
46
+
47
+ def funded_organizations
48
+ @funded_organizations ||= Relationship.array_from_list(@funded_organizations_list)
49
+ end
50
+
51
+ def new_items
52
+ @new_items ||= NewItem.array_from_list(@new_items_list)
53
+ end
54
+
55
+ def investments_total_items
56
+ @investments_total_items ||= Investment.total_items_from_list(@investments_list)
57
+ end
58
+
59
+ def funded_organizations_total_items
60
+ @funded_organizations_total_items ||= Relationship.total_items_from_list(@funded_organizations_list)
61
+ end
62
+
63
+ def new_items_total_items
64
+ @new_items_total_items ||= NewItem.total_items_from_list(@new_items_list)
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/headquarters
4
+
5
+ module Crunchbase
6
+ class Headquarter < CBEntity
7
+ RESOURCE_LIST = 'headquarters'
8
+
9
+ attr_reader :type_name, :name, :street_1, :street_2, :city, :city_uuid, :city_path,
10
+ :region, :country_code, :created_at, :updated_at
11
+
12
+ def initialize(json)
13
+ @type_name = json['type']
14
+ @name = json['name']
15
+ @street_1 = json['street_1']
16
+ @street_2 = json['street_2']
17
+ @city = json['city']
18
+ @city_uuid = json['city_uuid']
19
+ @city_path = json['city_path']
20
+ @region = json['region']
21
+ @country_code = json['country_code']
22
+ @created_at = Time.at(json['created_at']).utc
23
+ @updated_at = Time.at(json['updated_at']).utc
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # encode: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/images
4
+
5
+ module Crunchbase
6
+ class Image < CBEntity
7
+ RESOURCE_NAME = 'image'
8
+ RESOURCE_LIST = 'images'
9
+
10
+ attr_reader :type_name, :title, :path, :original_path, :created_at, :updated_at
11
+
12
+ def initialize(json)
13
+ @type_name = json['type']
14
+ @title = json['title']
15
+ @original_path = json['path']
16
+ @path = Crunchbase::API.image_url + json['path']
17
+ @created_at = Time.at(json['created_at']).utc
18
+ @updated_at = Time.at(json['updated_at']).utc
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/investments
4
+
5
+ module Crunchbase
6
+ class Investment < CBEntity
7
+ RESOURCE_LIST = 'investments'
8
+
9
+ attr_reader :type_name, :money_invested, :money_invested_currency_code,
10
+ :money_invested_usd, :funding_round_path, :invested_in_type,
11
+ :invested_in_name, :invested_in_path
12
+
13
+ def initialize(json)
14
+ @type_name = json['type']
15
+ @money_invested = json['money_invested']
16
+ @money_invested_currency_code = json['money_invested_currency_code']
17
+ @money_invested_usd = json['money_invested_usd']
18
+ @funding_round_path = json['funding_round'] && json['funding_round']['path']
19
+
20
+ if json['invested_in_type']
21
+ @invested_in_type = json['invested_in_type'] && json['invested_in_type']['type']
22
+ @invested_in_name = json['invested_in_type'] && json['invested_in_type']['name']
23
+ @invested_in_path = json['invested_in_type'] && json['invested_in_type']['path']
24
+ elsif json['investor']
25
+ @invested_in_type = json['investor'] && json['investor']['type']
26
+ @invested_in_name = json['investor'] && json['investor']['name']
27
+ @invested_in_path = json['investor'] && json['investor']['path']
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ module Crunchbase
4
+ class Ipo < CBEntity
5
+ RESOURCE_NAME = 'ipo'
6
+ RESOURCE_LIST = 'ipo'
7
+
8
+ attr_reader :type_name, :went_public_on, :went_public_on_trust_code, :canonical_currency_code,
9
+ :money_raised_currency_code, :opening_valuation_currency_code, :stock_symbol,
10
+ :permalink, :name, :opening_valuation_usd, :opening_share_price_usd,
11
+ :stock_exchange_symbol, :shares_outstanding, :shares_sold,
12
+ :opening_share_price_currency_code, :opening_share_price, :money_raised_usd,
13
+ :opening_valuation, :money_raised, :created_at, :updated_at
14
+
15
+ attr_reader :funded_companies
16
+ attr_reader :funded_companies_total_items
17
+
18
+
19
+ def initialize(json)
20
+ properties = json['properties']
21
+ relationships = json['relationships']
22
+
23
+ @type_name = properties['type']
24
+ @name = properties['name']
25
+ @went_public_on = properties['went_public_on']
26
+ @stock_symbol = properties['stock_symbol']
27
+ @permalink = properties['permalink']
28
+ @shares_outstanding = properties['shares_outstanding']
29
+ @shares_sold = properties['shares_sold']
30
+ @opening_share_price = properties['opening_share_price']
31
+ @money_raised_usd = properties['money_raised_usd']
32
+ @opening_valuation = properties['opening_valuation']
33
+ @money_raised = properties['money_raised']
34
+ @created_at = Time.at(properties['created_at']).utc
35
+ @updated_at = Time.at(properties['updated_at']).utc
36
+ @went_public_on_trust_code = properties['went_public_on_trust_code']
37
+ @canonical_currency_code = properties['canonical_currency_code']
38
+ @money_raised_currency_code = properties['money_raised_currency_code']
39
+ @opening_valuation_usd = properties['opening_valuation_usd']
40
+ @opening_share_price_usd = properties['opening_share_price_usd']
41
+ @stock_exchange_symbol = properties['stock_exchange_symbol']
42
+ @opening_valuation_currency_code = properties['opening_valuation_currency_code']
43
+ @opening_share_price_currency_code = properties['opening_share_price_currency_code']
44
+
45
+ @funded_companies_list = relationships['funded_company']
46
+ end
47
+
48
+ def funded_companies
49
+ @funded_companies ||= Relationship.array_from_list(@funded_companies_list)
50
+ end
51
+
52
+ def funded_companies_total_items
53
+ @funded_companies_total_items ||= Relationship.array_from_list(@funded_companies_list)
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module Crunchbase
4
+ class Location < CBEntity
5
+
6
+ RESOURCE_NAME = 'location'
7
+ RESOURCE_LIST = 'locations'
8
+
9
+ attr_reader :location_type, :name, :path, :parent_location_uuid, :uuid,
10
+ :type_name, :created_at, :updated_at
11
+
12
+ def initialize(json)
13
+ @location_type = json['location_type']
14
+ @name = json['name']
15
+ @path = json['path']
16
+ @parent_location_uuid = json['parent_location_uuid']
17
+ @uuid = json['uuid']
18
+ @type_name = json['type_name']
19
+ @created_at = Time.at(json['created_at']).utc
20
+ @updated_at = Time.at(json['updated_at']).utc
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # http://api.crunchbase.com/v/2/organization/facebook/news
4
+
5
+ module Crunchbase
6
+ class NewItem < CBEntity
7
+ RESOURCE_LIST = 'news'
8
+
9
+ attr_reader :type_name, :url, :author, :posted_on, :type, :title, :created_at,
10
+ :updated_at
11
+
12
+ def initialize(json)
13
+ @type_name = json['type']
14
+ @url = json['url']
15
+ @author = json['author']
16
+ @posted_on = json['posted_on'] && DateTime.parse(json['posted_on'])
17
+ @title = json['title']
18
+ @created_at = json['created_at']
19
+ @updated_at = json['updated_at']
20
+ end
21
+ end
22
+ end