crunchbase 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75f6513e17d35d263ca659edccd32390cf2e69a8
4
+ data.tar.gz: 21e3fd611e361296911d0ca4dba27b2061852fca
5
+ SHA512:
6
+ metadata.gz: ceb82a4cdd8e27e6ece53db621c3e0b17122a4d60c7f46f9178a84d282e131d17828661eb2c25715651c471a0504e9e9df7c3628f5b4bfe906a1f6458e794613
7
+ data.tar.gz: 04e6e289b6b883676722495abe2406ce0a996e9bf505278a4b67f364d488c40d8d525f1f87e1e5fb172662d24bc27b9d6ff30eb2290720bcdd090ab38bc0201e
data/README.rdoc CHANGED
@@ -36,7 +36,12 @@ the actual data.
36
36
  Searching the Crunchbase is possible with the Search class.
37
37
 
38
38
  s = Crunchbase::Search.find("widgets")
39
-
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
+
40
45
  You can access the search results by treating the returned Search instance as
41
46
  an array.
42
47
 
data/lib/crunchbase.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'crunchbase/api'
2
2
  require 'crunchbase/cb_object'
3
3
  require 'crunchbase/date_methods'
4
+ require 'crunchbase/array_from_list'
5
+ require 'crunchbase/image'
6
+ require 'crunchbase/milestone'
4
7
  require 'crunchbase/company'
5
8
  require 'crunchbase/financial_organization'
6
9
  require 'crunchbase/investment'
@@ -17,5 +20,5 @@ require 'crunchbase/search_result'
17
20
  require 'crunchbase/crunch_exception'
18
21
 
19
22
  module Crunchbase
20
- VERSION = "0.3.0"
23
+ VERSION = "0.4.0"
21
24
  end
@@ -56,6 +56,13 @@ module Crunchbase
56
56
  get_json_response(uri)
57
57
  end
58
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
+
59
66
  # Searches for a permalink in a particular category.
60
67
  def self.permalink(parameters, category)
61
68
  require "cgi"
@@ -0,0 +1,9 @@
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
@@ -9,12 +9,12 @@ module Crunchbase
9
9
 
10
10
  # Returns an array of tags
11
11
  def tags
12
- @tag_list.respond_to?('split') ? @tag_list.split(', ') : []
12
+ @tag_list.respond_to?('split') ? @tag_list.split(/,\s*/) : []
13
13
  end
14
14
 
15
15
  # Returns an array of aliases
16
16
  def aliases
17
- @alias_list.respond_to?('split') ? @alias_list.split(", ") : []
17
+ @alias_list.respond_to?('split') ? @alias_list.split(/,\s*/) : []
18
18
  end
19
19
 
20
20
  # Factory method to return an instance from a permalink
@@ -24,10 +24,14 @@ module Crunchbase
24
24
  return e
25
25
  end
26
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.
27
29
  def self.find(name)
28
30
  get(API.permalink({name: name}, self::ENT_PLURAL)["permalink"])
29
31
  end
30
32
 
33
+ # Requests a list of all entities of a given type. Returns the list as an
34
+ # array of EntityListItems.
31
35
  def self.all
32
36
  all = API.all(self::ENT_PLURAL).map do |ent|
33
37
  ent["namespace"] = self::ENT_NAME
@@ -45,4 +49,4 @@ module Crunchbase
45
49
  end
46
50
 
47
51
  end
48
- end
52
+ end
@@ -11,10 +11,11 @@ module Crunchbase
11
11
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
12
12
  :blog_feed_url, :twitter_username, :category_code, :number_of_employees,
13
13
  :deadpooled_url, :email_address, :phone_number, :description,
14
- :created_at, :updated_at, :overview, :image, :relationships,
15
- :competitions, :providerships, :total_money_raised, :funding_rounds,
16
- :investments, :acquisition, :acquisitions, :offices, :milestones, :ipo,
17
- :video_embeds, :screenshots, :external_links
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
18
19
 
19
20
  def initialize(json)
20
21
  @name = json["name"]
@@ -41,29 +42,54 @@ module Crunchbase
41
42
  @created_at = DateTime.parse(json["created_at"])
42
43
  @updated_at = DateTime.parse(json["updated_at"])
43
44
  @overview = json["overview"]
44
- @image = json["image"]
45
+ @image = Image.create(json["image"])
45
46
  @products_list = json["products"]
