What is it?

EveryonePHP is a simple PHP class for querying the EveryoneAPI service and returning the results. It uses Guzzle to create the request and makes the JSON response available to your application as a stdClass object. This makes handling the results even easier than working with arrays!

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.

  1. Install Composer
  2. cd to your project's directory
  3. Run composer require cedwardsmedia/everyonephp
  4. Build your amazing project!

Getting Started

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. The best way to explain how it works is to simply try it out. Let's build a basic EveryoneAPI client in five easy steps 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().

Note 1: During development, you may use phone number +1 (555) 123-4567 to test your code as EveryoneAPI provides this number for testing purposes. The API will answer queries on this number without setting credentials.

Note 2: EveryoneAPI does not currently provide a method for verifying API credentials. For now, the workaround to this is to query the API for the cheapest data point and check for the success of the 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. Keep in mind that not all errors are fatal. Therefore, you may get all of the data points you requested back from the server, and an error may have still occurred, so it is wise to always check this property after performing a query.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. 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 3-Clause License. See LICENSE for more.


Disclaimer: EveryonePHP is not endorsed by, sponsored by, or otherwise associated with OpenCNAM, EveryoneAPI, or Telo USA, Inc.