1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | $ irb irb(main):001:0> require 'rubygems' => true irb(main):002:0> require 'json' => true irb(main):003:0> require 'net/http' => true irb(main):004:0> uri = "http://api.crunchbase.com/v/1/company/ibm.js" => "http://api.crunchbase.com/v/1/company/ibm.js" irb(main):005:0> resp = Net::HTTP.get_response(URI.parse(uri)) => #<Net::HTTPOK 200 OK readbody=true> irb(main):006:0> puts resp.body {"name": "IBM", "permalink": "ibm", "crunchbase_url": "http://www.crunchbase.com/company/ibm", "homepage_url": "http://www.ibm.com", "blog_url": "", "blog_feed_url": "", "twitter_username": "", "category_code": "software", "number_of_employees": 388000, ... => nil irb(main):007:0> parsedresp = JSON.parse(resp.body) => {"updated_at"=>"Wed Feb 01 03:10:14 UTC 2012", "alias_list"=>nil, ... irb(main):008:0> irb(main):009:0* puts parsedresp['founded_year'] 1896 => nil irb(main):010:0> |
1 | $ sudo apt-get install ruby |
1 | $ sudo apt-get install irb |
1 2 3 | $ sudo apt-get install rubygems1.8 $ sudo apt-get install ruby-dev $ sudo gem install json |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | require 'rubygems' require 'json' require 'net/http' class Crunchbase_Company @record = nil def initialize( company ) base_url = "http://api.crunchbase.com" url = "#{base_url}/v/1/company/#{company}.js" resp = Net::HTTP.get_response(URI.parse(url)) @record = JSON.parse(resp.body) end def founded_year return @record['founded_year'] end def num_employees return @record['number_of_employees'] end def company_type return @record['category_code'] end def people employees = Hash.new relationships = @record['relationships'] if !relationships.nil? relationships.each do | person | if person['is_past'] == false then permalink = person['person']['permalink'] title = person['title'] employees[permalink] = title end end end return employees end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | require 'rubygems' require 'json' require 'net/http' class Crunchbase_Person @record = nil def initialize( person ) base_url = "http://api.crunchbase.com" url = "#{base_url}/v/1/person/#{person}.js" resp = Net::HTTP.get_response(URI.parse(url)) @record = JSON.parse(resp.body) end def fname return @record['first_name'] end def lname return @record['last_name'] end def companies firms = Array.new @record['relationships'].each do | firm | firms << firm['firm']['permalink'] end return firms end end |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |