Latest 0.1.5
Homepage https://github.com/lucaslimapoa/NewsAPISwift
License MIT
Platforms ios 8.0
Dependencies ObjectMapper
Authors

CI Status
Version
License
Platform

NewsAPISwift is a Swift wrapper around NewsAPI.org, a service that provides articles and headlines from more than 70 sources.

NOTE: This library and its author are not endorsed by or affiliated with NewsApi.org.

Usage

NewsAPI offers two endpoints to which sources and articles can be requested.

Sources

The first endpoint is used for listing all available sources and three parameters can be used to sort the results.

Parameter Description
Category The category you would like to get sources for. The possible values are: business, entertainment, gaming, general, music, politics, scienceAndNature, sport and technology.
Language The language you would like to get sources for. The possible values are: english, deutsch and french.
Country The country you would like to get sources for. The possible values are: australia, germany, unitedKingdom, india, italy and unitedStates.

Example

import NewsAPISwift

let newsAPI = NewsAPI(key: "YourKeyHere")

newsAPI.getSources(category: Category.gaming, language: Language.english, country: Country.unitedStates) { result in
    switch result {
    case .success(let sources):
        // Handle success case
    case .error(let error):
        // Handle error case
    }
}

Articles

The second endpoint is used for listing articles and headlines from a given Source. One parameter can be used for sorting the results.

Parameter Description
SourceId This is the id of the source you want to get articles from. This data is found in NewsAPISource.id.
SortBy The sort type you would like to get the articles. The possible values are: top, latest and popular.

Example

import NewsAPISwift

let newsAPI = NewsAPI(key: "YourKeyHere")

newsAPI.getArticles(sourceId: "SourceId", sortBy: SortBy.popular) { result in
switch result {
    case .success(let articles):
        // Handle success case
    case .error(let error):
        // Handle error case
    }
}

Example Application

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

NewsAPISwift is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "NewsAPISwift"

License

NewsAPISwift is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NewsAPISwift",
    "version": "0.1.5",
    "summary": "NewsAPISwift is a Swift wrapper around NewsAPI.",
    "description": "NewsAPISwift is a Swift wrapper around newsapi.org service, which provides articles from more than 70 sources.",
    "homepage": "https://github.com/lucaslimapoa/NewsAPISwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Lucas Lima": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lucaslimapoa/NewsAPISwift.git",
        "tag": "0.1.5"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "NewsAPISwift/Classes/**/*",
    "dependencies": {
        "ObjectMapper": [
            "~> 2.2"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This