PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Sergii Pryz   NASA Near Earth Orbit API Client   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: NASA Near Earth Orbit API Client
Get near Earth orbit object data with NASA API
Author: By
Last change: Updated changelog, added link to symfony integration example in readme
Date: 8 years ago
Size: 6,928 bytes
 

Contents

Class file image Download

NeoWsClient

PHP 7 ready Latest Stable Version License SensioLabsInsight

Master

Build Status Coverage Status

Dev

Build Status Coverage Status

NeoWsClient - client for NASA Open Api "Near Earth Object Web Service" or NeoWs in short. All NeoWs data is from the NASA JPL Asteroid team.

NeoWsClient supports NeoWs v1 with resources:

  • feed
  • neo
  • stats

Requirements

Installation

Update to your composer.json with:

{
    "require": {
        "picamator/neo-ws-client": "~1.0"
    }
}

Examples

To run examples please create parameters.yml in config directory using as a template parameters.yml.dist. The DEMO_KEY is a valid api token. It has limitation as requests per hour, per day. More information in NASA official documentation.

Example list:

Arbitrary precision math

NeoWsClient formats only Date to DateTime object all others keeps original API's. NeoWs uses string for long precision float like e.g. .6304873017364636 execution floatval on them would removes last two digits. Therefore NeoWsClient does not convert strings to int or float. To make any math with string floats please use BCMath. BCMath takes care of arbitrary precision mathematics.

Technical specification

That section describes extension and configuration points.

Dependency injection

NeoWsClient uses Symfony DI. It's configuration in services.yml.

Data mapping

NeoWsClient works with data mapping to create objects based on Api response. To make customization or build objects from API response it's need to create mapper repository object. Mapper repository object is a simple data storage over schema with implementation Mapper\Api\RespositoryInterface.

The schema contains:

Name | Is required | Description --- | --- | --- source | yes | Key in API response destination | yes | Property inside NeoWsClient value object destinationContainer | yes | Name of NeoWsClient object where destination property is located schema | no | Sub schema collectionOf | no | Interface name of NeoWsClient objects that will be present inside collection. It's an interface of destinationContainer in sub-schema. filter | no | Name of NeoWsClient filter object, it runs over API's data

Errors

There are three different error types:

  • Response HTTP codes: 401, 403, 404
  • Response HTTP code 200 with empty body
  • Exception

Response HTTP codes: 401, 403, 404

In case of getting HTTP codes: 401, 403, 404 or any unsuccessful one application return empty response. Empty response means valid Response object where:

  • code: is a http code
  • data: `stdClass` over body response string
  • rateLimit: valid rate limit object with data if they are present in API's header

Response HTTP code 200 with empty body

If API returns empty body with HTTP code 200 with several simultaneously requests. The NeoWsClient Manager rise exception ManagerException in that case. Because HTTP code 200 means OK, but body is wrong therefore NeoWsClient can not distinguish valid/invalid data by HTTP code.

That exception SHOULD be catch without putting any logic like resend, wait 3 sec. then resend again etc. Instead it's better to have cache over API.

Exception

The full exception list that NeoWsClient rises is in Exception folder. If exception rise it means that application can not proceed request, it does not have any business logic in it.

Documentation

Developing

To configure developing environment please:

  1. Follow Docker installation steps
  2. Run inside Docker container `composer install`

Contribution

If you find this project worth to use please add a star. Follow changes to see all activities. And if you see room for improvement, proposals please feel free to create an issue or send pull request. Here is a great guide to start contributing.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project and its community you agree to abide by those terms.

License

NeoWsClient is licensed under the MIT License. Please see the LICENSE file for details.