Class: Barchart::Quote

Inherits:
Resource show all
Defined in:
lib/barchart/resources/quote.rb

Overview

Instance Attribute Summary

Attributes inherited from Resource

#response_json, #struct

Class Method Summary collapse

Methods inherited from Resource

#as_json, #initialize, initialize_from_array_response, #inspect, #method_missing

Constructor Details

This class inherits a constructor from Barchart::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Barchart::Resource

Class Method Details

.get!(symbols, fields = [:bid,:ask], mode = 'R') ⇒ Object

mode can be R (realtime), I (delayed), D (end-of-day)



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/barchart/resources/quote.rb', line 5

def self.get!(symbols, fields=[:bid,:ask], mode='R')
  fields_query = fields.join(',')

  symbols_query = symbols
  symbols_query = symbols.join(',')  if symbols.is_a?(Array)

  response = Request.get("/getQuote.json?symbols=#{symbols_query}&fields=#{fields_query}")

  return Quote.new(response[:results].first)  if symbols.is_a?(String)
  response[:results].map { |result| Quote.new(result) }
end