simplicity_client 0.1.0
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.
- checksums.yaml +7 -0
- data/lib/simplicity_client.rb +156 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc8103d850590055f42dab594a5bf3b387fbc1e72650f14d3c870ec91462dd71
|
4
|
+
data.tar.gz: b503abe344ad5c3444842cf15f52f135ddea3f29129946b65fa8a640e5f4736d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '07889fe220e84ce10a24329d94868eb0395ca6dc93af151c6c53dfe0a0cff484fff35abc4dfcbdaaceae71c99215f7b7a74545fac76500564b7cee06e72ba1c1'
|
7
|
+
data.tar.gz: 57b312053cb9dcaf4052a0c602d7c82ba963b9cb179c79492b8ab04a5580514a2cf258f6d93c01ccdd554dfdf1778603c6d0c63e82186aa6b7156026d5ee1968
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "dotenv/load"
|
5
|
+
rescue LoadError
|
6
|
+
# Dotenv is not available, so move on without loading it. It's only used for development.
|
7
|
+
end
|
8
|
+
require "faraday"
|
9
|
+
require "faraday-cookie_jar"
|
10
|
+
require "faraday/follow_redirects"
|
11
|
+
require "aws-sdk-cognitoidentityprovider"
|
12
|
+
require "aws-cognito-srp"
|
13
|
+
require "aws-sdk-cognitoidentity"
|
14
|
+
require "aws-sigv4"
|
15
|
+
|
16
|
+
module SimplicityClient
|
17
|
+
class Error < StandardError; end
|
18
|
+
|
19
|
+
class Session
|
20
|
+
def initialize
|
21
|
+
@logger = Logger.new $stderr
|
22
|
+
@logger.level = Logger::INFO
|
23
|
+
|
24
|
+
@user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36"
|
25
|
+
|
26
|
+
@client = Faraday.new(
|
27
|
+
headers: { "User-Agent" => @user_agent },
|
28
|
+
# proxy: "http://Thinkbook.local:8080",
|
29
|
+
# :ssl => {:verify => false}
|
30
|
+
) do |builder|
|
31
|
+
builder.response :follow_redirects
|
32
|
+
# builder.response :logger
|
33
|
+
builder.adapter Faraday.default_adapter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Write the session data out to a string so that the session can be restored later
|
38
|
+
def export
|
39
|
+
{
|
40
|
+
auth_data: @auth_data,
|
41
|
+
}.to_json
|
42
|
+
end
|
43
|
+
|
44
|
+
# Load the session data from a string to restore a session
|
45
|
+
def load(str)
|
46
|
+
json = JSON.parse(str)
|
47
|
+
@auth_data = json["auth_data"]
|
48
|
+
end
|
49
|
+
|
50
|
+
def login(username, password)
|
51
|
+
client = Aws::CognitoIdentityProvider::Client.new(region: 'ap-southeast-2')
|
52
|
+
|
53
|
+
user_pool_id = "ap-southeast-2_abAklW6ap"
|
54
|
+
|
55
|
+
aws_srp = Aws::CognitoSrp.new(
|
56
|
+
username: username.downcase,
|
57
|
+
password: password,
|
58
|
+
pool_id: user_pool_id,
|
59
|
+
client_id: "kvoiu7unft0c8hqqsa6hkmeu5",
|
60
|
+
aws_client: client,
|
61
|
+
)
|
62
|
+
|
63
|
+
resp = aws_srp.authenticate
|
64
|
+
|
65
|
+
cognito_identity_client = Aws::CognitoIdentity::Client.new(region: 'ap-southeast-2')
|
66
|
+
|
67
|
+
# Assuming you have the Identity Pool ID and the ID token
|
68
|
+
identity_pool_id = 'ap-southeast-2:0ed33fc6-4cef-4f2e-b634-31c616e108e2'
|
69
|
+
id_token = resp.id_token
|
70
|
+
|
71
|
+
# Get ID from the identity pool
|
72
|
+
id_response = cognito_identity_client.get_id({
|
73
|
+
identity_pool_id: identity_pool_id,
|
74
|
+
logins: {
|
75
|
+
"cognito-idp.ap-southeast-2.amazonaws.com/#{user_pool_id}" => id_token
|
76
|
+
}
|
77
|
+
})
|
78
|
+
|
79
|
+
# Get credentials for the ID
|
80
|
+
credentials_response = cognito_identity_client.get_credentials_for_identity({
|
81
|
+
identity_id: id_response.identity_id,
|
82
|
+
logins: {
|
83
|
+
"cognito-idp.ap-southeast-2.amazonaws.com/#{user_pool_id}" => id_token
|
84
|
+
}
|
85
|
+
})
|
86
|
+
|
87
|
+
access_key_id = credentials_response.credentials.access_key_id
|
88
|
+
secret_key = credentials_response.credentials.secret_key
|
89
|
+
session_token = credentials_response.credentials.session_token
|
90
|
+
|
91
|
+
@auth_data = {
|
92
|
+
email: username,
|
93
|
+
access_key_id: access_key_id,
|
94
|
+
secret_key: secret_key,
|
95
|
+
region: "ap-southeast-2",
|
96
|
+
session_token: session_token,
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def logout
|
101
|
+
# Not required
|
102
|
+
end
|
103
|
+
|
104
|
+
def list_accounts
|
105
|
+
# Ensure @auth_data contains the necessary credentials
|
106
|
+
raise Error, "Authentication data not found. Please login first." unless @auth_data
|
107
|
+
|
108
|
+
service = "execute-api"
|
109
|
+
region = "ap-southeast-2"
|
110
|
+
http_method = "POST"
|
111
|
+
url = "https://h4ku5ofov2.execute-api.ap-southeast-2.amazonaws.com/prod/secure"
|
112
|
+
email = @auth_data["email"]
|
113
|
+
body = {
|
114
|
+
variables: {},
|
115
|
+
query: "{\n Account(email: \"#{email}\") {\n InvestmentType\n InvestmentCode\n PortfolioCode\n InvestmentName\n Portfolio\n Status\n RegistryAccountId\n MarketValue\n PrimaryBeneficiarySurname\n EntityType\n PriceDate\n IsDefault\n ExternalReference\n BankAccounts {\n AccountName\n LastThreeDigitsOfAccountNumberPart\n SuffixPart\n IsPrimary\n Id\n __typename\n }\n __typename\n }\n}\n",
|
116
|
+
}.to_json
|
117
|
+
|
118
|
+
signer = Aws::Sigv4::Signer.new(
|
119
|
+
service: service,
|
120
|
+
region: region,
|
121
|
+
access_key_id: @auth_data["access_key_id"],
|
122
|
+
secret_access_key: @auth_data["secret_key"],
|
123
|
+
session_token: @auth_data["session_token"],
|
124
|
+
)
|
125
|
+
|
126
|
+
signature = signer.sign_request(
|
127
|
+
http_method: http_method,
|
128
|
+
url: url,
|
129
|
+
body: body
|
130
|
+
)
|
131
|
+
|
132
|
+
response = @client.post(url) do |req|
|
133
|
+
req.headers = signature.headers.merge({
|
134
|
+
'Content-Type' => 'application/json'
|
135
|
+
})
|
136
|
+
req.body = body
|
137
|
+
end
|
138
|
+
|
139
|
+
# Handle the response
|
140
|
+
if response.success?
|
141
|
+
obj = JSON.parse(response.body)
|
142
|
+
obj["data"]["Account"].map do |account|
|
143
|
+
{
|
144
|
+
accountNo: account["InvestmentCode"],
|
145
|
+
accountType: "#{account["InvestmentType"]} - #{account["Portfolio"]}",
|
146
|
+
customerName: account["InvestmentName"],
|
147
|
+
accountBalance: account["MarketValue"],
|
148
|
+
isLiabilityType: false,
|
149
|
+
}
|
150
|
+
end
|
151
|
+
else
|
152
|
+
raise Error, "Failed to list accounts: #{response.status}, #{response.body}"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplicity_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- George Dewar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-cookie_jar
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.7
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-follow_redirects
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: aws-sdk-cognitoidentityprovider
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.87'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.87'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: aws-cognito-srp
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.6.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.6.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aws-sdk-cognitoidentity
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.52.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.52.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: aws-sigv4
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.8.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.8.0
|
111
|
+
description: This gem can log into Simplicity and fetch fund balances
|
112
|
+
email:
|
113
|
+
- george@dewar.co.nz
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- lib/simplicity_client.rb
|
119
|
+
homepage: https://rubygems.org/gems/hola
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.0.0
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubygems_version: 3.2.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Fetch KiwiSaver and investment fund balances from Simplicity
|
142
|
+
test_files: []
|