2017 © Pedro Peláez
 

library php-randomorg-draws

PHP Random.org draws

image

naffiq/php-randomorg-draws

PHP Random.org draws

  • Tuesday, July 4, 2017
  • by naffiq
  • Repository
  • 1 Watchers
  • 1 Stars
  • 411 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 6 % Grown

The README.md

PHP Random.org Draws API

Build Status Test Coverage Code Climate, (*1)

This library helps you with connecting your app to Random.org's Third-Party Draws service., (*2)

Installation

Preferable way to install this package is through composer:, (*3)

$ composer require naffiq/php-randomorg-draws

Usage

You have to register random.org account and provide login/password to \naffiq\randomorg\DrawService constructor. Then you can create draws via \naffiq\randomorg\DrawService::newDraw() method, which will spawn an object of \naffiq\randomprg\Draw., (*4)

<?php

$service = new \naffiq\randomorg\DrawService('random.org_login', 'random.org_password');
$draw = $service->newDraw(
    'Title',                                    // Name of the draw
    1,                                          // ID of created draw, which will be passed to random.org
    ['user_1@email.com', 'user_2@email.com'],   // You can provide any unique identifiers of your participants
    1,                                          // Winners count 
    'test'                                      // Use 'private' or 'public' in production
    );

$draw->pushEntry('user_3@email.com'); // Adds new entry

To start draw run \naffiq\randomorg\DrawService::holdDraw() method with created $draw. In result you will get instance of \naffiq\randomorg\DrawResponse class., (*5)

<?php

/**
 * @var $service \naffiq\randomorg\DrawService
 * @var $draw \naffiq\randomorg\Draw
 */
$response = $service->holdDraw($draw);

var_dump($response->getWinners()); // Will output all winners of created draw

Handling API errors

Any error, that was generated by Random.org API is thrown as an instance of \naffiq\randomorg\DrawException. It passes error code and message as well as additional data, which is accessible via \naffiq\randomorg\DrawException::getData() method., (*6)

Contributing and testing

Any contribution is highly welcomed. If you want to run tests provide RANDOMORG_LOGIN and RANDOMORG_PASSWORD environment variables. They can be automatically initialized them from .env file. Just specify them as follows: ```.env RANDOMORG_LOGIN=your_random_org_login RANDOMORG_PASSWORD=your_random_org_password, (*7)


And run ```bash $ phpunit

The Versions

04/07 2017

dev-master

9999999-dev

PHP Random.org draws

  Sources   Download

MIT

The Requires

 

The Development Requires

04/07 2017