robinhood-api 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/robinhood.rb +22 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf571e1d096eb33585450426648dbb611defd49e
4
- data.tar.gz: d3f5ead7ec9e3a78cd4193a163219664f9b5c595
3
+ metadata.gz: 4dfe1dce8dda9168979bd651c80b877f0ab9e0a0
4
+ data.tar.gz: 684af5059539659160b16aafeec5048bc185e54a
5
5
  SHA512:
6
- metadata.gz: 58518aea355a1c4345094807000ef4be7110b0146f315c3bce29a4318832be2b4b5a4f7779fa2fce4feab861d179111ddcfb61e86bd8a5429859650129d7d880
7
- data.tar.gz: cbb117fe801eccd261d373b71f7b341d9d5784db1f2d9480955cbb509794a35b00753aac01312e0f1b21593e8b85a57f4ee6c2427fe431f06814872a79e5b740
6
+ metadata.gz: 8a93b1179979a58f8f41892d6735a23b6ca63b13b27cdb84128b8d8d22d280d82a542f9ef1b28779c2950cc2bb1c0510156a852dc210dc7aa66bd898dfdde44f
7
+ data.tar.gz: b31cd8904edb399e9b062f9801d648de7b09ecf5ff81076238a1eb53f833f97084eff1039ce5ce040668962005ea0bdf69c802c801e2b4ea281df165ad394e39
@@ -4,11 +4,16 @@ module RobinhoodModule
4
4
  m = instance_method(name)
5
5
  define_method(name) do |*args, &block|
6
6
  # yield
7
- if token_compliant(name)
8
- m.bind(self).(*args, &block)
7
+ if prerequisites?(name)
8
+ if token_compliant?(name)
9
+ m.bind(self).(*args, &block)
10
+ else
11
+ puts "You have to run the login(<username>, <password>) method or a Robinhood.new instance before running the #{name} method"
12
+ exit 1
13
+ end
9
14
  else
10
- puts "You have to run the login(<username>, <password>) method or a Robinhood.new instance before running the #{name} method"
11
- exit 1
15
+ puts "You must define ROBINHOOD_USERNAME and ROBINHOOD_PASSWORD environment variables to run the #{name} method"
16
+ exit 2
12
17
  end
13
18
  end
14
19
  end
@@ -200,14 +205,25 @@ module RobinhoodModule
200
205
  }
201
206
  end
202
207
 
208
+ def methodlist
209
+ [:investment_profile, :accounts, :ach_iav_auth, :ach_relationships, :ach_transfers, :applications, :dividends, :edocuments, :margin_upgrade, :notifications, :orders, :password_reset, :document_requests, :user, :watchlists]
210
+ end
211
+
203
212
  def headers
204
213
  @headers ||= {
205
214
  'Accept' => 'application/json',
206
215
  }
207
216
  end
208
217
 
209
- def token_compliant(method)
210
- methodlist = [:investment_profile, :accounts, :ach_iav_auth, :ach_relationships, :ach_transfers, :applications, :dividends, :edocuments, :margin_upgrade, :notifications, :orders, :password_reset, :document_requests, :user, :watchlists]
218
+ def prerequisites?(method)
219
+ if methodlist.include?(method)
220
+ return ENV['ROBINHOOD_USERNAME'] && ENV['ROBINHOOD_PASSWORD']
221
+ else
222
+ return true
223
+ end
224
+ end
225
+
226
+ def token_compliant?(method)
211
227
 
212
228
  if methodlist.include?(method)
213
229
  if headers.key?('Authorization')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robinhood-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Alcala