2017 © Pedro Peláez
 

library unitconvert-laravel

UnitConvert API Wrapper for Laravel

image

devsquared/unitconvert-laravel

UnitConvert API Wrapper for Laravel

  • Thursday, March 8, 2018
  • by Failcookie
  • Repository
  • 2 Watchers
  • 1 Stars
  • 150 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 582 % Grown

The README.md

Convert/Compare Units of Measurement in Laravel

Latest Version GitHub license, (*1)

With the UnitConvert.io wrapper for Laravel, you can quickly and easily compare and convert units of measurement programmatically., (*2)

This package was created and developer by DevSquared - a consultant and development agency located in Pittsburg, KS, USA. Check out our website to learn more information about us., (*3)

Installation

UnitConvert requires an API key to use this wrapper. You can sign up for a free account today and get started. This package can be installed through Composer., (*4)

composer require devsquared/unitconvert-laravel, (*5)

In Laravel 5.5 and above, the package will autoregister the provider and the alias. For Laravel 5.4 and below, you must install the provider and the alias., (*6)

// config/app.php
'providers' => [
    ...
    DevSquared\UnitConvert\UnitConvertProvider::class,
    ...
];

'aliases' => [
    ...
    'UnitConvert' => DevSquared\UnitConvert\UnitConvertFacade::class,
    ...
];

Next, you will need to add your API key to the config. You can add it to your .env file as, (*7)

UNITCONVERT_API_KEY=, (*8)

Optionally, you can publish the config file of this package with this command:, (*9)

php artisan vendor:publish --provider="DevSquared\UnitConvert\UnitConvertServiceProvider", (*10)

Usage

The UnitConvert database contains variants as people use the system. Commonly misspellings, abbreviations, and full words are all excepted strings in addition to the measurement value. Below is an example of how to compare and convert a unit of measurement(s)., (*11)

```$xslt use UnitConvert;, (*12)

// Get Information for a Unit of Measurement $response = UnitConvert::getMeasurementInfo('20 miles'); $response->getSuccess(); // Returns true $response->getError(); // Returns the response error message, if success is false $response->getAmount(); // Returns 20 $response->getUnit(); // Returns "Miles" $response->getDisplay(); // Returns "20 Miles" $response->getCategory(); // Returns "Length" $response->getVariants(); // Returns ["Mile","Miles","mi"] $response->getConvertableTo(); // Returns ["Centimeters","Millimeters","Meters","Inches","Feet","Yards","Miles","Decimeters","Kilometers","Astronomical Units","Light Years","Parsecs","Nautical Miles"], (*13)

// Comparing a Measurement $response = UnitConvert::compare('10mg', '==', '10 pounds'); $response->getSuccess(); // Returns true $response->getError(); // Returns the response error message, if success is false $response->getResult(); // Returns false, (*14)

// Converting a Measurement $response = UnitConvert::convert('20 miles', 'kilometers'); $response->getSuccess(); // Returns true $response->getError(); // Returns the response error message, if success is false $response->getAmount(); // Returns 32.1868 $response->getUnit(); // Returns "Kilometers" $response->getDisplay(); // Returns "32.18680 Kilometers", (*15)


Here is an example use case for the `convert` function:

$response = UnitConvert::convert('20 miles', 'gallons'); if ($response->getSuccess() == false) { return $response->getError(); }, (*16)

return $response->getDisplay(); ```, (*17)

Changelog

Please see the changelog for more information on what has changed recently., (*18)

Using this? Let us know!

We really enjoy seeing our work being used in production environments. If you decide to implement this wrapper, feel free to let us know and share your work. You can send us an email on our website: https://dev-squared.com, (*19)

License

The MIT License (MIT). Please see the License File for more information., (*20)

The Versions

08/03 2018

dev-master

9999999-dev https://unitconvert.io

UnitConvert API Wrapper for Laravel

  Sources   Download

MIT

The Requires

 

by Caleb Smith
by John Kuefler

laravel unit conversion unitconvert convert measurements

06/03 2018

0.2.2

0.2.2.0 https://unitconvert.io

UnitConvert API Wrapper for Laravel

  Sources   Download

MIT

The Requires

 

by Caleb Smith
by John Kuefler

laravel unit conversion unitconvert convert measurements

06/03 2018

0.2.1

0.2.1.0 https://unitconvert.io

UnitConvert API Wrapper for Laravel

  Sources   Download

MIT

The Requires

 

by Caleb Smith
by John Kuefler

laravel unit conversion unitconvert convert measurements

06/03 2018

0.1.0

0.1.0.0 https://unitconvert.io

UnitConvert API Wrapper for Laravel

  Sources   Download

MIT

The Requires

 

by Caleb Smith
by John Kuefler

laravel unit conversion unitconvert convert measurements