ballerinax/nytimes.topstories Ballerina library

1.5.1

Overview

This is a generated connector from New York Times Top Stories API v2.0.0 OpenAPI specification. With the New York Times Top Stories API you can get articles currently on a section front or home page. The Top Stories API returns an array of articles currently on the specified section (arts, business, ...). The possible section value are: arts, automobiles, books, business, fashion, food, health, home, insider, magazine, movies, nyregion, obituaries, opinion, politics, realestate, science, sports, sundayreview, technology, theater, t-magazine, travel, upshot, us, and world.

Prerequisites

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

Quickstart

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

Step 1: Import connector

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

Copy
import ballerinax/nytimes.topstories as nt;

Step 2: Create a new connector instance

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

Copy
nt:ApiKeysConfig config = {
    apiKey: "<API_KEY>"
}
nt: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 look up top stories using the connector. You can now get an array of articles currently on the specified section (arts, business, ...). Here we have searched for top stories in the world section. The possible section value are: arts, automobiles, books, business, fashion, food, health, home, insider, magazine, movies, nyregion, obituaries, opinion, politics, realestate, science, sports, sundayreview, technology, theater, t-magazine, travel, upshot, us, and world.

    Look up top stories

    Copy
    public function main() {
        nt:InlineResponse200|error response = baseClient->topStories("world", "json");
        if (response is nt:InlineResponse200) {
            nt:Article[]? articles = response?.results;
            if !(articles is ()) {
                foreach var article in articles {
                    log:printInfo(article?.'abstract.toString() + "\n");
                }
            }
        } else {
            log:printError(response.toString());
        }
    }

    Following is an example on how to look up top stories on home page using the connector. You can now get articles currently on the homepage. Here we have searched for articles with the word "home".

    Look up top stories on home page

    Copy
    public function main() {
        nt:InlineResponse200|error response = baseClient->topStories("home", "json");
        if (response is nt:InlineResponse200) {
            nt:Article[]? articles = response?.results;
            if !(articles is ()) {
                foreach var article in articles {
                    log:printInfo(article?.'abstract.toString() + "\n");
                }
            }
        } else {
            log:printError(response.toString());
        }
    }
  2. Use bal run command to compile and run the Ballerina program.

Import

import ballerinax/nytimes.topstories;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...