cedwardsmedia / everyonephp
Simple Class for querying EveryoneAPI
Requires
- php: >=5.3.0
- guzzlehttp/guzzle: ~6.0
This package is not auto-updated.
Last update: 2024-12-17 05:27:44 UTC
README
STOP
Due to the purchase of EveryoneAPI by Neustar and their refusal to offer any type of hobbyist access to their service, this project is officially discontinued.
Introduction
EveryonePHP is a PHP library for querying EveryoneAPI. The original code was developed as part of CNAM-CLI and webCNAM before being forked into a stand-alone library. If you need a Python module for EveryoneAPI, consider trying EveryoneAPI.py.
In order to use EveryonePHP, you must have an EveryoneAPI account with available funds.
Installation
I highly recommend using Composer to install EveryonePHP for your project. Composer will allow you to automatically install the GuzzleHttp library, which EveryonePHP depends on.
- Install Composer
cd
to your project's directory- Run
composer require cedwardsmedia/everyonephp
- Build your amazing project!
Usage
I have never been a great programmer. As such, I strived to make EveryonePHP as simple to use as possible and I'm always looking to simplify it even more. Let's build a basic EveryoneAPI client using EveryonePHP:
Step 1: Instantiate EveryonePHP as an Object
// Instantiate EveryonePHP $api = new EveryonePHP();
Creating a new EveryonePHP object allows us to interact with the class.
Step 2: Set EveryoneAPI Credentials
// Set EveryoneAPI Credentials $api->sid = "9e3cef42da225d42bd86feaa80ff47"; $api->token = "65f3ef01462c62f7f4ce7d2156ceee";
EveryonePHP needs these credentials in order to query EveryoneAPI. Otherwise, the query will fail. How you obtain and store these credentials is completely up to you, just be sure to set them for each instance of EveryonePHP before calling query()
.
Step 3: Set EveryoneAPI Data Points
// Set EveryoneAPI Data Points $data = array("name", "profile", "cnam", "gender", "image", "address", "location", "line_provider", "carrier", "carrier_o", "linetype");
Each data point is optional and all data points are returned by default, unless otherwise specified. In the same way EveryoneAPI uses a comma separated list of identifiers, EveryonePHP uses a simple array to specify the data points you wish to retrieve. EveryonePHP passes these identifiers directly to EveryoneAPI so you will use the same identifiers here as you would in a cURL request.
For a full list of available Data Points, check the EveryoneAPI Docs.
Step 4: Perform EveryoneAPI Query
// Perform EveryoneAPI query $api->query($phone, $data);
Only $phone
is required for this function. The function performs the query against EveryoneAPI and stores the results in a stdClass object, in this example, $api->results
.
Step 5: Print the Results
// Print results // Print first name echo $api->results->data->expanded_name->first; // Print last name echo $api->results->data->expanded_name->last; // Print carrier name echo $api->results->data->carrier->name;
EveryonePHP converts the JSON response from EveryoneAPI into a stdClass object. This allows us to access the entire response for our application. In the above example, we print the first name, last name, and carrier for the given phone number.
Optional: Error Checking
// Check for Error if ($api->error) { // If there's an error echo "Error: $api->error"; // Print it out exit(1); // Exit with status 1 }
EveryonePHP will assign error messages, if one occurs, to $api->error
. You can use this in an if
statement, as shown above, to halt your application if something has gone wrong.
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request ^^,
Credits
Concept and original codebase: Corey Edwards (@cedwardsmedia)
Optimization and Debugging: Brian Seymour (@eBrian)
License
EveryonePHP is licensed under the BSD Simplified License. See LICENSE for more.
Disclaimer: EveryonePHP is not endorsed by, sponsored by, or otherwise associated with OpenCNAM, EveryoneAPI, or Telo USA, Inc.