Commit 4b4ed560 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel

Store session in client

parent f1f9b315
......@@ -14,7 +14,8 @@ import (
)
type Client struct {
creds Credentials
creds Credentials
session Session
privateKey *rsa.PrivateKey
publicKey *rsa.PublicKey
......@@ -32,6 +33,7 @@ func NewClient(creds Credentials) *Client {
return &Client{
creds: creds,
session: Session{},
privateKey: privateKey,
publicKey: publicRSAKey,
httpClient: &http.Client{
......
package bunqapi
// Amount describes a monetary amount.
type Amount struct {
// The amount formatted to two decimal places.
Value string `json:"value"`
// The currency of the amount. It is an ISO 4217 formatted currency code.
Currency string `json:"currency"`
}
package bunqapi
import "github.com/sirupsen/logrus"
type Session struct {
Token string
UserCompany *UserCompany
UserPerson *UserPerson
}
type sessionServerRequest struct {
// The API key.
Secret string `json:"secret"`
}
type wrappedSessionServerResponse struct {
Response []sessionServerResponse `json:"Response"`
}
type sessionServerResponse struct {
Response []struct {
ID *BunqID `json:"Id"`
Token *struct {
ID int `json:"id"`
Token string `json:"token"`
} `json:"Token"`
UserCompany *UserCompany `json:"UserCompany"`
} `json:"Response"`
ID *BunqID `json:"Id"`
Token *struct {
ID int `json:"id"`
Token string `json:"token"`
} `json:"Token"`
UserCompany *UserCompany `json:"UserCompany"`
UserPerson *UserPerson `json:"UserPerson"`
}
func (c *Client) SessionStart() {
......@@ -21,10 +32,22 @@ func (c *Client) SessionStart() {
Secret: c.creds.APIKey,
}
response := sessionServerResponse{}
errResp := c.DoRequest("POST", "session-server", &payload, &response)
wrappedResponse := wrappedSessionServerResponse{}
errResp := c.DoRequest("POST", "session-server", &payload, &wrappedResponse)
if errResp != nil {
log.WithFields(errResp.LogFields()).Fatal("error performing session creation request")
}
response := sessionServerResponse{}
MergeStructs(wrappedResponse.Response, &response)
c.session.Token = response.Token.Token
c.session.UserCompany = response.UserCompany
c.session.UserPerson = response.UserPerson
logrus.WithFields(logrus.Fields{
"firstName": c.session.UserPerson.FirstName,
"lastName": c.session.UserPerson.LastName,
"session": c.session.Token,
}).Info("session created")
}
......@@ -78,3 +78,42 @@ type UserCompany struct {
DailyLimitWithoutConfirmationLogin Limit `json:"daily_limit_without_confirmation_login"`
NotificationFilters []NotificationFilter `json:"notification_filters"`
}
type UserPerson struct {
ID int `json:"id"`
Created Time `json:"created"`
Updated Time `json:"updated"`
FirstName string `json:"first_name"`
MiddleName string `json:"middle_name"`
LastName string `json:"last_name"`
PublicNickName string `json:"public_nick_name"`
AddressMain Address `json:"address_main"`
AddressPostal Address `json:"address_postal"`
AvatarUUID string `json:"avatar_uuid"`
TaxResident string `json:"tax_resident"`
DocumentType string `json:"document_type"`
DocumentNumber string `json:"document_number"`
DocumentCountryOfIssuance string `json:"document_country_of_issuance"`
DocumentFrontAttachmentID int `json:"document_front_attachment_id"`
DocumentBackAttachmentID int `json:"document_back_attachment_id"`
DateOfBirth string `json:"date_of_birth"`
PlaceOfBirth string `json:"place_of_birth"`
CountryOfBirth string `json:"country_of_birth"`
Nationality string `json:"nationality"`
Language string `json:"language"`
Region string `json:"region"`
Gender string `json:"gender"`
Status string `json:"status"`
SubStatus string `json:"sub_status"`
LegalGuardianAlias []Alias `json:"legal_guardian_alias"`
SessionTimeout int `json:"session_timeout"`
DailyLimitWithoutConfirmationLogin Amount `json:"daily_limit_without_confirmation_login"`
NotificationFilters []NotificationFilter `json:"notification_filters"`
DisplayName string `json:"display_name"`
PublicUUID string `json:"public_uuid"`
LegalName string `json:"legal_name"`
Alias []Alias `json:"alias"`
Avatar Avatar `json:"avatar"`
VersionTermsOfService string `json:"version_terms_of_service"`
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment