Code Monkey home page Code Monkey logo

astrology-sdk's Introduction

Getting Started with Prokerala Astrology API

Prokerala Astrology SDK provides convenient access to Prokerala Astrology API for applications developed in PHP. Prokerala API integration helps you generate custom horoscope, perform horoscope matching, check mangal dosha, panchang and much more.

We have open sourced the code for our API demo at prokerala/astrology-api-demo.

Requirements

PHP needs to be a minimum version of PHP 8.0

Installation

If you prefer to work with the JSON response directly, please checkout our dependency free minimal PHP Client example that calls the API directly.

Using composer (recommended)

This is the recommended method for installation of the SDK.

Quick Installation

If you have composer already installed, and just want to get started quickly, the following command will install the SDK and its dependencies:

composer require prokerala/astrology-sdk:^1.0 nyholm/psr7 guzzlehttp/guzzle symfony/cache

That's it. The SDK is now ready to use. You can skip to the Usage section below.

Detailed Instructions

If you do not have composer already installed, you can install it with the following command.

curl -sS https://getcomposer.org/installer | php

The current version of the SDK no longer ships with an HTTP client, instead depends on external implementations of PSR-17 (HTTP Message factory) and PSR-18 (HTTP client). You may choose any implementation of PSR-17 and PSR-18, for example, the following command installs nyholm/psr7 for PSR-17 and Guzzle HTTP client for PSR-18.

composer require nyholm/psr7 guzzlehttp/guzzle

Optionally, you can pass an implementation of PSR-16 Simple Cache interface for caching the access token and responses. As before, you can choose any implementation of PSR-16. The following command will install symfony/cache.

composer require symfony/cache

Now that you have all the dependencies installed, install the SDK by running the following command.

composer require prokerala/astrology-sdk:^1.0

Manual Installation

If you are not using composer, download the latest release from the releases section. You should download the zip file. After that include autoload.php in your application and you can use the API as usual.

For further help, Please visit our documentation

Usage

This SDK is powering our API demo page. The source code of the demos are open source and available on a separate GitHub repostiory.

<?php

use Prokerala\Api\Astrology\Location;
use Prokerala\Api\Astrology\Service\MangalDosha;
use Prokerala\Common\Api\Authentication\Oauth2;
use Prokerala\Common\Api\Client;
use Prokerala\Common\Api\Exception\QuotaExceededException;
use Prokerala\Common\Api\Exception\RateLimitExceededException;

# Include composer autoloader
include __DIR__.'/vendor/autoload.php';

# Create the PSR-17 Factory. The following line creates a PSR-17 factory using
# nyholm/psr7. If you are using a different implementation, update accordingly.
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();

# Create the PSR-18 HTTP Client
$httpClient = new \GuzzleHttp\Client();

# Create the PSR-16 Cache. Even though the cache parameter is optional, it is
# highly recommended to pass a cache to Oauth2, to improve performance.
$cache = new \Symfony\Component\Cache\Psr16Cache(
    new \Symfony\Component\Cache\Adapter\FilesystemAdapter()
);

$authClient = new Oauth2('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', $httpClient, $psr17Factory, $psr17Factory, $cache);

$client = new Client($authClient, $httpClient, $psr17Factory);
$input = [
    'datetime' => '1967-08-29T09:00:00+05:30',
    'latitude' => '19.0821978',
    'longitude' => '72.7411014', // Mumbai
];

$datetime = new DateTime($input['datetime']);
$tz = $datetime->getTimezone();

$location = new Location($input['latitude'], $input['longitude'], 0, $tz);

try {
    $method = new MangalDosha($client);
    $result = $method->process($location, $datetime);

    $mangalDoshaResult = [
        'has_mangal_dosha' => $result->hasDosha(),
        'description' => $result->getDescription(),
    ];

    print_r($mangalDoshaResult);
} catch (QuotaExceededException $e) {
} catch (RateLimitExceededException $e) {
}

Please check out our API Demo for a sample implementation using the SDK. The source code for the demo is available under the GitHub repository prokerala/astrology-api-demo.

License

Copyright © 2019-2022 Ennexa Technologies Private Limited. The Prokerala Astrology API PHP SDK is released under the MIT License.

astrology-sdk's People

Contributors

abhishek-rao-kr avatar abintabraham123 avatar akhilp-dev avatar ananthalakshmig avatar anjususanpadiyara avatar chinnukunjumon avatar joycebabu avatar vimalkumarvs avatar vishnu-ennexa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

astrology-sdk's Issues

Errors parsing results using docced exampl for planets

[Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$id in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 54 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$id in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 55 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined index: in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 55 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$longitude in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 56 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$is_reverse in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 57 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$position in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 58 [Thu Oct 24 20:00:35.403369 2019] [php7:notice] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Notice: Undefined property: stdClass::$degree in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\vendor\\prokerala\\astrology-sdk\\src\\Api\\Astrology\\Result\\Planet.php on line 59 [Thu Oct 24 20:00:35.404367 2019] [php7:error] [pid 2868:tid 1300] [client 127.0.0.1:53555] PHP Fatal error: Uncaught Error: Cannot use object of type Prokerala\\Api\\Astrology\\Result\\Planet as array in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\index.php:91\nStack trace:\n#0 {main}\n thrown in C:\\dev\\www\\bfclocal\\public_html\\mooncalc\\index.php on line 91

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.