Skip to content

kqarlos/ny-times

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NY Times


Languages Top Language Code Size Repo Size Total Lines Last Commit Issues Followers

Description

Easily search for NY Times articles.

Table of Contents

Installation

This application is compatible with the most commonly used web browsers.

Live Site

Usage

Screeshots

  1. Working Site

Site

  1. Returned articles

Site

Snippets

  1. Search
//Call to build query. Sends query to another function that return the articles according to the query. 
//Calls to render the articles
$("#search").on("click", function () {
    let numberOfRecords = $("#searchFilter [name=numberOfRecords]").val().trim();
    var queryURL = getQuery();
    getArticles(queryURL).then(function (articles) {
        renderArticles(articles, numberOfRecords);
    });
});
    
  • This listerner takes care of th esteps necessary to go from getting the user's information to rendering the articles on the user's web. Calls a functon to build the query. Then with the query it calls a function that will get the articles from the NYT api. Once the articles are ready, they are sent to another function that renders the articles to the HTML.
  1. Query building
//Build query given the users parameters
function getQuery() {
    var queryURL = "https://api.nytimes.com/svc/search/v2/articlesearch.json?";
    let terms = $("#searchFilter [name=term]").val().trim();
    let startYear = $("#searchFilter [name=startYear]").val().trim();
    let endYear = $("#searchFilter [name=endYear]").val().trim();

    var queryParams = { "api-key": "3NYM77KW72ndmEaRDzr2cjaOcabhAIRW" };
    queryParams.q = terms;
    if (parseInt(startYear)) {
        queryParams.begin_date = startYear + "0101";
    }
    if (parseInt(endYear)) {
        queryParams.end_date = endYear + "0101";
    }

    return queryURL + $.param(queryParams);
}
  • This function takes care of building the query. It gets the values from the fields that were filled form the user. These then add to an object of all the necesary parameters for the query. Then, the queryParams object is added to the queryURL with the $.param() function.

Credits

Author

Built With

HMTL CSS Javascript Bootstrap


License

MIT license

About

Search and filter through the New York Times archived records

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published