Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7f2f1f39ff
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 38 lines (28 sloc) 0.955 kb
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
param($query = "Obama")

$apiKey = "e91adfa87e8f8026712c4d92b54a0b14:0:39364737"

function Get-SemanticNYT {

    param($query)

    $uri = "http://api.nytimes.com/svc/semantic/v2/"+
        "concept/search.json?query=$query&api-key=$apiKey"

    (Invoke-RestMethod $uri).results
}

function Get-SemanticNYTArticles {

    param(
        [Parameter(ValueFromPipelineByPropertyName=$true)]
        $concept_name,
        [Parameter(ValueFromPipelineByPropertyName=$true)]
        $concept_type
    )

    process {
      $uri = "http://api.nytimes.com/svc/semantic/v2/" +
      "concept/name/$concept_type/$concept_name.json?&" +
      "fields=all&api-key=$apiKey"

      (Invoke-RestMethod $uri).results
    }
}

Get-SemanticNYT $query |
    Get-SemanticNYTArticles |
    Where links |
        Select -ExpandProperty article_list |
        Select -ExpandProperty results |
        Select date, title, url| Out-GridView
Something went wrong with that request. Please try again.