adrianmejias/factom-api

A simple Laravel service provider for the Factom API.

v1.4 2017-09-21 22:35 UTC

This package is auto-updated.

Last update: 2024-04-06 23:12:06 UTC


README

Latest Version Software License Build Status Quality Score StyleCI Total Downloads

This package provides a simple service provider for the Factom API for use with the Laravel Framework.

Factom API documentation: https://docs.factom.com/api

Note: This package is under development and should not be used for production environments.

Installation

You can install this package via composer using:

composer require adrianmejias/factom-api

You must also install this service provider in conifg/app.php.

'providers' => [
  ...
  
  AdrianMejias\FactomApi\FactomApiServiceProvider::class,
  
  ...

The package will automatically register itself. If not, then add the alias in config/app.php.

'aliases' => [
  ...
  
  'FactomApi' => AdrianMejias\FactomApi\Facades\FactomApi::class,
  'FactomWalletApi' => AdrianMejias\FactomApi\Facades\FactomWalletApi::class,
  'FactomDebugApi' => AdrianMejias\FactomApi\Facades\FactomDebugApi::class,
  
  ...

To publish the config file to app/config/factom-api.php

php artisan vendor:publish --provider="AdrianMejias\FactomApi\FactomApiServiceProvider"

This will publish a file factom-api.php in your config directory with teh following content:

<?php

return [
  
  /**
   * Base credentials for Factom server.
   */
  'url' => env('FACTOM_URL', 'http://localhost:8088/v2'),

  'ssl' => [
    'enable' => env('FACTOM_SSL', false),
    'certificate' => env('FACTOM_CERTIFICATE', storage_path('app/factomdAPIpub.cert')),
  ],

  'username' => env('FACTOM_USERNAME'),

  'password' => env('FACTOM_PASSWORD'),

  /**
   * Factom wallet server credentials.
   */
  'wallet' => [
    'url' => env('FACTOM_WALLET_URL', 'http://localhost:8089/v2'),

    'ssl' => [
      'enable' => env('FACTOM_WALLET_SSL', false),
      'certificate' => env('FACTOM_WALLET_CERTIFICATE', storage_path('app/factomdAPIpub.cert')),
    ],

    'username' => env('FACTOM_WALLET_USERNAME'),

    'password' => env('FACTOM_WALLET_PASSWORD'),
  ],

  /**
   * Factom debug server credentials.
   */
  'debug' => [
    'url' => env('FACTOM_DEBUG_URL', 'http://localhost:8088/debug'),

    'ssl' => [
      'enable' => env('FACTOM_DEBUG_SSL', false),
      'certificate' => env('FACTOM_DEBUG_CERTIFICATE', storage_path('app/factomdAPIpub.cert')),
    ],

    'username' => env('FACTOM_DEBUG_USERNAME'),

    'password' => env('FACTOM_DEBUG_PASSWORD'),
  ],

];

Usage

After you've installed the package and filled in the values in the config-file working with this pacakge will be a breeze. All the following examples use the facade.

Route::get('/factom/heights', function() {
  $result = FactomApi::heights();

  return response()->json($result);
});

Todo

  • Replace Curl with Guzzle
  • Add Wallet methods
  • Add certificate auth
  • Add unit tests

Testing

Run the tests with:

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email adrianmejias@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.