item8 / hasoffers-sdk
ORM/SDK for HasOffers API
Installs: 1 246
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=7.0
- jbzoo/data: ^1.6.1|^2.0
- jbzoo/event: ^1.4
- jbzoo/http-client: ^1.2
- jbzoo/utils: ^2.0
Requires (Dev)
- item8/codestyle: ^2.0
- jbzoo/profiler: ^1.0
- dev-master
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.3
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-feature/ho-integrator-api
- dev-develop
This package is not auto-updated.
Last update: 2020-05-20 00:08:31 UTC
README
ORM/SDK for HasOffers API (Network and Integrator endpoints).
SDK built by item8 - CRM&Billing SaaS for Advertising Networks. Free to use for developing add-ons and integrations for HasOffers by TUNE.
Code Examples
Talk is cheap. Show me the code.
Client Initialization
use Item8\HasOffers\Request\ClientApi; use Item8\HasOffers\Request\IntegratorApi; // Classical API $hoClient = new ClientApi(); $hoClient->setAuth('__NETWORK_ID__', '__NETWORK_TOKEN__'); // New Integrator API $hoClient = new IntegratorApi(); $hoClient->setAuth('__NETWORK_ID__', '__INTEGRATOR_SECRET__', '__INTEGRATOR_ID__');
Usage
<?php // Get needed classes use Item8\HasOffers\Exception; use Item8\HasOffers\Entity\AbstractEntity; use Item8\HasOffers\Entity\Affiliate; use Item8\HasOffers\Entity\AffiliateInvoice; use Item8\HasOffers\Request\ClientApi; use Item8\HasOffers\Contain\PaymentMethod; use Item8\HasOffers\Contain\AffiliateInvoiceItem; use JBZoo\Event\EventManager; use JBZoo\Event\ExceptionStop; // Init HasOffers Client try { // Init HasOffers Client $hoClient = new ClientApi(); $hoClient->setAuth('networkId', 'token'); $eManager = new EventManager(); $hoClient->setEventManager($eManager); // Sleep 10 seconds each 100 requests to API $hoClient->setTimeout(10); $hoClient->setRequestsLimit(100); /** @var Affiliate $affiliate */ $affiliate = $hoClient->get(Affiliate::class); $affiliate2 = $hoClient->get(Affiliate::class, 1004); // Get & set props $affiliate->company = 'Test Company'; $companyName = $affiliate->company; $affiliate->phone = '+7 845 845 84 54'; $affiliate->bindData([ 'company' => 'Test Company', 'phone' => '+7 845 845 84 54' ]); $affiliate->mergeData([ 'company' => 'Test Company', ]); $affiliate->data()->find('company'); $affiliate->data()->find('some.nested.key'); // CRUD $affiliate->save(); $affiliate->save(['company' => 'New Company Name']); $affiliate->reload(); // forced loading actual info from HO $affiliate->delete(); // set deleted status // Work with related objects /** @var PaymentMethod $paymentMethod */ $paymentMethod = $affiliate->getPaymentMethod(); $paymentType = $paymentMethod->getType(); $paypalEmail1 = $paymentMethod->email; $paypalEmail2 = $paymentMethod->data()->find('email'); // Work with contain items $billId = 56; $affInvoice = $hoClient->get(AffiliateInvoice::class, $billId); $affInvoiceItemsResultSet = $affInvoice->getItemsList(); // Find all: iterable $affInvoiceItems = $affInvoiceItemsResultSet->findAll(); foreach ($affInvoiceItems as $affInvoiceItem) { $affInvoiceItem->amount = 0.0; $affInvoiceItem->save(); } // Find by ID $affInvoiceItemId = 123; $affInvoiceItem = $affInvoiceItemsResultSet->findById($affInvoiceItemId); $affInvoiceItem->delete(); // delete from HO and reload parent // Add item $invoiceItem = $affInvoice ->getItemsList() ->addItem([ 'invoice_id' => $billId, 'offer_id' => 8, 'memo' => 'memo', 'amount' => 0.0, 'payout_type' => AffiliateInvoiceItem::PAYOUT_TYPE_CPA_FLAT ])->save(); // Or $affInvoiceItem = $affInvoiceItemsResultSet->addItem(); $affInvoiceItem->invoice_id = $billId; $affInvoiceItem->offer_id = 8; $affInvoiceItem->amount = 0.0; $affInvoiceItem->payout_type = 'cpa_flat'; $affInvoiceItem->save(); // Attach event handlers // @see https://github.com/JBZoo/Event $eManager ->on('ho.*.save.before', function(AbstractEntity $entity){ saveToLog($entity->data(), 'Snapshort before save'); }) ->on('ho.*.save.before', function(AbstractEntity $entity){ if('__some__condition__') { throw new ExceptionStop('Break event chain'); } }) ->on('ho.*.save.after', function(AbstractEntity $entity){ saveToLog($entity->data(), 'Snapshort after save'); }); } catch(Exception $exception) { echo $exception->getMessage(); // Any API or SDK errors }
Full Event List
More about JBZoo Event Manager
- ho.api.request.(before|after)
- ho.api.sleep.(before|after)
- ho.exception
- ho.{entity}.init
- ho.{entity}.save.(before|after)
- ho.{entity}.set.{property}.(before|after)
- ho.{entity}.unset.{property}.(before|after)
- ho.{entity}.bind.(before|after)
- ho.{entity}.delete.(before|after)
- ho.{entity}.block.(before|after)
- ho.{entity}.reload.(before|after)
- ho.{entity}.restore.(before|after) // Only Advertiser
- ho.{entity}.unblock.(before|after) // Only Affiliate
- ho.{entity}.find.(before|after)
- ho.{entity}.related.{contain}.init.(before|after)
- ho.{related}.reload.(before|after)
Unit tests and check code style
Notice. Before unit tests set eviroment variables via custom phpunit.xml
. See example
make make test-all
Licence
GNU GPL v2.0 or later. See details