46
- @relationships = Relationship.array_from_relationship_list(json["relationships"]) if json["relationships"]
47
+ @relationships_list = json["relationships"]
47
48
  @competitions = json["competitions"]
48
- @providerships = Relationship.array_from_relationship_list(json["providerships"]) if json["providerships"]
49
+ @providerships_list = json["providerships"]
49
50
  @total_money_raised = json["total_money_raised"]
50
51
  @funding_rounds = json["funding_rounds"]
51
- @investments = Investment.array_from_investment_list(json['investments']) if json['investments']
52
+ @investments_list = json['investments']
52
53
  @acquisition = json["acquisition"]
53
54
  @acquisitions = json["acquisitions"]
54
55
  @offices = json["offices"]
55
- @milestones = json["milestones"]
56
+ @milestones_list = json["milestones"]
56
57
  @ipo = json["ipo"]
57
58
  @video_embeds = json["video_embeds"]
58
59
  @screenshots = json["screenshots"]
59
60
  @external_links = json["external_links"]
60
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
61
82
 
62
83
  # Returns the date the company was founded, or nil if not provided.
63
84
  def founded
64
85
  @founded ||= date_from_components(@founded_year, @founded_month, @founded_day)
65
86
  end
66
87
 
88
+ # Returns whether the company has a deadpooled date component
89
+ def deadpooled?
90
+ !!(@deadpooled_year || @deadpooled_month || @deadpooled_day)
91
+ end
92
+
67
93
  # Returns the date the company was deadpooled, or nil if not provided.
68
94
  def deadpooled
69
95
  @deadpooled ||= date_from_components(@deadpooled_year, @deadpooled_month, @deadpooled_day)
@@ -11,8 +11,8 @@ module Crunchbase
11
11
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
12
12
  :blog_feed_url, :twitter_username, :phone_number, :description,
13
13
  :email_address, :number_of_employees, :created_at, :updated_at,
14
- :overview, :image, :offices, :relationships, :investments, :milestones,
15
- :providerships, :funds, :video_embeds, :external_links
14
+ :overview, :image, :offices, :funds, :video_embeds, :external_links,
15
+ :founded_year, :founded_month, :founded_day
16
16
 
17
17
  def initialize(json)
18
18
  @name = json['name']
@@ -34,17 +34,37 @@ module Crunchbase
34
34
  @created_at = DateTime.parse(json["created_at"])
35
35
  @updated_at = DateTime.parse(json["updated_at"])
36
36
  @overview = json['overview']
37
- @image = json['image']
37
+ @image = Image.create(json['image'])
38
38
  @offices = json['offices']
39
- @relationships = Relationship.array_from_relationship_list(json["relationships"]) if json["relationships"]
40
- @investments = Investment.array_from_investment_list(json['investments']) if json['investments']
41
- @milestones = json['milestones']
42
- @providerships = Relationship.array_from_relationship_list(json['providerships']) if json["providerships"]
39
+ @relationships_list = json["relationships"]
40
+ @investments_list = json['investments']
41
+ @milestones_list = json['milestones']
42
+ @providerships_list = json["providerships"]
43
43
  @funds = json['funds']
44
44
  @video_embeds = json['video_embeds']
45
45
  @external_links = json['external_links']
46
46
  end
47
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
+
48
68
  # Returns the date the financial org was founded, or nil if not provided.
49
69
  def founded
50
70
  @founded ||= date_from_components(@founded_year, @founded_month, @founded_day)
@@ -0,0 +1,36 @@
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
@@ -2,15 +2,13 @@ module Crunchbase
2
2
  class Investment
3
3
 
4
4
  include Crunchbase::DateMethods
5
+ self.extend Crunchbase::ArrayFromList
5
6
 
6
7
  attr_reader :funding_round_code, :funding_source_url,
7
8
  :funding_source_description, :raised_amount, :raised_currency_code,
9
+ :funded_year, :funded_month, :funded_day,
8
10
  :company_name, :company_permalink
9
11
 
10
- def self.array_from_investment_list(list)
11
- list.map{|l| self.new(l)}
12
- end
13
-
14
12
  def initialize(hash)
15
13
  hash = hash["funding_round"]
16
14
  @funding_round_code = hash["round_code"]
@@ -32,10 +30,14 @@ module Crunchbase
32
30
  @company = Company.get(@company_permalink)
33
31
  return @company
34
32
  end
