Class: EODData::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/eod_data/client.rb

Overview

:nodoc:

Defined Under Namespace

Classes: BushelPrice, CentsPerPoundPrice, LoginResponse, LoginResult, OriginalPrice, Quote, QuoteGetResponse, QuoteGetResult, QuoteList2Response, QuoteList2Result, QuoteListByDateResponse, QuoteListByDateResult, Response, Result, SavonRequest

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



39
40
41
42
43
44
45
46
47
48
# File 'lib/eod_data/client.rb', line 39

def initialize(options = {})
  options = default_options.merge(options)

  @base_url = options[:base_url]
  @logger = options.compact.fetch(:logger, Logger.new(STDOUT))
  @proxy_url = options[:proxy_url]
  @password = options[:password]
  @username = options[:username]
  @request = SavonRequest.new(@base_url, @logger, @proxy_url)
end

Class Attribute Details

.base_urlObject

Returns the value of attribute base_url.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def base_url
  @base_url
end

.loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def logger
  @logger
end

.passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def password
  @password
end

.price_conversion_class_namesObject

Returns the value of attribute price_conversion_class_names.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def price_conversion_class_names
  @price_conversion_class_names
end

.proxy_urlObject

Returns the value of attribute proxy_url.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def proxy_url
  @proxy_url
end

.request_typeObject

Returns the value of attribute request_type.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def request_type
  @request_type
end

.usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/eod_data/client.rb', line 8

def username
  @username
end

Class Method Details

.configure {|_self| ... } ⇒ Object

“‘ruby EODData::Client.configure do |config|

config.base_url = 'http://localhost:3000'
config.logger = Logger.new(STDOUT)
config.password = 'password'
config.price_conversion_class_names = {
  ZC: 'OriginalPrice'
  ZM: 'TonPrice'
}
config.username = 'username'

end “‘ elsewhere

“‘ruby client = EODData::Client.new “`

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
# File 'lib/eod_data/client.rb', line 33

def configure
  yield self
  true
end

Instance Method Details

#loginObject



50
51
52
53
54
55
56
# File 'lib/eod_data/client.rb', line 50

def 
  message = { Username: @username, Password: @password }

  response = @request.perform_request(:login, message: message)

  LoginResponse.new(response).result
end

#quote(exchange, symbol) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/eod_data/client.rb', line 58

def quote(exchange, symbol)
  message = { Exchange: exchange, Symbol: symbol, Token: token }

  response = @request.perform_request(:quote_get, message: message)

  QuoteGetResponse.new(response).result
end

#quotes(exchange, symbols) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/eod_data/client.rb', line 66

def quotes(exchange, symbols)
  message = { Exchange: exchange, Symbols: symbols.join(','), Token: token }

  response = @request.perform_request(:quote_list2, message: message)

  QuoteList2Response.new(response).result
end

#quotes_by_date(exchange, quote_date) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/eod_data/client.rb', line 74

def quotes_by_date(exchange, quote_date)
  message = {
    Exchange: exchange,
    QuoteDate: quote_date.strftime('%Y%m%d'),
    Token: token
  }

  response = @request.perform_request(:quote_list_by_date, message: message)

  QuoteListByDateResponse.new(response).result
end

#tokenString

Returns Login Token.

Returns:

  • (String)

    Login Token



90
91
92
93
94
# File 'lib/eod_data/client.rb', line 90

def token
  return @token if @token

  @token = .token
end