Sha256: 726c217dea3d94834686fdffa5156ffd5189a5dbce56bad00860e6a2738da725

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

require 'faraday'
require 'json'
require 'hashie'

module Crunchbase
  class Person

    attr_accessor :metadata

    def initialize(data, meta)
      @mash = data
      self.metadata = meta
    end

    def method_missing(method_sym, *arguments, &block)
      @mash.send(method_sym, *arguments)
    end

    def load_details
      if properties
        return self
      else
        Person.find(path.sub("person/", ''))
      end
    end

    def self.all(options = {})
      opts = options.merge({user_key: Crunchbase.config.user_key})
      response = Faraday.get("#{Crunchbase.config.host}/#{Crunchbase.config.api_version_prefix}/people", opts)

      raise "Error" if response.status != 200

      # ignore paging
      raw = Hashie::Mash.new(JSON.parse(response.body))
      collection = raw.data.items
      collection.map { |item| new(item, raw.metadata) }
    rescue
      []
    end

    def self.find(permalink)
      response = Faraday.get("#{Crunchbase.config.host}/#{Crunchbase.config.api_version_prefix}/person/#{permalink}", user_key: Crunchbase.config.user_key)

      raise "Error" if response.status != 200

      raw = Hashie::Mash.new(JSON.parse(response.body))
      new(raw.data, raw.metadata)
    rescue
      nil
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crunchbase-wrapper-0.0.2 lib/crunchbase/person.rb
crunchbase-wrapper-0.0.1 lib/crunchbase/person.rb