Skip to content

Instantly share code, notes, and snippets.

@MateuszNad
Last active May 22, 2017 19:23
Show Gist options
  • Save MateuszNad/e381a7690a0ede3513e0e9507cdb42b5 to your computer and use it in GitHub Desktop.
Save MateuszNad/e381a7690a0ede3513e0e9507cdb42b5 to your computer and use it in GitHub Desktop.
<#
More about Feedly API - #The feedly Cloud API - https://developer.feedly.com/
What are the differences with a regular access token?
A developer access token has a longer life than a regular access token: it expire after 30 days (instead of one week).
It can be renewed by feedly pro accounts. It is limited to 250 API requests per day
#>
######################### Global variable #######################################
#Tutaj wprowadź klucz niezbędny do skorzystania z Feedly Cloud API
$global:key = ''
$global:file = "FeedlyRequestLog_$(Get-Date -Format ddMMyyyy).txt"
$global:category
######################### End Global variable ####################################
function Check-FeedlyKey
{
if(-not $global:key)
{
$moreInfo = "How do I generate a developer access token?
Start here - https://feedly.com/v3/auth/dev. After you login with your feedly account, a link will be sent to your account’s email address (or in a Twitter Direct Message).
Follow this link to retrieve your access token. If you logged in with a feedly pro account, the page will also contain a refresh token.
Store this value securely: it enables you to renew an expired access token."
Write-Host "Enter into the $PSCommandPath key to authenticate to the Cloud API feed. `r`n" -ForegroundColor Yellow
Write-Host $moreInfo
}
else
{
return $true
}
}
function Get-FeedlyRequestCount
{
<#
.Synopsis
Pobiera liczbe już wysłanych żądań do Feedly Api
.DESCRIPTION
Umożliwia sprawdzenie ile żądań wysłaliśmy do Feedly Api oraz ile zostało żądań do przekroczenia limitu 250.
Do poprawnego działania modułu niezbędne jest prowadzenie klucza oraz id usera.
Szczegółów dotyczących feedly Cloud API -> https://developer.feedly.com/
.EXAMPLE
Get-FeedlyRequestCount
Api Feedly został odpytany - 2 razy. Pozostało 248.
.LINK
Author: Mateusz Nadobnik
Link: blog.mnadobnik.pl
Date:
Version: 0.0.0.1
Keywords: Feedly Api
Notes:
#>
$fullPath = Join-Path (Split-Path $PSCommandPath) -ChildPath $global:file
if(Test-Path $fullPath)
{
$countRequest = (Get-Content (Join-Path (Split-Path $PSCommandPath) -ChildPath $global:file)).Count
}
else
{
$countRequest = 0
}
Write-Host "Api Feedly został odpytany - $countRequest razy. Pozostało $(250-$countRequest)." -ForegroundColor Yellow
}
function Set-FeedlyCountRequest
{
param($command)
$fullPath = Join-Path (Split-Path $PSCommandPath) -ChildPath $global:file
if(Test-Path $fullPath)
{
Add-Content -Value "$(Get-Date);$command" -Path $fullPath
}
else
{
Get-ChildItem -Path (Split-Path $PSCommandPath) -Filter "*.txt" -Exclude $formatFile | Remove-Item
[void](New-Item -Path $fullPath -Value "$(Get-Date);$command`r`n")
}
}
function Get-FeedlyTags
{
<#
.Synopsis
Pobranie listy tagów z aplikacji Feedly
.DESCRIPTION
Pobranie listy tagów z aplikacji Feedly, wykorzystywana w funkcji Search-FeedlyContent.
.EXAMPLE
[51]: Get-FeedlyTags
id label
-- -----
user/bf8aea46-87b6-454a-a514-56ffb5f52368/tag/Cloud Cloud
user/bf8aea46-87b6-454a-a514-56ffb5f52368/tag/Docker Docker
.EXAMPLE
[138]: Search-FeedlyContent -TagsName 'SQL' -QuerySearch "SPN OR Kerberos"
Origin : http://www.mssqltips.com/
OriginId : http://feedproxy.google.com/~r/MSSQLTips-LatestSqlServerTips/~3/8O7fhVODlhc/tip.asp
Alternate : http://feedproxy.google.com/~r/MSSQLTips-LatestSqlServerTips/~3/8O7fhVODlhc/tip.asp
Title : Script to Check and Auto Generate SPNs for SQL Server
Summary :
LenghtSummary : 195
.LINK
Author: Mateusz Nadobnik
Link: blog.mnadobnik.pl
Date:
Version: 0.0.0.1
Keywords: Feedly Api, Search
Notes:
#>
param(
[string]$key = $global:key
)
begin
{
$Object =@()
}
process
{
if(Check-FeedlyKey)
{
try
{
$category = 'http://cloud.feedly.com/v3/tags'
$results = (Invoke-RestMethod -Uri $category -Headers @{'Authorization'=$key})
#Counter request
Set-FeedlyCountRequest -command "Get-FeedlyTags"
}
catch
{
Write-Host $results
Write-Host ($Error[0] | ConvertFrom-Json).errorMessage -ForegroundColor Yellow
return
}
foreach($result in $results)
{
$Obj = @{} | Select TagsName, TagsStreamId
$Obj.TagsStreamId = (($result.id).Replace('/','%2F')).Replace(' ','%20')
if($result.label)
{
$Obj.TagsName = $result.label
}
else
{
$Obj.TagsName = 'All'
}
$Object += $Obj
}
}
}
end
{
$global:category = $Object
return $Object
}
}
function Search-FeedlyContent
{
<#
.Synopsis
Wyszukiwanie newsów poprzez Feedly API.
.DESCRIPTION
Funkcja umożliwia wyszukiwanie interesującego nas contentu spośród naszych otagowanuch newsów.
Do poprawnego działania modułu niezbędne jest prowadzenie klucza oraz id usera.
Szczegółów dotyczących feedly Cloud API -> https://developer.feedly.com/
.EXAMPLE
[137]: Search-FeedlyContent -TagsName Docker -QuerySearch "copy"
Origin : http://www.sqlservercentral.com/blogs/
OriginId : /blogs/the-dba-who-came-in-from-the-cold/2017/05/10/copying-files-fromto-a-container/
Alternate : http://www.sqlservercentral.com/blogs/the-dba-who-came-in-from-the-cold/2017/05/10/copying-files-fromto
-a-container/
Title : Copying files from/to a container
Summary : <p>Last week I was having an issue with a SQL install within a container and to fix I needed to copy th
e setup log files out of the container onto the host so that I could review.</p>
<p>But how do you copy files out of a containe
LenghtSummary : 7164
Origin : http://www.sqlservercentral.com/blogs/
OriginId : /blogs/the-dba-who-came-in-from-the-cold/2017/05/02/building-a-container-running-sql-server-2014-sp2-de
veloper/
Alternate : http://www.sqlservercentral.com/blogs/the-dba-who-came-in-from-the-cold/2017/05/02/building-a-container
-running-sql-server-2014-sp2-developer/
Title : Building a container running SQL Server 2014 SP2 Developer
Summary : <p>One of the things about working with SQL in Docker is that you kinda have to use the images that are
on the Docker Hub. Now this is great if you want SQL Server 2016 or 2017 but what about earlier versio
ns?</p>
<p>Now, this is
LenghtSummary : 9488
.EXAMPLE
[138]: Search-FeedlyContent -TagsName 'SQL' -QuerySearch "SPN OR Kerberos"
Origin : http://www.mssqltips.com/
OriginId : http://feedproxy.google.com/~r/MSSQLTips-LatestSqlServerTips/~3/8O7fhVODlhc/tip.asp
Alternate : http://feedproxy.google.com/~r/MSSQLTips-LatestSqlServerTips/~3/8O7fhVODlhc/tip.asp
Title : Script to Check and Auto Generate SPNs for SQL Server
Summary :
LenghtSummary : 195
.LINK
Author: Mateusz Nadobnik
Link: blog.mnadobnik.pl
Date:
Version: 0.0.0.1
Keywords: Feedly Api, Search
Notes:
#>
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1)]
[string]$QuerySearch,
[string]$key = $global:key
)
DynamicParam
{
if($global:category)
{
$categoryList = ($global:category).TagsName
}
else
{
try
{
$category = Get-FeedlyTags
$categoryList = ($category).TagsName
}
finally
{
$categoryList = "API rate limit reached"
}
}
$attributes = new-object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = "__AllParameterSets"
$attributes.Mandatory = $true
$attributes.Position = 0
$attributes.ValueFromPipelineByPropertyName = $true
$validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute -ArgumentList $categoryList
$attributeCollection = new-object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributeCollection.Add($attributes)
$attributeCollection.Add($validateSetAttribute)
$dynParam1 = new-object -Type System.Management.Automation.RuntimeDefinedParameter("TagsName", [string], $attributeCollection)
$paramDictionary = new-object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
$paramDictionary.Add("TagsName", $dynParam1)
return $paramDictionary
}
begin
{
if($global:category)
{
$Category = ($global:category | Where TagsName -eq $PsBoundParameters.TagsName).TagsStreamId
}
else
{
$Category = ($category | Where TagsName -eq $PsBoundParameters.TagsName).TagsStreamId
}
}
process
{
try
{
$searchUri = "http://cloud.feedly.com/v3/search/contents?streamId=$Category&query=$querySearch"
$results = (Invoke-RestMethod -Uri $searchUri -Headers @{'Authorization'=$key})
#Counter request
Set-FeedlyCountRequest -command "Search-FeedlyContent"
}
catch
{
Write-Host ($Error[0] | ConvertFrom-Json).errorMessage -ForegroundColor Yellow
}
}
end
{
($results).items | select @{L="Origin";E={$_.origin.htmlUrl}}, `
@{L='OriginId';E={$_.originId}}, `
@{L="Alternate";E={$_.alternate.href}}, `
@{L='Title';E={$_.title}}, `
@{L='Summary';E={
if(($_.summary.content).Length -gt 20)
{
($_.summary.content).Substring(0,230)
}
else
{
($_.summary.content)
}}}, `
@{L='LenghtSummary';E={($_.summary.content).Length }}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment