projectstage / hasoffers-api-wrapper
Make easy API calls against the HasOffers API
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.6
- ext-curl: *
- netresearch/jsonmapper: *
- phpunit/php-code-coverage: *
- phpunit/phpunit: *
This package is not auto-updated.
Last update: 2024-10-18 08:04:37 UTC
README
HasOffers take your performance marketing to the next level. Either you could use their admin panel to setup your marketing campaign and handle everything there (get stats for leads, sales, revenues, clicks, your publisher and so much more ...). But maybe you would like to build your own application to integrate that kind of data within your business flow.
Therefore you can use HasOffers API. This wrapper package hopefully gives you an easy to use set of OOP methods to make your API calls without having too much hassle.
Install
Via Composer
$ composer require projectstage/hasoffers-api-wrapper
Basic Usage
There is no rocket sience. Instantiate a HasOffers client with your authentication data, set some criterias and finally call the API. More information about how to authenticate with the HasOffers API you'll find here: setting-up-api-authentication.
Information about the return field names and values you'll get e.g. for "Offer" here
require_once __DIR__.'/vendor/autoload.php'; // your target controller name $target = 'Offer'; // instantiate HasOffers client $HasOfferClient = new \HasOffersApi\HasOffersClient('YOUR-NETWORK-ID','YOUR-API-KEY'); // setup criteria - here: From which controller you want to call which method $Criteria = new \HasOffersApi\Helper\Criteria($target, 'findAll'); // set the criterias $HasOfferClient->setFilters($Criteria); // finally make the API call // will return a stdClass object $offers = $HasOfferClient->callApi(); // output the HasOffers campaign name foreach($offers as $offer) { echo $offer->{$target}->name."\n"; }
Extend Criteria
andFilter
You can define as many andFilter as you want. Unfortunately a combination of andFilter + orFilter is not possible. From point of development you could notate it like e.g.
$Criteria ->andFilter('name', '%Love%', $Criteria::FILTER_LIKE) ->andFilter('advertiser_id',2) ->orFilter('name', '%live%', $Criteria::FILTER_LIKE);
but the very last entry counts. In the above example the both andFilter will be ignored so the MySql equivalent would look like this:
SELECT * FROM `Offer` WHERE `name` LIKE '%live%';
Assuming the orFilter would be the very first entry than both andFilter are active:
SELECT * FROM `Offer` WHERE `name` LIKE '%Love%' AND `advertiser_id` = 2;
Finally here a short example of using one, or multiple andFilter:
require_once __DIR__.'/vendor/autoload.php'; // your target controller name $target = 'Offer'; // instantiate HasOffers client $HasOfferClient = new \HasOffersApi\HasOffersClient('YOUR-NETWORK-ID','YOUR-API-KEY'); // setup criteria - here: From which controller you want to call which method $Criteria = new \HasOffersApi\Helper\Criteria($target, 'findAll'); // find all offer where field name contains "YOUR-SEARCH-TERM" // MySQL equivalent: SELECT FROM `Offer` WHERE `name` LIKE '%YOUR-SEARCH-TERM%' $Criteria->andFilter('name', '%YOUR-SEARCH-TERM%', $Criteria::FILTER_LIKE); // another example // maybe you would like to use more AND combinations // MySQL equivalent: SELECT FROM `Offer` WHERE `name` LIKE '%YOUR-SEARCH-TERM%' AND `advertiser_id` = 2 $Criteria ->andFilter('name', '%Love%', $Criteria::FILTER_LIKE) ->andFilter('advertiser_id',2); // set the criterias $HasOfferClient->setFilters($Criteria); // finally make the API call $offers = $HasOfferClient->callApi();
orFilter
Here we have the same restricitons as for the andFilter, both you can't combine.
require_once __DIR__.'/vendor/autoload.php'; // your target controller name $target = 'Offer'; // instantiate HasOffers client $HasOfferClient = new \HasOffersApi\HasOffersClient('YOUR-NETWORK-ID','YOUR-API-KEY'); // setup criteria - here: From which controller you want to call which method $Criteria = new \HasOffersApi\Helper\Criteria($target, 'findAll'); // find all offer where field name contains "YOUR-SEARCH-TERM" // MySQL equivalent: SELECT FROM `Offer` WHERE `name` LIKE '%YOUR-SEARCH-TERM%' $Criteria->orFilter('name', '%YOUR-SEARCH-TERM%', $Criteria::FILTER_LIKE); // another example // maybe you would like to use more AND combinations // MySQL equivalent: SELECT FROM `Offer` WHERE `name` LIKE '%YOUR-SEARCH-TERM%' OR `advertiser_id` = 2 $Criteria ->orFilter('name', '%Love%', $Criteria::FILTER_LIKE) ->orFilter('advertiser_id',2); // set the criterias $HasOfferClient->setFilters($Criteria); // finally make the API call $offers = $HasOfferClient->callApi();
conditionalFilter
This filter will be used for reporting tasks. For more information about reports at HasOffer please have look here.
The conditionalFilter does not support orFilter. Even if you could notate:
$Criteria ->conditionalFilter('expiration_date', ['2017-10-01', '2017-10-31'], $Criteria::FILTER_BETWEEN) ->orFilter('name', '%live%', $Criteria::FILTER_LIKE);
the orFilter part will be ignored.
Criteria FILTER list
Criteria::FILTER_OR; Criteria::FILTER_NOT_EQUAL_TO; Criteria::FILTER_LESS_THAN; Criteria::FILTER_LESS_THAN_OR_EQUAL_TO; Criteria::FILTER_GREATER_THAN; Criteria::FILTER_GREATER_THAN_OR_EQUAL_TO; Criteria::FILTER_LIKE; Criteria::FILTER_NOT_LIKE; Criteria::FILTER_NULL; Criteria::FILTER_NOT_NULL; Criteria::FILTER_TRUE; Criteria::FILTER_FALSE; // used for contitioanlFilter Criteria::FILTER_EQUAL_TO; Criteria::FILTER_BETWEEN;
HasOffers client settings
setFields
Setting some fields means basically that your response should only return the specified fields, not more. The MySql equivalent would look like this:
SELECT `advertiser_id`, `name`, `preview_url`, `offer_url` FROM `Offer`;
$fields = [ 'advertiser_id', 'name', 'preview_url', 'offer_url' ]; $HasOfferClient->setFields($fields);
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email author instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.