33
+
34
+ def funded_date?
35
+ !!(@funded_year || @funded_month || @funded_day)
36
+ end
35
37
 
36
38
  def funded_date
37
39
  @funded_date ||= date_from_components(@funded_year, @funded_month, @funded_day)
38
40
  end
39
41
 
40
42
  end
41
- end
43
+ end
@@ -0,0 +1,33 @@
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
@@ -10,8 +10,8 @@ module Crunchbase
10
10
  attr_reader :first_name, :last_name, :permalink, :crunchbase_url,
11
11
  :homepage_url, :birthplace, :twitter_username, :blog_url, :blog_feed_url,
12
12
  :affiliation_name, :created_at, :updated_at, :overview, :created_at,
13
- :updated_at, :overview, :relationships, :investments, :milestones,
14
- :video_embeds, :external_links, :web_presences
13
+ :updated_at, :image, :video_embeds, :external_links, :web_presences,
14
+ :born_year, :born_month, :born_day
15
15
 
16
16
  def self.find(first_name, last_name)
17
17
  get(API.permalink({first_name: first_name, last_name: last_name}, "people")["permalink"])
@@ -36,15 +36,31 @@ module Crunchbase
36
36
  @created_at = DateTime.parse(json["created_at"])
37
37
  @updated_at = DateTime.parse(json["updated_at"])
38
38
  @overview = json["overview"]
39
-
40
- @relationships = Relationship.array_from_relationship_list(json["relationships"]) if json["relationships"]
41
- @investments = Investment.array_from_investment_list(json["investments"]) if json["investments"]
42
- @milestones = json["milestones"]
39
+ @image = Image.create(json["image"])
40
+ @relationships_list = json["relationships"]
41
+ @investments_list = json["investments"]
42
+ @milestones_list = json["milestones"]
43
43
  @video_embeds = json["video_embeds"]
44
44
  @external_links = json["external_links"]
45
45
  @web_presences = json["web_presences"]
46
46
  end
47
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
+
48
64
  # Returns a date object, or nil if Date cannot be created from
49
65
  # provided information.
50
66
  def born
@@ -9,9 +9,10 @@ module Crunchbase
9
9
 
10
10
  attr_reader :name, :permalink, :crunchbase_url, :homepage_url, :blog_url,
11
11
  :blog_feed_url, :twitter_username, :stage_code, :deadpooled_url,
12
+ :deadpooled_year, :deadpooled_month, :deadpooled_day,
13
+ :launched_year, :launched_month, :launched_day,
12
14
  :invite_share_url, :created_at, :updated_at, :overview, :image,
13
- :company_permalink, :company_name, :milestones, :video_embeds,
14
- :external_links
15
+ :company_permalink, :company_name, :video_embeds, :external_links
15
16
 
16
17
  def initialize(json)
17
18
  @name = json['name']
@@ -35,18 +36,30 @@ module Crunchbase
35
36
  @created_at = DateTime.parse(json['created_at'])
36
37
  @updated_at = DateTime.parse(json['updated_at'])
37
38
  @overview = json['overview']
38
- @image = json['image']
39
+ @image = Image.create(json["image"])
39
40
  @company_permalink = json['company']['permalink']
40
41
  @company_name = json['company']['name']
41
- @milestones = json['milestones']
42
+ @milestones_list = json['milestones']
42
43
  @video_embeds = json['video_embeds']
43
44
  @external_links = json['external_links']
44
45
  end
45
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
+
46
55
  # Returns the date the product was deadpooled, or nil if not provided.
47
56
  def deadpooled
48
57
  @deadpooled ||= date_from_components(@deadpooled_year, @deadpooled_month, @deadpooled_day)
49
58
  end
59
+
60
+ def launched?
61
+ !!(@launched_year || @launched_month || @launched_day)
62
+ end
50
63
 
51
64
  # Returns the date the product was launched, or nil if not provided.
52
65
  def launched
@@ -7,7 +7,7 @@ module Crunchbase
7
7
 
8
8
  # Takes a relationship list (directly from the JSON hash) and returns an
9
9
  # array of instances of Relationship subclasses.
10
- def self.array_from_relationship_list(list)
10
+ def self.array_from_list(list)
11
11
  list.map do |l|
12
12
  if l["person"]
13
13
  PersonRelationship.new(l)
@@ -37,4 +37,4 @@ module Crunchbase
37
37
  @is_past
38
38
  end
39
39
  end
40
- end
40
+ end