lita-onewheel-finance 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5edbbe2ef63969dd624af3c1657c738648ff8b5faf965379860c87e8283f95f2
4
- data.tar.gz: 978e055da01a370ce7f6c835ecffedb4cf8bee00edc29cda2586d4a9cbee57db
3
+ metadata.gz: f3747c2d546ac8e758258319b48a71e103a903a51483a57cbaee270ba6aa0538
4
+ data.tar.gz: 938ffb54fe90b72caa32a50f59e28b59eed27cb8bdbbe9c07cd416d358b14a11
5
5
  SHA512:
6
- metadata.gz: ddb1e70d29cccdc9862a6de746db606b3818ca6bc64d45d4b7836f103c4f53766b91f891ce029277507534be70b8942cbf6ce0e5617741c149c812196bf99e0d
7
- data.tar.gz: 44b36a8c69c951f93355db2286fe0113458d6d2323fd97e486fb46166eb82e6546e497a5cd18ff7978272b427d66b7e7d63f9b890ea40f6bf81a9c6c32ffbf8e
6
+ metadata.gz: c4239764c78f96cefaf2d319caa1d30d55d77fc6ae100e1410c4a7fa801807bd58b51a683d1f828dfea7b473586fc88b94201d1f48e3bef447e852e4b987eaab
7
+ data.tar.gz: fa467590bdd56dda70008a42e4c90ac42847437e57f5a3f3a53dba78b95e9c453dbf1cf837c79ae9d2bdc55c51b12242badd3626faa6ddf1cf982aeab4667ebb
@@ -68,11 +68,20 @@ class AlphaVantageQuote
68
68
  end
69
69
 
70
70
  class WorldTradeDataQuote
71
- attr_reader :symbol, :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange
71
+ attr_reader :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange, :error
72
+ attr_accessor :symbol
72
73
 
73
74
  def initialize(json_blob)
74
75
  Lita.logger.debug "parsing: #{json_blob}"
75
76
  hash = JSON.parse(json_blob)
77
+
78
+ if hash['Message'].to_s.include? 'Error'
79
+ @error = true
80
+ return
81
+ else
82
+ @error = false
83
+ end
84
+
76
85
  quote = hash['data'][0]
77
86
 
78
87
  quote.keys.each do |key|
@@ -117,12 +126,16 @@ module Lita
117
126
  def handle_quote(response)
118
127
  stock = handle_world_trade_data response.matches[0][0]
119
128
 
120
- str = "#{stock.exchange} - #{stock.symbol}: $#{stock.price} "
121
- if stock.change >= 0
122
- # if irc
123
- str += "#{IrcColors::green} ⬆$#{stock.change}#{IrcColors::reset}, #{IrcColors::green}#{stock.change_percent}%#{IrcColors::reset} "
129
+ if stock.error
130
+ str = "`#{stock.symbol}` not found on any stock exchange."
124
131
  else
125
- str += "#{IrcColors::red} ↯$#{stock.change}#{IrcColors::reset}, #{IrcColors::red}#{stock.change_percent}%#{IrcColors::reset} "
132
+ str = "#{IrcColors::grey}#{stock.exchange} - #{IrcColors::reset}#{stock.symbol}: #{IrcColors::blue}$#{stock.price}#{IrcColors::reset} "
133
+ if stock.change >= 0
134
+ # if irc
135
+ str += "#{IrcColors::green} ⬆$#{stock.change}#{IrcColors::reset}, #{IrcColors::green}#{stock.change_percent}%#{IrcColors::reset} "
136
+ else
137
+ str += "#{IrcColors::red} ↯$#{stock.change}#{IrcColors::reset}, #{IrcColors::red}#{stock.change_percent}%#{IrcColors::reset} "
138
+ end
126
139
  end
127
140
 
128
141
  response.reply str
@@ -135,7 +148,13 @@ module Lita
135
148
  Lita.logger.debug "#{url} #{params.inspect}"
136
149
 
137
150
  resp = RestClient.get url, {params: params}
151
+ Lita.logger.debug "response: #{resp}"
152
+
138
153
  stock = WorldTradeDataQuote.new resp
154
+ if stock.error
155
+ stock.symbol = symbol
156
+ end
157
+ stock
139
158
  end
140
159
 
141
160
  # deprecated for now
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-onewheel-finance"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Andrew Kreps"]
5
5
  spec.email = ["andrew.kreps@gmail.com"]
6
6
  spec.description = "Wee li'l stock quote bot"
7
- spec.summary = spec.description
7
+ spec.summary = "Designed to query stock indicies and return relevant data."
8
8
  spec.homepage = "https://github.com/onewheelskyward/lita-onewheel-finance"
9
9
  spec.license = "MIT"
10
10
  spec.metadata = { "lita_plugin_type" => "handler" }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Message": "Error! The requested stock(s) could not be found."
3
+ }
@@ -13,15 +13,19 @@ describe Lita::Handlers::OnewheelFinance, lita_handler: true do
13
13
  it 'quotes up' do
14
14
  mock_up 'worldtradedata-quote-up'
15
15
  send_command 'quote lulu'
16
- puts replies.last
17
- expect(replies.last).to include('NASDAQ - LULU: $233.01')
16
+ expect(replies.last).to include("\u000314NASDAQ - \u0003LULU: \u000302$233.01\u0003")
18
17
  end
19
18
 
20
19
  it 'quotes down' do
21
20
  mock_up 'worldtradedata-quote-down'
22
21
  send_command 'quote xlp'
23
- puts replies.last
24
- expect(replies.last).to include('NYSE - XLP: $62.51')
22
+ expect(replies.last).to include("\u000314NYSE - \u0003XLP: \u000302$62.51\u0003")
25
23
  expect(replies.last).to include('↯$-0.47')
26
24
  end
25
+
26
+ it 'errors' do
27
+ mock_up 'worldtradedata-error'
28
+ send_command 'quote in'
29
+ expect(replies.last).to eq('`in` not found on any stock exchange.')
30
+ end
27
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-finance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
@@ -141,6 +141,7 @@ files:
141
141
  - spec/fixtures/alphavantage-global-quote.json
142
142
  - spec/fixtures/alphavantage-quote-down.json
143
143
  - spec/fixtures/effr.html
144
+ - spec/fixtures/worldtradedata-error.json
144
145
  - spec/fixtures/worldtradedata-quote-down.json
145
146
  - spec/fixtures/worldtradedata-quote-up.json
146
147
  - spec/lita/handlers/onewheel_finance_spec.rb
@@ -168,11 +169,12 @@ requirements: []
168
169
  rubygems_version: 3.0.3
169
170
  signing_key:
170
171
  specification_version: 4
171
- summary: Wee li'l stock quote bot
172
+ summary: Designed to query stock indicies and return relevant data.
172
173
  test_files:
173
174
  - spec/fixtures/alphavantage-global-quote.json
174
175
  - spec/fixtures/alphavantage-quote-down.json
175
176
  - spec/fixtures/effr.html
177
+ - spec/fixtures/worldtradedata-error.json
176
178
  - spec/fixtures/worldtradedata-quote-down.json
177
179
  - spec/fixtures/worldtradedata-quote-up.json
178
180
  - spec/lita/handlers/onewheel_finance_spec.rb