Skip to content

Commit

Permalink
Merge pull request #186 from thedavecarroll/185-add-bluebirdpslastres…
Browse files Browse the repository at this point in the history
…ponse-session-variable

closed #185
  • Loading branch information
thedavecarroll committed Nov 24, 2022
2 parents 4a4bbe4 + cc4a746 commit f893252
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion BluebirdPS/BluebirdPS.psd1
Expand Up @@ -4,7 +4,7 @@
PowerShellVersion = '7.0'
RootModule = 'BluebirdPS.psm1'
CompanyName = 'thedavecarroll'
ModuleVersion = '0.8.1'
ModuleVersion = '0.8.2'
Author = 'Dave Carroll'
CompatiblePSEditions = 'Core'
FileList = @()
Expand Down
9 changes: 9 additions & 0 deletions BluebirdPS/prepend/BluebirdPS.ps1
Expand Up @@ -44,4 +44,13 @@ $BluebirdPSConfiguration = [Configuration]@{
#region other variables
[SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$BluebirdPSHistoryList = [List[ResponseData]]::new()
$global:BluebirdPSLastResponse = [ResponseData]::new()
#endregion

#region Handle Module Removal
$OnRemoveScript = {
Remove-Variable -Name BluebirdPSLastResponse -Scope Global -Force
}
$ExecutionContext.SessionState.Module.OnRemove += $OnRemoveScript
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $OnRemoveScript
#endregion Handle Module Removal
4 changes: 3 additions & 1 deletion BluebirdPS/private/Write-TwitterResponse.ps1
Expand Up @@ -23,7 +23,9 @@ function Write-TwitterResponse {

$BluebirdPSHistoryList.Add($ResponseData)
Write-Information -MessageData $ResponseData
$script:LastResponseData = $ResponseData

[SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')]
$global:BluebirdPSLastResponse = $ResponseData

switch ($BluebirdPSConfiguration.OutputType) {
'PSCustomObject' {
Expand Down
2 changes: 1 addition & 1 deletion BluebirdPS/public/api_v2/tweets/Get-TweetCount.ps1
Expand Up @@ -49,7 +49,7 @@ function Get-TweetCount {
}

$TweetCount = Invoke-TwitterRequest -RequestParameters $Request
$TotalCount = $script:LastResponseData.ApiResponse.meta.total_tweet_count
$TotalCount = $global:BluebirdPSLastResponse.ApiResponse.meta.total_tweet_count
$TweetCountSummary = [TweetInfo.TweetCountSummary]@{
SearchString = $SearchString
Granularity = $Granularity
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Expand Up @@ -132,7 +132,8 @@ The returned response, including response headers, the status code, and the requ
The response data object is sent to the `Write-TwitterResponse` command.
This command performs the rate limit action when the threshold is reached, both based on configuration values.

Next, the command adds the response data to the module's session history table and writes the same data to the *Information Stream*.
Next, the command adds the response data to the module's session history list, writes the same data to the *Information Stream*,
and stores the last response in the session variable `$BluebirdPSLastResponse`.

With possible values of 'CustomClasses', 'PsCustomObject', or 'JSON', the configuration value for OutputType determines the format that the API response will be presented to the user.

Expand Down
10 changes: 7 additions & 3 deletions docs/about_BluebirdPS.md
Expand Up @@ -58,11 +58,15 @@ Set-TwitterAuthentication

# Information Stream and History

The execution results of commands that connect to the Twitter API are written to PowerShell's information stream.
The execution results of commands that connect to the Twitter API are written to PowerShell's information stream for each API call.
These results contains the command name, HTTP method, URL, OAuth Version, HTTP Status, API response, endpoint rate limit details, and more.

The same data is also written to the a history record that is only maintained for the current session.
Reimporting the module will reset the command history.
The same data available via `$BluebirdPSLastResponse` for the current session.
Each result is also added to a list, likewise available for the current session.

### Example

$BluebirdPSLastResponse

### Example (Last 5 commands sent to Twitter)

Expand Down

0 comments on commit f893252

Please sign in to comment.