Class: Crunchbase::Product
- Inherits:
-
Object
- Object
- Crunchbase::Product
- Defined in:
- lib/crunchbase/product.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, meta) ⇒ Product
constructor
A new instance of Product.
- #load_details ⇒ Object
- #method_missing(method_sym, *arguments, &block) ⇒ Object
Constructor Details
#initialize(data, meta) ⇒ Product
Returns a new instance of Product.
10 11 12 13 |
# File 'lib/crunchbase/product.rb', line 10 def initialize(data, ) @mash = data self. = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
15 16 17 |
# File 'lib/crunchbase/product.rb', line 15 def method_missing(method_sym, *arguments, &block) @mash.send(method_sym, *arguments) end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/crunchbase/product.rb', line 8 def @metadata end |
Class Method Details
.all(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/crunchbase/product.rb', line 27 def self.all( = {}) opts = .merge({user_key: Crunchbase.config.user_key}) response = Faraday.get("#{Crunchbase.config.host}/#{Crunchbase.config.api_version_prefix}/products", 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.) } rescue [] end |
.find(permalink) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/crunchbase/product.rb', line 41 def self.find(permalink) response = Faraday.get("#{Crunchbase.config.host}/#{Crunchbase.config.api_version_prefix}/product/#{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.) rescue nil end |