crunchbase 0.4.0 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75f6513e17d35d263ca659edccd32390cf2e69a8
4
- data.tar.gz: 21e3fd611e361296911d0ca4dba27b2061852fca
3
+ metadata.gz: ffd5ba31ec023633cda2812127ef906f79caaf4e
4
+ data.tar.gz: 3b79782a2f7727bb8640f3d24c8f2457e6549dc7
5
5
  SHA512:
6
- metadata.gz: ceb82a4cdd8e27e6ece53db621c3e0b17122a4d60c7f46f9178a84d282e131d17828661eb2c25715651c471a0504e9e9df7c3628f5b4bfe906a1f6458e794613
7
- data.tar.gz: 04e6e289b6b883676722495abe2406ce0a996e9bf505278a4b67f364d488c40d8d525f1f87e1e5fb172662d24bc27b9d6ff30eb2290720bcdd090ab38bc0201e
6
+ metadata.gz: 2db47155effd5af3bfcaf98ffe7e59a27ec0fd71159fcc25bfc18974a6e24f9c8b965defbf35aad88b594ec097b06ecfd5f95e1e0a910fc901ba8e6507881db4
7
+ data.tar.gz: aac48f0e8ddc2ec226e76676ec13762ce6f2fae9667263192845ff788c36380b92923d80c685798b0abd6feeaa3ecd6ba6b6b7f9b818f81ff854618ae4a75d4e
@@ -1,89 +1,14 @@
1
1
  = crunchbase
2
2
 
3
- Library for pulling data from the CrunchBase API.
3
+ == EOL
4
4
 
5
- == Dependencies
5
+ Crunchbase has retired the v1 api and I unfortunately do not have the time to
6
+ bring this gem up to date with v2. This project and gem are therefore retired
7
+ as well.
6
8
 
