Class: Accern::Alpha
- Inherits:
-
Object
- Object
- Accern::Alpha
- Defined in:
- lib/accern/alpha.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#docs ⇒ Object
readonly
Returns the value of attribute docs.
-
#flat ⇒ Object
readonly
Returns the value of attribute flat.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#last_id ⇒ Object
readonly
Returns the value of attribute last_id.
-
#new_id ⇒ Object
readonly
Returns the value of attribute new_id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#ticker ⇒ Object
readonly
Returns the value of attribute ticker.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #create_uri ⇒ Object
- #download(path) ⇒ Object
- #download_loop(path: nil) ⇒ Object
-
#initialize(token: nil, ticker: nil, index: nil, format: :json) ⇒ Alpha
constructor
A new instance of Alpha.
Constructor Details
#initialize(token: nil, ticker: nil, index: nil, format: :json) ⇒ Alpha
Returns a new instance of Alpha.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/accern/alpha.rb', line 8 def initialize(token: nil, ticker: nil, index: nil, format: :json) @token = token @ticker = ticker @index = index @format = format @params = params @base_url = 'https://feed.accern.com/v3/alphas' @uri = URI(base_url) read_last_id @flat = Flatner.new end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def base_url @base_url end |
#docs ⇒ Object (readonly)
Returns the value of attribute docs.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def docs @docs end |
#flat ⇒ Object (readonly)
Returns the value of attribute flat.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def flat @flat end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def format @format end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def index @index end |
#last_id ⇒ Object (readonly)
Returns the value of attribute last_id.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def last_id @last_id end |
#new_id ⇒ Object (readonly)
Returns the value of attribute new_id.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def new_id @new_id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def params @params end |
#ticker ⇒ Object (readonly)
Returns the value of attribute ticker.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def ticker @ticker end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def token @token end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/accern/alpha.rb', line 5 def uri @uri end |
Instance Method Details
#create_uri ⇒ Object
55 56 57 58 |
# File 'lib/accern/alpha.rb', line 55 def create_uri uri.query = URI.encode_www_form(combine_query) puts uri end |
#download(path) ⇒ Object
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 |
# File 'lib/accern/alpha.rb', line 20 def download(path) create_uri http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true format_response(http.request_get(uri, header)) return if new_id == last_id save_last_id generate_csv_header(path) if format == :csv File.open(path, 'a') do |f| if format == :json docs.reverse_each { |d| f.puts d.to_json } end if format == :csv docs.reverse_each { |d| f.puts flat.process(d) } end end rescue => e puts e. puts e.backtrace end |
#download_loop(path: nil) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/accern/alpha.rb', line 47 def download_loop(path: nil) loop do download(path) sleep 8 end end |