-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathESI_PS.Ps1
151 lines (110 loc) · 4.92 KB
/
ESI_PS.Ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#Initial Variables
#User INformation
#Character ID
$CharacterID = ""
#Developers.Eveonline.com INformation Goes HEre
$ClientID = ""
$ClientSecret = ""
#SSO Auth Info
#obtain Refresh Token Using POSTMAN or other REST TOOLS
$RefreshToken = ""
#End User Information
#System Configs
#SET Storage Location of EVE API Dump Stuff
$StoragePath = "C:\ESI_DUMP\" #MAke sure this path ends with a backslash
$AccessToken ="" #This Value Left Blank to be populated
#$CallbackUrl = "https://localhost/callback "
$GetNewTokenUrl = "https://login.eveonline.com/oauth/token?grant_type=refresh_token&refresh_token="+$RefreshToken
$ESIURL = "https://esi.tech.ccp.is/latest/"
###########################
#End System Configs
#This Function allows you to renew an Auth Token with a refresh Token stored in the $RefreshToken VAriable
Function GetAuthToken
{
#BAse64 Encoding Stuff For Authorization Requests
$Authstring1 = $ClientID+":"+$ClientSecret
$Authstring1
$Text = $Authstring1
$Bytes = [System.Text.Encoding]::Default.GetBytes($Text)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText
#End SSO Auth Information
#Set Headers for Token Request.
$header = @{
}
$header.Add('Authorization','Basic '+ $EncodedText )
$header.Add('Content-Type','application/x-www-form-urlencoded' )
#End Request header
#Request new Autorization Token
$TEST = Invoke-WebRequest -UseBasicParsing -Uri $GetNewTokenUrl -Headers $header -Method Post
$AuthkeyObj = ConvertFrom-JSON $TEST #Convert to Powershell Object from JSON
#$Authkey is new Token
$Authkey = $AuthKeyObj|Select-Object -ExpandProperty "access_token"
$Seconds = $AuthKeyObj|Select-Object -ExpandProperty "expires_in"
$ts = New-TimeSpan -Seconds $Seconds
$ExpirationTime = (get-date) + $ts
$AuthTracking = New-Object -Typename psobject -Property @{Authkey=$Authkey;Expiry=$ExpirationTime }
#Writes Token & Expiration time to File for storage
Export-CSV -NoTypeInformation -InputObject $AuthTracking -Path $StoragePath"AuthkeyStuff.csv"
}
#This Function imports the Auth Token From The Stored CSV and checks if it is valid
Function CheckAuth
{
$AUTHINFO = Import-CSV "E:\EVE API\Powershell Storage\AuthkeyStuff.csv"
$AuthExpiry = $AuthINFO|Select-Object -ExpandProperty Expiry
$CurrentTime = Get-Date
#If token is Expired, uses GetAuthToken to Acquire new Auth Token
if ([DateTime]$AuthExpiry -le [DateTime]$CurrentTime)
{
GetAuthToken
$AccessToken = $AuthINFO|Select-Object -ExpandProperty Authkey
}
Else
{
#If token is valid, does not replace token
$AccessToken = $AuthINFO|Select-Object -ExpandProperty Authkey
}
#Returns AccessToken
return $AccessToken
}
Function WalletBalance #This Pulls Your Current Walletbalance & Dumps the balance & Timestamp to a CSV
{
$AccessToken = CheckAuth
$WalletQuery = $ESIURL+ "characters/"+$CharacterID+"/wallet/?datasource=tranquility&token="+$AccessToken
$WalletBalance = Invoke-WebRequest -URI $WalletQuery
$WalletObj = ConvertFrom-JSON $WalletBalance
# $WalletObj|out-Gridview
# $WalletObj | Get-Member
$Currentbalance = $WalletObj
$BalanceOutput = New-Object -Typename psobject -Property @{Balance=$WalletObj;Datetime=get-date }
Export-CSV -Append -NoTypeInformation -InputObject $BalanceOutput -Path $StoragePath"WalletBalance.CSV"
}
Function JournalEntries #This Grabs Journal Entries
{
$AccessToken = CheckAuth
$JournalQuery = $ESIURL+ "characters/"+$CharacterID+"/wallet/journal/?datasource=tranquility&token="+$AccessToken
$JournalTransactions = Invoke-WebRequest -URI $JournalQuery
$JournalObj = ConvertFrom-JSON -InputObject $JournalTransactions
([pscustomobject]$JournalObj) | export-csv -NoTypeInformation -Append -Path $StoragePath"Journal.CSV"
}
Function CharacterTransactions #This grabs all Transactions
{
$AccessToken = CheckAuth
$TransQuery = $ESIURL+ "characters/"+$CharacterID+"/wallet/transactions/?datasource=tranquility&token="+$AccessToken
$Transactionlog = Invoke-WebRequest -URI $TransQuery
$TransObj = ConvertFrom-JSON -InputObject $Transactionlog
([pscustomobject]$TransObj) | export-csv -NoTypeInformation -Append -Path $StoragePath"Transactions.CSV"
}
Function CharacterOrders #This Grabs your orders & A timestamp, then appends to a file
{
$AccessToken = CheckAuth
$OrderQuery = $ESIURL+ "characters/"+$CharacterID+"/orders/?datasource=tranquility&token="+$AccessToken
$Orderlog = Invoke-WebRequest -URI $OrderQuery
$OrderObj = ConvertFrom-JSON -InputObject $Orderlog
# Add-member -InputObject ([pscustomobject]$OrderObj) -NotePropertyName Timestamp -NotePropertyValue Get-Date
([pscustomobject]$OrderObj) |Select-Object *,@{Name='Timestamp';Expression = {get-date} } | export-csv -NoTypeInformation -Append -Path $StoragePath"Orders.CSV"
}
WalletBalance
JournalEntries
CharacterTransactions
CharacterOrders