7
- The Crunchbase API is entirely JSON-based. By default, if present, the gem will
8
- use the {YAJL gem}[http://github.com/brianmario/yajl-ruby]; if not, it will
9
- fall back to the {JSON gem}[http://flori.github.com/json/]. Please ensure one
10
- of the two is installed.
9
+ A number of folks have created gems for v2. I have not personally used any of
10
+ them as I don't use Crunchbase for any current projects, but links can be found
11
+ in the Crunchbase developer documentation: https://developer.crunchbase.com/docs
11
12
 
12
- You will need to get an API key from {Crunchbase}[http://developer.crunchbase.com/]
13
-
14
- == Usage
15
-
16
- If you already know the permalink for a given entity, you can grab the entry
17
- with the +get+ method.
18
-
19
- require 'crunchbase'
20
- Crunchbase::API.key = 'your crunchbase api key'
21
- steve = Crunchbase::Person.get("steve-jobs")
22
- facebook = Crunchbase::Company.get("facebook")
23
-
24
- If you know the name of the entity but not the permalink, you can use the
25
- +find+ method.
26
-
27
- steve = Crunchbase::Person.find("Steve", "Jobs")
28
- github = Crunchbase::Company.find("Github")
29
-
30
- Note that finding using a name performs two HTTP requests internally, the first
31
- returning the permalink associated with the name, and the second which returns
32
- the actual data.
33
-
34
- === Search
35
-
36
- Searching the Crunchbase is possible with the Search class.
37
-
38
- s = Crunchbase::Search.find("widgets")
39
-
40
- You can also search by location using the Location class. Searches can be by city,
41
- state, zip, country-code, etc.
42
-
43
- l = Crunchbase::Location.geo("San Francisco")
44
-
45
- You can access the search results by treating the returned Search instance as
46
- an array.
47
-
48
- first_result = s[0]
49
- s.each { |result| puts result.name }
50
-
51
- The Search will return a list consisting of objects of the SearchResult type. To
52
- access the full entity object, call the +entity+ method of the SearchResult.
53
-
54
- While Search does include the Enumerable module, it does not implement all of
55
- the methods of Array. If you need to treat the results as an array in a way not
56
- supported, you can call +to_ary+; this prefetches all result pages (if they have
57
- not already been loaded), so it may entail a slight delay, depending on the
58
- number of results.
59
-
60
- all_results = s.to_ary
61
-
62
- === List all Items
63
-
64
- If you've gone insane and want a list of every single item for a given entity
65
- type, you can do so with the +all+ method.
66
-
67
- all_companies = Company.all
68
- company = all_companies[105]
69
-
70
- This returns an array containing objects representing each entity. Just like
71
- Search, the full item can be grabbed with the +entity+ method. Unlike Search,
72
- however, all of the result objects are fetched at once, so iterating through the
73
- list does not entail a delay every ten items. Of course, the list is enormous
74
- (the list of all companies returns over 84,500 entries as of this writing), so
75
- it's little consolation.
76
-
77
- == Contributing
78
-
79
- Contributions are welcome. Note that in order to run the test suite, you need to
80
- include an API key in +spec/apikey.yml+. This file is ignored by git. An example
81
- file is provided for convenience.
82
-
83
- == Copyright
84
-
85
- Copyright (c) 2011-12 Tyler Cunnion. This software is made available under the
86
- MIT/X11 license. See LICENSE.txt for further details.
87
-
88
- I am not affiliated in any way with AOL, TechCrunch, Crunchbase, or anyone
89
- really.
13
+ Thanks to all who contributed code and apologies for not being able to
14
+ maintain the project further.
@@ -1,24 +1,5 @@
1
- require 'crunchbase/api'
2
- require 'crunchbase/cb_object'
3
- require 'crunchbase/date_methods'
4
- require 'crunchbase/array_from_list'
5
- require 'crunchbase/image'
6
- require 'crunchbase/milestone'
7
- require 'crunchbase/company'
8
- require 'crunchbase/financial_organization'
9
- require 'crunchbase/investment'
10
- require 'crunchbase/person'
11
- require 'crunchbase/product'
12
- require 'crunchbase/service_provider'
13
- require 'crunchbase/relationship'
14
- require 'crunchbase/relationships/firm_relationship'
15
- require 'crunchbase/relationships/person_relationship'
16
- require 'crunchbase/relationships/provider_relationship'
17
- require 'crunchbase/entity_list_item'
18
- require 'crunchbase/search'
19
- require 'crunchbase/search_result'
20
- require 'crunchbase/crunch_exception'
21
-
22
1
  module Crunchbase
23
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
24
3
  end
4
+
5
+ raise ScriptError.new("crunchbase gem not compatible with current api, please change to a new gem with api v2 support")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crunchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Cunnion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: tyler.cunnion@gmail.com
@@ -18,29 +18,9 @@ extra_rdoc_files:
18
18
  - LICENSE.txt
19
19
  - README.rdoc
20
20
  files:
21
- - lib/crunchbase/api.rb
22
- - lib/crunchbase/array_from_list.rb
23
- - lib/crunchbase/cb_object.rb
24
- - lib/crunchbase/company.rb
25
- - lib/crunchbase/crunch_exception.rb
26
- - lib/crunchbase/date_methods.rb
27
- - lib/crunchbase/entity_list_item.rb
28
- - lib/crunchbase/financial_organization.rb
29
- - lib/crunchbase/image.rb
30
- - lib/crunchbase/investment.rb
31
- - lib/crunchbase/milestone.rb
32
- - lib/crunchbase/person.rb
33
- - lib/crunchbase/product.rb
34
- - lib/crunchbase/relationship.rb
35
- - lib/crunchbase/relationships/firm_relationship.rb
36
- - lib/crunchbase/relationships/person_relationship.rb
37
- - lib/crunchbase/relationships/provider_relationship.rb
38
- - lib/crunchbase/search.rb
39
- - lib/crunchbase/search_result.rb
40
- - lib/crunchbase/service_provider.rb
41
- - lib/crunchbase.rb
42
21
  - LICENSE.txt
43
22
  - README.rdoc
23
+ - lib/crunchbase.rb
44
24
  homepage: http://github.com/tylercunnion/crunchbase
45
25
  licenses:
46
26
  - MIT
@@ -51,18 +31,19 @@ require_paths:
51
31
  - lib
52
32
  required_ruby_version: !ruby/object:Gem::Requirement
53
33
  requirements:
54
- - - '>='
34
+ - - ">="
55
35
  - !ruby/object:Gem::Version
56
36
  version: '0'
57
37
  required_rubygems_version: !ruby/object:Gem::Requirement
58
38
  requirements:
59
- - - '>='
39
+ - - ">="
60
40
  - !ruby/object:Gem::Version
61
41
  version: '0'
62
42
  requirements: []
63
43
  rubyforge_project:
64
- rubygems_version: 2.0.14
44
+ rubygems_version: 2.4.2
65
45
  signing_key:
66
46
  specification_version: 4
67
47
  summary: Ruby wrapper for CrunchBase API
68
48
  test_files: []
49
+ has_rdoc:
@@ -1,107 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'net/http'
3
-
4
- begin
5
- require 'yajl'
6
- rescue LoadError
7
- require 'json'
8
- end
9
-
10
- require 'timeout'
11
-
12
- module Crunchbase
13
-
14
- # Handles the actual calls to the Crunchbase API through a series of class
15
- # methods, each referring to a CB entity type. Each method returns the raw
16
- # JSON returned from the API. You should probably be using the factory
17
- # methods provided on each entity class instead of calling these directly.
18
- class API
19
- CB_URL = 'http://api.crunchbase.com/v/1/'
20
- SUPPORTED_ENTITIES = ['person', 'company', 'financial-organization', 'product', 'service-provider']
21
- @timeout_limit = 60
22
- @redirect_limit = 2
23
- class << self; attr_accessor :timeout_limit, :redirect_limit, :key end
24
-
25
- def self.single_entity(permalink, entity_name)
26
- raise CrunchException, "Unsupported Entity Type" unless SUPPORTED_ENTITIES.include?(entity_name)
27
- fetch(permalink, entity_name)
28
- end
29
-
30
- def self.all(entity)
31
- uri = CB_URL + entity + ".js"
32
- get_json_response(uri)
33
- end
34
-
35
- private
36
-
37
- # Returns the JSON parser, whether that's an instance of Yajl or JSON
38
- def self.parser
39
- if defined?(Yajl)
40
- Yajl::Parser
41
- else
42
- JSON
43
- end
44
- end
45
-
46
- # Fetches URI for the permalink interface.
47
- def self.fetch(permalink, object_name)
48
- uri = CB_URL + "#{object_name}/#{permalink}.js"
49
- get_json_response(uri)
50
- end
51
-
52
- # Fetches URI for the search interface.
53
- def self.search(query, page=1)
54
- require "cgi"
55
- uri = CB_URL + "search.js?query=#{CGI.escape(query)}&page=#{page}"
56
- get_json_response(uri)
57
- end
58
-
59
- # Fetches URI for geographic search interface
60
- def self.geo(query, page=1)
61
- require "cgi"
62
- uri = CB_URL + "search.js?geo=#{CGI.escape(query)}&page=#{page}"
63
- get_json_response(uri)
64
- end
65
-
66
- # Searches for a permalink in a particular category.
67
- def self.permalink(parameters, category)
68
- require "cgi"
69
- qs = parameters.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join('&')
70
- uri = CB_URL + "#{category}/permalink?#{qs}"
71
- get_json_response(uri)
72
- end
73
-
74
- # Gets specified URI, then parses the returned JSON. Raises Timeout error
75
- # if request time exceeds set limit. Raises CrunchException if returned
76
- # JSON contains an error.
77
- def self.get_json_response(uri)
78
- raise CrunchException, "API key required, visit http://developer.crunchbase.com" unless @key
79
- uri = uri + "#{uri.match('\?') ? "&" : "?"}api_key=#{@key}"
80
- resp = Timeout::timeout(@timeout_limit) {
81
- get_url_following_redirects(uri, @redirect_limit)
82
- }
83
- resp = resp.gsub(/[[:cntrl:]]/, '')
84
- j = parser.parse(resp)
85
- raise CrunchException, j["error"] if j.class == Hash && j["error"]
86
- j
87
- end
88
-
89
- # Performs actual HTTP requests, recursively if a redirect response is
90
- # encountered. Will raise HTTP error if response is not 200, 404, or 3xx.
91
- def self.get_url_following_redirects(uri_str, limit = 10)
92
- raise CrunchException, 'HTTP redirect too deep' if limit == 0
93
-
94
- url = URI.parse(uri_str)
95
- response = Net::HTTP.start(url.host, url.port) { |http| http.get(url.request_uri) }
96
- case response
97
- when Net::HTTPSuccess, Net::HTTPNotFound
98
- response.body
99
- when Net::HTTPRedirection
100
- get_url_following_redirects(response['location'], limit - 1)
101
- else
102
- response.error!
103
- end
104
- end
105
-
106
- end
107
- end
@@ -1,9 +0,0 @@
1
- module Crunchbase
2
- module ArrayFromList
3
- # Takes a list (directly from the JSON hash) and returns an
4
- # array of instances of the class
5
- def array_from_list(list)
6
- list.map {|l| self.new(l) }
7
- end
8
- end
9
- end
@@ -1,52 +0,0 @@
1
- module Crunchbase
2
-
3
- # Represents any object which can be pulled directly from the CB API.
4
- class CB_Object
5
-
6
- # Must be overridden in subclasses
7
- ENT_NAME = "undefined"
8
- ENT_PLURAL = "undefineds"
9
-
10
- # Returns an array of tags
11
- def tags
12
- @tag_list.respond_to?('split') ? @tag_list.split(/,\s*/) : []
13
- end
14
-
15
- # Returns an array of aliases
16
- def aliases
17
- @alias_list.respond_to?('split') ? @alias_list.split(/,\s*/) : []
18
- end
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
- # Finds an entity by its name. Uses two HTTP requests; one to find the
28
- # permalink, and another to request the actual entity.
29
- def self.find(name)
30
- get(API.permalink({name: name}, self::ENT_PLURAL)["permalink"])
31
- end
32
-
33
- # Requests a list of all entities of a given type. Returns the list as an
34
- # array of EntityListItems.
35
- def self.all
36
- all = API.all(self::ENT_PLURAL).map do |ent|
37
- ent["namespace"] = self::ENT_NAME
38
- EntityListItem.new(ent)
39
- end
40
- end
41
-
42
-
43
- # Compares two objects, returning true if they have the same permalink
44
- # (ie, represent the same entity). If you must ensure that the two objects
45
- # also contain the same data, you should also compare the updated_at
46
- # attributes.
47
- def ===(other)
48
- @permalink == other.permalink
49
- end
50
-
51
- end
52
- end
@@ -1,104 +0,0 @@
1
- require 'date'
2
- module Crunchbase
3
- # Represents a Company listed in the Crunchbase.
4
- class Company < CB_Object
5
-
6
- ENT_NAME = "company"
7
- ENT_PLURAL = "companies"
8
-
9
- include Crunchbase::DateMethods
10
-
11
- attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
12
- :blog_feed_url, :twitter_username, :category_code, :number_of_employees,
13
- :deadpooled_url, :email_address, :phone_number, :description,
14
- :created_at, :updated_at, :overview, :image, :competitions,
15
- :total_money_raised, :funding_rounds, :acquisition, :acquisitions,
16
- :offices, :ipo, :video_embeds, :screenshots, :external_links,
17
- :deadpooled_year, :deadpooled_month, :deadpooled_day,
18
- :founded_year, :founded_month, :founded_day
19
-
20
- def initialize(json)
21
- @name = json["name"]
22
- @permalink = json["permalink"]
23
- @crunchbase_url = json["crunchbase_url"]
24
- @homepage_url = json["homepage_url"]
25
- @blog_url = json["blog_url"]
26
- @blog_feed_url = json["blog_feed_url"]
27
- @twitter_username = json["twitter_username"]
28
- @category_code = json["category_code"]
29
- @number_of_employees = json["number_of_employees"]
30
- @founded_year = json["founded_year"]
31
- @founded_month = json["founded_month"]
32
- @founded_day = json["founded_day"]
33
- @deadpooled_year = json["deadpooled_year"]
34
- @deadpooled_month = json["deadpooled_month"]
35
- @deadpooled_day = json["deadpooled_day"]
36
- @deadpooled_url = json["deadpooled_url"]
37
- @tag_list = json["tag_list"]
38
- @alias_list = json["alias_list"]
39
- @email_address = json["email_address"]
40
- @phone_number = json["phone_number"]
41
- @description = json["description"]
42
- @created_at = DateTime.parse(json["created_at"])
43
- @updated_at = DateTime.parse(json["updated_at"])
44
- @overview = json["overview"]
45
- @image = Image.create(json["image"])
46
- @products_list = json["products"]
47
- @relationships_list = json["relationships"]
48
- @competitions = json["competitions"]
49
- @providerships_list = json["providerships"]
50
- @total_money_raised = json["total_money_raised"]
51
- @funding_rounds = json["funding_rounds"]
52
- @investments_list = json['investments']
53
- @acquisition = json["acquisition"]
54
- @acquisitions = json["acquisitions"]
55
- @offices = json["offices"]
56
- @milestones_list = json["milestones"]
57
- @ipo = json["ipo"]
58
- @video_embeds = json["video_embeds"]
59
- @screenshots = json["screenshots"]
60
- @external_links = json["external_links"]
61
- end
62
-
63
- def relationships
64
- @relationships ||= Relationship.array_from_list(@relationships_list)
65
- end
66
-
67
- def providerships
68
- @providerships ||= Relationship.array_from_list(@providerships_list)
69
- end
70
-
71
- def investments
72
- @investments ||= Investment.array_from_list(@investments_list)
73
- end
74
-
75
- def milestones
76
- @milestones ||= Milestone.array_from_list(@milestones_list)
77
- end
78
-
79
- def founded?
80
- !!(@founded_year || @founded_month || @founded_day)
81
- end
82
-
83
- # Returns the date the company was founded, or nil if not provided.
84
- def founded
85
- @founded ||= date_from_components(@founded_year, @founded_month, @founded_day)
86
- end
87
-
88
- # Returns whether the company has a deadpooled date component
89
- def deadpooled?
90
- !!(@deadpooled_year || @deadpooled_month || @deadpooled_day)
91
- end
92
-
93
- # Returns the date the company was deadpooled, or nil if not provided.
94
- def deadpooled
95
- @deadpooled ||= date_from_components(@deadpooled_year, @deadpooled_month, @deadpooled_day)
96
- end
97
-
98
- # Returns an array of Product objects, representing this Company's products.
99
- def products
100
- @products ||= @products_list.map {|p| Product.get(p['permalink']) }
101
- end
102
-
103
- end
104
- end
@@ -1,4 +0,0 @@
1
- module Crunchbase
2
- class CrunchException < StandardError
3
- end
4
- end
@@ -1,15 +0,0 @@
1
- module Crunchbase
2
- module DateMethods
3
-
4
- # Constructs a Date object from year, month, day, returns nil if it fails
5
- def date_from_components(year, month, day)
6
- begin
7
- date = Date.new(year, month, day)
8
- rescue
9
- date = nil
10
- end
11
- date
12
- end
13
-
14
- end
15
- end
@@ -1,59 +0,0 @@
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
@@ -1,73 +0,0 @@
1
- require 'date'
2
- module Crunchbase
3
- # Represents a Financial Organization listed in the Crunchbase.
4
- class FinancialOrganization < CB_Object
5
-
6
- ENT_NAME = "financial-organization"
7
- ENT_PLURAL = "financial-organizations"
8
-
9
- include Crunchbase::DateMethods
10
-
11
- attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
12
- :blog_feed_url, :twitter_username, :phone_number, :description,
13
- :email_address, :number_of_employees, :created_at, :updated_at,
14
- :overview, :image, :offices, :funds, :video_embeds, :external_links,
15
- :founded_year, :founded_month, :founded_day
16
-
17
- def initialize(json)
18
- @name = json['name']
19
- @permalink = json['permalink']
20
- @crunchbase_url = json['crunchbase_url']
21
- @homepage_url = json['homepage_url']
22
- @blog_url = json['blog_url']
23
- @blog_feed_url = json['blog_feed_url']
24
- @twitter_username = json['twitter_username']
25
- @phone_number = json['phone_number']
26
- @description = json['description']
27
- @email_address = json['email_address']
28
- @number_of_employees = json['number_of_employees']
29
- @founded_year = json['founded_year']
30
- @founded_month = json['founded_month']
31
- @founded_day = json['founded_day']
32
- @tag_list = json['tag_list']
33
- @alias_list = json['alias_list']
34
- @created_at = DateTime.parse(json["created_at"])
35
- @updated_at = DateTime.parse(json["updated_at"])
36
- @overview = json['overview']
37
- @image = Image.create(json['image'])
38
- @offices = json['offices']
39
- @relationships_list = json["relationships"]
40
- @investments_list = json['investments']
41
- @milestones_list = json['milestones']
42
- @providerships_list = json["providerships"]
43
- @funds = json['funds']
44
- @video_embeds = json['video_embeds']
45
- @external_links = json['external_links']
46
- end
47
-
48
- def relationships
49
- @relationships ||= Relationship.array_from_list(@relationships_list)
50
- end
51
-
52
- def providerships
53
- @providerships ||= Relationship.array_from_list(@providerships_list)
54
- end
55
-
56
- def investments
57
- @investments ||= Investment.array_from_list(@investments_list)
58
- end
59
-
60
- def milestones
61
- @milestones ||= Milestone.array_from_list(@milestones_list)
62
- end
63
-
64
- def founded?
65
- !!(@founded_year || @founded_month || @founded_day)
66
- end
67
-
68
- # Returns the date the financial org was founded, or nil if not provided.
69
- def founded
70
- @founded ||= date_from_components(@founded_year, @founded_month, @founded_day)
71
- end
72
- end
73
- end
@@ -1,36 +0,0 @@
1
- module Crunchbase
2
- class Image
3
-
4
- def self.create(hash)
5
- hash ? self.new(hash) : nil
6
- end
7
-
8
- attr_reader :attribution, :sizes
9
-
10
- def initialize(hash)
11
- return nil unless hash
12
- @attribution = hash['attribution']
13
- @sizes = hash['available_sizes'].map{|s| ImageSize.new(s)}.sort
14
- end
15
- end
16
-
17
- class ImageSize
18
- include Comparable
19
-
20
- attr_reader :height, :width, :url
21
-
22
- def <=>(anOther)
23
- pixels <=> anOther.pixels
24
- end
25
-
26
- def initialize(ary)
27
- @width = ary[0][0]
28
- @height = ary[0][1]
29
- @url = ary[1]
30
- end
31
-
32
- def pixels
33
- return @width * @height
34
- end
35
- end
36
- end
@@ -1,43 +0,0 @@
1
- module Crunchbase
2
- class Investment
3
-
4
- include Crunchbase::DateMethods
5
- self.extend Crunchbase::ArrayFromList
6
-
7
- attr_reader :funding_round_code, :funding_source_url,
8
- :funding_source_description, :raised_amount, :raised_currency_code,
9
- :funded_year, :funded_month, :funded_day,
10
- :company_name, :company_permalink
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
- !!(@funded_year || @funded_month || @funded_day)
36
- end
37
-
38
- def funded_date
39
- @funded_date ||= date_from_components(@funded_year, @funded_month, @funded_day)
40
- end
41
-
42
- end
43
- end
@@ -1,33 +0,0 @@
1
- module Crunchbase
2
- class Milestone
3
- attr_reader :description, :source_url, :source_text,
4
- :source_description, :stoneable_type, :stoned_value,
5
- :stoned_value_type, :stoned_acquirer,
6
- :stoned_year, :stoned_month, :stoned_year
7
-
8
- include Crunchbase::DateMethods
9
- self.extend Crunchbase::ArrayFromList
10
-
11
- def initialize(obj)
12
- @description = obj['description']
13
- @stoned_year = obj['stoned_year']
14
- @stoned_month = obj['stoned_month']
15
- @stoned_day = obj['stoned_day']
16
- @source_url = obj['source_url']
17
- @source_text = obj['source_text']
18
- @source_description = obj['source_description']
19
- @stoneable_type = obj['stoneable_type']
20
- @stoned_value = obj['stoned_value']
21
- @stoned_value_type = obj['stoned_value_type']
22
- @stoned_acquirer = obj['stoned_acquirer']
23
- end
24
-
25
- def date?
26
- !!(@stoned_year || @stoned_month || @stoned_day)
27
- end
28
-
29
- def date
30
- @date ||= date_from_components(@stoned_year, @stoned_month, @stoned_day)
31
- end
32
- end
33
- end
@@ -1,71 +0,0 @@
1
- require 'date'
2
- module Crunchbase
3
- class Person < CB_Object
4
-
5
- ENT_NAME = "person"
6
- ENT_PLURAL = "people"
7
-
8
- include Crunchbase::DateMethods
9
-
10
- attr_reader :first_name, :last_name, :permalink, :crunchbase_url,
11
- :homepage_url, :birthplace, :twitter_username, :blog_url, :blog_feed_url,
12
- :affiliation_name, :created_at, :updated_at, :overview, :created_at,
13
- :updated_at, :image, :video_embeds, :external_links, :web_presences,
14
- :born_year, :born_month, :born_day
15
-
16
- def self.find(first_name, last_name)
17
- get(API.permalink({first_name: first_name, last_name: last_name}, "people")["permalink"])
18
- end
19
-
20
- def initialize(json)
21
- @first_name = json["first_name"]
22
- @last_name = json["last_name"]
23
- @permalink = json["permalink"]
24
- @crunchbase_url = json["crunchbase_url"]
25
- @homepage_url = json["homepage_url"]
26
- @birthplace = json["birthplace"]
27
- @twitter_username = json["twitter_username"]
28
- @blog_url = json["blog_url"]
29
- @blog_feed_url = json["blog_feed_url"]
30
- @affiliation_name = json["affiliation_name"]
31
- @born_year = json["born_year"]
32
- @born_month = json["born_month"]
33
- @born_day = json["born_day"]
34
- @tag_list = json["tag_list"]
35
- @alias_list = json["alias_list"]
36
- @created_at = DateTime.parse(json["created_at"])
37
- @updated_at = DateTime.parse(json["updated_at"])
38
- @overview = json["overview"]
39
- @image = Image.create(json["image"])
40
- @relationships_list = json["relationships"]
41
- @investments_list = json["investments"]
42
- @milestones_list = json["milestones"]
43
- @video_embeds = json["video_embeds"]
44
- @external_links = json["external_links"]
45
- @web_presences = json["web_presences"]
46
- end
47
-
48
- def relationships
49
- @relationships ||= Relationship.array_from_list(@relationships_list)
50
- end
51
-
52
- def investments
53
- @investments ||= Investment.array_from_list(@investments_list)
54
- end
55
-
56
- def milestones
57
- @milestones ||= Milestone.array_from_list(@milestones_list)
58
- end
59
-
60
- def born?
61
- !!(@born_year || @born_month || @born_day)
62
- end
63
-
64
- # Returns a date object, or nil if Date cannot be created from
65
- # provided information.
66
- def born
67
- @born ||= date_from_components(@born_year, @born_month, @born_day)
68
- end
69
-
70
- end
71
- end
@@ -1,77 +0,0 @@
1
- require 'date'
2
- module Crunchbase
3
- class Product < CB_Object
4
-
5
- ENT_NAME = "product"
6
- ENT_PLURAL = "products"
7
-
8
- include Crunchbase::DateMethods
9
-
10
- attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
11
- :blog_feed_url, :twitter_username, :stage_code, :deadpooled_url,
12
- :deadpooled_year, :deadpooled_month, :deadpooled_day,
13
- :launched_year, :launched_month, :launched_day,
14
- :invite_share_url, :created_at, :updated_at, :overview, :image,
15
- :company_permalink, :company_name, :video_embeds, :external_links
16
-
17
- def initialize(json)
18
- @name = json['name']
19
- @permalink = json['permalink']
20
- @crunchbase_url = json['crunchbase_url']
21
- @homepage_url = json['homepage_url']
22
- @blog_url = json['blog_url']
23
- @blog_feed_url = json['blog_feed_url']
24
- @twitter_username = json['twitter_username']
25
- @stage_code = json['stage_code']
26
- @deadpooled_url = json['deadpooled_url']
27
- @invite_share_url = json['invite_share_url']
28
- @tag_list = json['tag_list']
29
- @alias_list = json['alias_list']
30
- @deadpooled_year = json['deadpooled_year']
31
- @deadpooled_month = json['deadpooled_month']
32
- @deadpooled_day = json['deadpooled_day']
33
- @launched_year = json['launched_year']
34
- @launched_month = json['launched_month']
35
- @launched_day = json['launched_day']
36
- @created_at = DateTime.parse(json['created_at'])
37
- @updated_at = DateTime.parse(json['updated_at'])
38
- @overview = json['overview']
39
- @image = Image.create(json["image"])
40
- @company_permalink = json['company']['permalink']
41
- @company_name = json['company']['name']
42
- @milestones_list = json['milestones']
43
- @video_embeds = json['video_embeds']
44
- @external_links = json['external_links']
45
- end
46
-
47
- def milestones
48
- @milestones ||= Milestone.array_from_list(@milestones_list)
49
- end
50
-
51
- def deadpooled?
52
- !!(@deadpooled_year || @deadpooled_month || @deadpooled_day)
53
- end
54
-
55
- # Returns the date the product was deadpooled, or nil if not provided.
56
- def deadpooled
57
- @deadpooled ||= date_from_components(@deadpooled_year, @deadpooled_month, @deadpooled_day)
58
- end
59
-
60
- def launched?
61
- !!(@launched_year || @launched_month || @launched_day)
62
- end
63
-
64
- # Returns the date the product was launched, or nil if not provided.
65
- def launched
66
- @launched ||= date_from_components(@launched_year, @launched_month, @launched_day)
67
- end
68
-
69
- # Lazy-loads the associated Company entity and caches it. Pass true to
70
- # force reload.
71
- def company(force_reload = false)
72
- return @company unless @company.nil? or force_reload
73
- @company = Company.get(@company_permalink)
74
- return @company
75
- end
76
- end
77
- end
@@ -1,40 +0,0 @@
1
- module Crunchbase
2
- # Superclass for all relationships. Used for both the relationships and
3
- # providerships arrays on retrieved objects.
4
- class Relationship
5
-
6
- attr_reader :title
7
-
8
- # Takes a relationship list (directly from the JSON hash) and returns an
9
- # array of instances of Relationship subclasses.
10
- def self.array_from_list(list)
11
- list.map do |l|
12
- if l["person"]
13
- PersonRelationship.new(l)
14
- elsif l["firm"]
15
- FirmRelationship.new(l)
16
- elsif l["provider"]
17
- ProviderRelationship.new(l)
18
- else
19
- # "Relationship type not recognized"
20
- # TODO: Figure out how to log this
21
- next
22
- end
23
- end
24
- end
25
-
26
- def initialize(hash)
27
- @is_past = hash["is_past"]
28
- @title = hash["title"]
29
- end
30
-
31
- # Convenience method, returns opposite of is_past?
32
- def current?
33
- !@is_past
34
- end
35
-
36
- def is_past?
37
- @is_past
38
- end
39
- end
40
- end
@@ -1,33 +0,0 @@
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 #:nodoc:
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
- FinancialOrganization.get(@firm_permalink)
26
- else
27
- raise CrunchException, "Not implemented"
28
- end
29
- return @firm
30
- end
31
-
32
- end
33
- end
@@ -1,25 +0,0 @@
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 #:nodoc:
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
@@ -1,24 +0,0 @@
1
- module Crunchbase
2
- class ProviderRelationship < Relationship
3
-
4
- attr_reader :provider_name, :provider_permalink
5
-
6
- def self.array_from_relationship_list #:nodoc:
7
- raise CrunchException, "Method must be called from superclass Relationship"
8
- end
9
-
10
- def initialize(hash)
11
- super(hash)
12
- @provider_name = hash["provider"]["name"]
13
- @provider_permalink = hash["provider"]["permalink"]
14
- end
15
-
16
- # Returns a representation of the associated person, loading from memory
17
- # if previously fetched, unless force_reload is set to true.
18
- def provider(force_reload=false)
19
- return @provider unless @provider.nil? || force_reload
20
- @provider = ServiceProvider.get(@provider_permalink)
21
- end
22
-
23
- end
24
- end
@@ -1,124 +0,0 @@
1
- module Crunchbase
2
-
3
- # The Search class provides access to the Crunchbase search API. To perform a
4
- # search, call the find class method, which returns an object of the Search
5
- # class. This object represents an array of SearchResult objects, which may
6
- # be addressed in a way analogous to an Array. These results are loaded on
7
- # demand, in line with the CB API which returns results in pages of 10. When
8
- # requesting a result index that has not been loaded yet, a new request is
9
- # made to fetch it, resulting in a small delay. The class implements the
10
- # Enumerable module, allowing usage of +map+, +select+, etc. If this is not
11
- # sufficient, and full access to the underlying array is required, you may
12
- # call to_ary, which will return the entire array including all results. If
13
- # not all results have been fetched yet, there will be a delay to retrieve
14
- # them, so consider this if your search contains a large number of results.
15
- class Search
16
- include Enumerable
17
-
18
- attr_reader :size, :crunchbase_url
19
- alias :length :size
20
-
21
- # Performs a Crunchbase search for query.
22
- def self.find(query)
23
- j = API.search(query)
24
- s = Search.new(query, j)
25
- end
26
-
27
- def initialize(query, json)
28
- @query = query
29
- @results = []
30
- @size = json["total"]
31
- @crunchbase_url = json["crunchbase_url"]
32
- populate_results(json)
33
- end
34
-
35
- def [](*args)
36
- case args.length
37
- when 1
38
- key = args[0]
39
- if key.kind_of?(Integer)
40
- get_single_key(key)
41
- elsif key.kind_of?(Range)
42
- get_range(key)
43
- end
44
- when 2
45
- start = args[0]
46
- length = args[1]
47
- start = @size + start if start < 0
48
- get_range(start..start+length-1)
49
- end
50
- end
51
-
52
- # Returns array of all search results (not just ones currently loaded.)
53
- # This enables the user to take advantage of all Array methods, not just
54
- # the ones implmented on Search.
55
- def to_ary
56
- self.map{|result| result}
57
- end
58
-
59
- # Calls _block_ once for each search result, passing that item as a
60
- # parameter.
61
- def each(&block) # :yields: result
62
- 0.upto(@size - 1) {|x| yield self[x]}
63
- end
64
-
65
- private
66
-
67
- # Inserts items into the results array from the retrieved search page
68
- def populate_results(json)
69
- page = json["page"]
70
- results = json["results"].map{|r| SearchResult.new(r)}
71
- start = (page - 1) * 10
72
- @results[start, results.length] = results
73
- end
74
-
75
- # Retrieves the search page containing the given index
76
- def retrieve_for_index(index)
77
- page = (index / 10) + 1
78
- populate_results(API.search(@query, page))
79
- end
80
-
81
- # Given one integer key, returns the indexed object from results
82
- def get_single_key(key)
83
- key = @size+key if key < 0
84
- r = @results[key]
85
- unless r.nil? && key < @size
86
- r
87
- else
88
- retrieve_for_index(key)
89
- @results[key]
90
- end
91
- end
92
-
93
- # Given a range, returns the array slice of results indicated
94
- def get_range(range)
95
- r = []
96
- enum = range.to_enum
97
- begin
98
- while (x = enum.next) < @size
99
- r << get_single_key(x)
100
- end
101
- rescue StopIteration
102
- end
103
- r.empty? ? nil : r
104
- end
105
-
106
- end
107
-
108
- class Location < Search
109
-
110
- # Performs a Crunchbase geo-location search for query.
111
- def self.geo(query)
112
- j = API.geo(query)
113
- s = Location.new(query, j)
114
- end
115
-
116
- # Retrieves the search page containing the given index
117
- def retrieve_for_index(index)
118
- page = (index / 10) + 1
119
- populate_results(API.geo(@query, page))
120
- end
121
-
122
- end
123
-
124
- end
@@ -1,16 +0,0 @@
1
- module Crunchbase
2
- # Represents a single search result arising from a Search. The information
3
- # returned from a search includes the name, namespace (i.e. entity type),
4
- # permalink, and an overview. You may also choose to retrieve the full
5
- # entity with the entity method.
6
- class SearchResult < EntityListItem
7
- attr_reader :crunchbase_url, :overview
8
-
9
- def initialize(json)
10
- super
11
- @crunchbase_url = json["crunchbase_url"]
12
- @overview = json["overview"]
13
- end
14
-
15
- end
16
- end
@@ -1,34 +0,0 @@
1
- require 'date'
2
- module Crunchbase
3
- class ServiceProvider < CB_Object
4
-
5
- ENT_NAME = "service-provider"
6
- ENT_PLURAL = "service-providers"
7
-
8
- attr_reader :name, :permalink, :crunchbase_url, :homepage_url,
9
- :phone_number, :created_at, :updated_at, :overview, :image, :offices,
10
- :external_links
11
-
12
- def initialize(json)
13
- @name = json["name"]
14
- @permalink = json["permalink"]
15
- @crunchbase_url = json["crunchbase_url"]
16
- @homepage_url = json["homepage_url"]
17
- @phone_number = json["phone_number"]
18
- @tag_list = json["tag_list"]
19
- @alias_list = json["alias_list"]
20
- @created_at = DateTime.parse(json["created_at"])
21
- @updated_at = DateTime.parse(json["updated_at"])
22
- @overview = json["overview"]
23
- @image = Image.create(json["image"])
24
- @offices = json["offices"]
25
- @providerships_list = json["providerships"]
26
- @external_links = json["external_links"]
27
- end
28
-
29
- def providerships
30
- @providerships ||= Relationship.array_from_list(@providerships_list)
31
- end
32
-
33
- end
34
- end