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.
-
#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.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #download(path) ⇒ Object
- #download_loop(path) ⇒ Object
-
#initialize(options) ⇒ Alpha
constructor
A new instance of Alpha.
Constructor Details
#initialize(options) ⇒ Alpha
Returns a new instance of Alpha.
6 7 8 9 10 11 12 13 14 |
# File 'lib/accern/alpha.rb', line 6 def initialize() @token = .fetch(:token) @format = .fetch(:format, :json) @params = .fetch(:params, {}) @base_url = 'http://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.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def base_url @base_url end |
#docs ⇒ Object (readonly)
Returns the value of attribute docs.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def docs @docs end |
#flat ⇒ Object (readonly)
Returns the value of attribute flat.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def flat @flat end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def format @format end |
#last_id ⇒ Object (readonly)
Returns the value of attribute last_id.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def last_id @last_id end |
#new_id ⇒ Object (readonly)
Returns the value of attribute new_id.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def new_id @new_id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def params @params end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def token @token end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
3 4 5 |
# File 'lib/accern/alpha.rb', line 3 def uri @uri end |
Instance Method Details
#download(path) ⇒ Object
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 |
# File 'lib/accern/alpha.rb', line 16 def download(path) uri.query = URI.encode_www_form(last_id: last_id) if last_id puts uri format_response( Net::HTTP.new(uri.host, uri.port).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) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/accern/alpha.rb', line 45 def download_loop(path) loop do download(path) sleep 8 end end |