Socket
Socket
Sign inDemoInstall

afpnews-api

Package Overview
Dependencies
17
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

afpnews-api

Node helper functions to authenticate and fetch AFP News API


Version published
Maintainers
1
Weekly downloads
71
decreased by-33.02%

Weekly downloads

Readme

Source

AfpNews API

Build Status

This project is aimed to help javascript developers use the AFP News API.

It provides authentication, searching for documents function, and online news product.

Getting Started

This package is available both for NodeJS and browsers. That's why two versions are available on the ./dist directory.

Prerequisites

Read the API documentation, and ask for an API Key and credentials.

Installing

Node

npm install --save afpnews-api

const AfpNews = require('afpnews-api')
// OR using import
import AfpNews from 'afpnews-api'
Browser
<script src="./dist/afpnews-api.umd.js"></script>

Let's start using it

// Initialize the API
const afpNews = new AfpNews({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  saveToken: token => {
    // You can eventually save the token to be used later
    console.log(token)
  }
})

// Search for latest documents
afpNews
  .authenticate({
    username: 'YOUR_USERNAME',
    password: 'YOUR_PASSWORD'
  })
  .then(() => afpNews.search())
  .then(({ documents }) => {
    console.log(documents)
  })

// Get a specific document
afpNews
  .get('A_SPECIFIC_UNO')
  .then(document => {
    console.log(document)
  })

// Look for similar documents
afpNews
  .mlt('A_SPECIFIC_UNO')
  .then(({ documents }) => {
    console.log(documents)
  })

// Display the most used slugs
afpNews
  .list('slug')
  .then(({ keywords }) => {
    console.log(keywords)
  })

// Display the available topics for a specific language
afpNews
  .topics('fr')
  .then(({ topics }) => {
    console.log(topics)
  })

// Display the editor's choice for a specific topic
afpNews
  .topicIndex('Sport', 'fr')
  .then(({ documents }) => {
    console.log(documents)
  })

// Display the feed for a specific topic
afpNews
  .topicFeed('Sport', 'fr')
  .then(({ documents }) => {
    console.log(documents)
  })

Query parser

The above request use default parameters stored in ./src/default-search-params.js

You can pass your own parameters to the search function, that will overide the defaults :

afpNews.search({
  products: ['news'],
  langs: ['fr'],
  urgencies: [1, 2, 3, 4],
  query: 'french politics',
  size: 10,
  dateFrom: '2012-01-01',
  dateTo: 'now',
  sortField: 'published',
  sortOrder: 'desc'
})

The query parameter can be used to look precisely for a field (title:Macron) and may include logical parameters (Macron OR Merkel, Macron AND NOT Merkel, title:(Macron OR Merkel) AND country:fra).

Development

Clone the repository, then npm install

Build and minify your work for browsers and node with npm run build

Running the tests

Just npm test to execute all tests in ./tests

You will need some environment variables in a .env file :

AFPNEWS_BASE_URL=
AFPNEWS_API_KEY=
AFPNEWS_CLIENT_ID=
AFPNEWS_CLIENT_SECRET=
AFPNEWS_USERNAME=
AFPNEWS_PASSWORD=
AFPNEWS_CUSTOM_AUTH_URL=https://

Built With

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Keywords

FAQs

Last updated on 02 Dec 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc