newsapi_client 0.2.5+2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 88

Newsapi client for dart #

A client for the newsapi.org API written in dart.

Endpoints #

Top headlines #

import 'package:newsapi_client/newsapi_client.dart';

class News {

  final client = NewsapiClient('YOUR API KEY');

  // Get the latest business headlines.
  Future<Map<String, dynamic>> topBusiness() async {
    final response = await client.request(TopHeadlines(
      category: Categories.business,
    ));
    return response;
  }

  [...]

Everything #

  [...]

  // Get all articles with keyword: Microsoft from 2019-02-01 to now.
  Future<Map<String, dynamic>> everythingMicrosoft() async {
    final response = await client.request(Everything(
      query: 'Microsoft',
      from: DateTime.parse('2019-02-01'),
      to: DateTime.now(),
    ));
    return response;
  }

  [...]

Sources #

  [...]

  // Get all norwegian sources.
  Future<Map<String, dynamic>> norwegianSources() async {
    final response = await client.request(Sources(
      country: Countries.norway,
    ));
    return response;
  }

}

Changelog #

0.2.5 - 2019-02-08 #

Added #

  • Added a few tests for the pageSize and page parameters.
  • Endpoint object can now be accessed.

0.2.4 - 2019-02-05 #

Added #

  • Added missing pageSize and page parameters to TopHeadlines endpoint.
  • Added missing excludeDomains parameter to Everything endpoint.
  • Added documentation to Sources endpoint parameters.
  • Added documentation to TopHeadlines endpoint parameters.
  • Added documentation to Everything endpoint parameters.
  • Added tests for all the different endpoints and their parameters.

Changed #

  • The API key is now delivered over an HTTP header instead of being a url-parameter.

Deprecated #

  • Removed language parameter from TopHeadlines endpoint. It didn't work in the first place, so this shouldn't affect anything.

0.2.2 - 2019-02-03 #

Added #

  • Added new examples to README from ./example/example.dart.

Changed #

  • Updated ./example/example.dart with more, better examples.

Fixed #

  • Fixed parameters not being encoded correctly when handling enums or null values.
  • Fixed apiKey not being added correctly to the final url.

0.2.1 - 2019-02-01 #

Added #

  • Added contributing guide.
  • Added license.

Changed #

  • Changed tests so that they work with with the updated NewsapiClient.

0.2.0 - 2019-02-01 #

Added #

  • Generated dartdoc documentation.

Changed #

  • Changed the way requesting works to make it easier to read and write.

0.1.0 - 2019-01-31 #

Added #

  • Added client functionality.
  • Added country constants.
  • Added category constants.

example/example.dart

import 'package:newsapi_client/newsapi_client.dart';

class News {
  final client = NewsapiClient('YOUR API KEY');

  // Get the latest business headlines.
  Future<Map<String, dynamic>> topBusiness() async {
    final response = await client.request(TopHeadlines(
      category: Categories.business,
    ));
    return response;
  }

  // Get all articles with keyword: Microsoft from 2019-02-01 to now.
  Future<Map<String, dynamic>> everythingMicrosoft() async {
    final response = await client.request(Everything(
      query: 'Microsoft',
      from: DateTime.parse('2019-02-01'),
      to: DateTime.now(),
    ));
    return response;
  }

  // Get all norwegian sources.
  Future<Map<String, dynamic>> norwegianSources() async {
    final response = await client.request(Sources(
      country: Countries.norway,
    ));
    return response;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  newsapi_client: ^0.2.5+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:newsapi_client/newsapi_client.dart';
  
Version Uploaded Documentation Archive
0.2.5+2 Feb 8, 2019 Go to the documentation of newsapi_client 0.2.5+2 Download newsapi_client 0.2.5+2 archive
0.2.5+1 Feb 8, 2019 Go to the documentation of newsapi_client 0.2.5+1 Download newsapi_client 0.2.5+1 archive
0.2.5 Feb 8, 2019 Go to the documentation of newsapi_client 0.2.5 Download newsapi_client 0.2.5 archive
0.2.4 Feb 5, 2019 Go to the documentation of newsapi_client 0.2.4 Download newsapi_client 0.2.4 archive
0.2.3 Feb 4, 2019 Go to the documentation of newsapi_client 0.2.3 Download newsapi_client 0.2.3 archive
0.2.2 Feb 3, 2019 Go to the documentation of newsapi_client 0.2.2 Download newsapi_client 0.2.2 archive
0.2.1 Feb 1, 2019 Go to the documentation of newsapi_client 0.2.1 Download newsapi_client 0.2.1 archive
0.2.0 Feb 1, 2019 Go to the documentation of newsapi_client 0.2.0 Download newsapi_client 0.2.0 archive
0.1.4 Jan 31, 2019 Go to the documentation of newsapi_client 0.1.4 Download newsapi_client 0.1.4 archive
0.1.3 Jan 31, 2019 Go to the documentation of newsapi_client 0.1.3 Download newsapi_client 0.1.3 archive

All 13 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
76
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Apr 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:newsapi_client/newsapi_client.dart.

Health suggestions

Fix lib/src/client.dart. (-0.50 points)

Analysis of lib/src/client.dart reported 1 hint:

line 8 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/endpoint.dart. (-0.50 points)

Analysis of lib/src/endpoint.dart reported 1 hint:

line 11 col 3: The class 'Future' was not exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/util/build_url.dart. (-0.50 points)

Analysis of lib/src/util/build_url.dart reported 1 hint:

line 1 col 38: Don't explicitly initialize variables to null.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.8.0 <3.0.0
http ^0.12.0 0.12.0+2
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.7
path 1.6.2
pedantic 1.5.0
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
test ^1.5.1