ballerinax/nytimes.archive Ballerina library

1.5.1

Overview

This is a generated connector for New York Times Archive API v1.0.0 OpenAPI specification. With the New York Times Archive API you can get all NYTimes article metadata for a given month. The Archive API returns an array of NYT articles for a given month, going back to 1851. Its response fields are the same as the Article Search API. The Archive API is very useful if you want to build your own database of NYT article metadata. You simply pass the API the year and month and it returns all articles for that month. The response size can be large (~20mb).

Prerequisites

Before using this connector in your Ballerina application, complete the following:

Quickstart

To use the New York Times TimesTags connector in your Ballerina application, update the .bal file as follows:

Step 1: Import connector

First, import the ballerinax/nytimes.archive module into the Ballerina project.

Copy
import ballerinax/nytimes.archive as na;

Step 2: Create a new connector instance

Create a archive:ApiKeysConfig with the API key obtained, and initialize the connector with it.

Copy
na:ApiKeysConfig config = {
    apiKey: "<API_KEY>"
}
na:Client baseClient = check new Client(config);

Step 3: Invoke connector operation

  1. Now you can use the operations available within the connector. Note that they are in the form of remote operations.

    Following is an example on how to get all article metadata for a given month and year using the connector.

    Get all article metadata for a given month and year

    Copy
    public function main() {
        na:InlineResponse200|error response = baseClient->getArticles(2021, 1);
        if (response is na:InlineResponse200) {
            log:printInfo(response.toString());
        } else {
            log:printError(response.message());
        }
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/nytimes.archive;Copy

Metadata

Released date: 12 months ago

Version: 1.5.1

License: Apache-2.0


Compatibility

Platform: any

Ballerina version: 2201.4.1

GraalVM compatible: Yes


Pull count

Total: 0

Current verison: 0


Weekly downloads


Source repository


Keywords

Lifestyle & Entertainment/News & Lifestyle

Cost/Free


Contributors

Other versions

See more...