picamator / neo-ws-client
Client for NASA Open Api: Near Earth Object Web Service
Requires
- php: ~5.6|~7.0
- guzzlehttp/guzzle: ~6.2
- psr/http-message: ~1.0
- symfony/config: ~2.8 || ~3.1
- symfony/dependency-injection: ~2.8 || ~3.1
- symfony/proxy-manager-bridge: ~2.8 || ~3.1
- symfony/yaml: ~2.8 || ~3.1
Requires (Dev)
- phpdocumentor/phpdocumentor: ~2.0
- phpunit/phpunit: ~5.5
- satooshi/php-coveralls: ~1.0
This package is not auto-updated.
Last update: 2024-11-09 20:56:29 UTC
README
Master
Dev
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:
- Statistics: GET /rest/v1/stats
- Neo: GET /rest/v1/neo/{asteroid_id}
- Neo browse: GET /rest/v1/neo/browse
- Feed: GET /rest/v1/feed
- Feed detailed: GET /rest/v1/feed
- Feed today: GET /rest/v1/feed/today
- Feed today detailed: GET /rest/v1/feed/today
- Wrong resource 404: GET /rest/v1/wrong-resource
- Wrong api token 403: GET /rest/v1/wrong-resource
- Symfony 2.8 integration: NeoWsExample
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:
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
- UML class diagram: class.diagram.png
- Generated documentation: phpdoc, please build it following instruction
Developing
To configure developing environment please:
- Follow Docker installation steps
- 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.