Class: Webull::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/webull/authenticator.rb

Overview

Authenticator generates access/refresh tokens from a username/password

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(udid) ⇒ Authenticator

Returns a new instance of Authenticator.



29
30
31
# File 'lib/webull/authenticator.rb', line 29

def initialize(udid)
  @udid = udid
end

Instance Attribute Details

#udidObject (readonly)

Returns the value of attribute udid.



27
28
29
# File 'lib/webull/authenticator.rb', line 27

def udid
  @udid
end

Instance Method Details

#generate_tokensObject

rubocop:disable Metrics/MethodLength



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/webull/authenticator.rb', line 33

def generate_tokens # rubocop:disable Metrics/MethodLength
  params = {
    account: username,
    accountType: 2,
    deviceId: udid,
    regionId: 6,
    grade: 1,
    pwd: hashed_password,
    verificationCode: mfa
  }
  resp = HTTParty.post(
    'https://userapi.webull.com/api/passport/login/v3/account',
    body: params.to_json,
    headers: { 'Content-Type' => 'application/json' }
  )
  raise("Login request failed: #{resp.code}") unless resp.success?
  Tokens.from_resp(resp)
end