From df8a344066c754b44d4e80feb9024666132cfff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorente?= Date: Mon, 4 Jun 2018 11:39:53 +0200 Subject: [PATCH] Fixed some bugs in api configuration. New class created with the event type constants. --- src/Api/InAppEvent.php | 6 ++++- src/Appsflyer.php | 4 +-- src/ConfigInterface.php | 8 +++--- src/Core/Api.php | 8 +++--- src/Data/InAppEventType.php | 53 +++++++++++++++++++++++++++++++++++++ src/Utility.php | 2 +- 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 src/Data/InAppEventType.php diff --git a/src/Api/InAppEvent.php b/src/Api/InAppEvent.php index 4e9ef7a..161d1a7 100644 --- a/src/Api/InAppEvent.php +++ b/src/Api/InAppEvent.php @@ -19,12 +19,14 @@ namespace Jlorente\Appsflyer\Api; +use GuzzleHttp\RequestOptions; use Jlorente\Appsflyer\Core\Api; /** * Class InAppEvent. * * @author Jose Lorente + * @see https://support.appsflyer.com/hc/en-us/articles/115005544169-Rich-In-App-Events-Android-and-iOS#EventTypes */ class InAppEvent extends Api { @@ -46,7 +48,9 @@ class InAppEvent extends Api */ public function create($appId, array $parameters = []) { - return $this->_post("inappevent/$appId", $parameters); + return $this->_post("inappevent/$appId", [ + RequestOptions::JSON => $parameters + ]); } } diff --git a/src/Appsflyer.php b/src/Appsflyer.php index 01dd099..4b88188 100644 --- a/src/Appsflyer.php +++ b/src/Appsflyer.php @@ -107,9 +107,9 @@ class Appsflyer * * @return string */ - public function getApiKey() + public function getDevKey() { - return $this->config->getApiKey(); + return $this->config->getDevKey(); } /** diff --git a/src/ConfigInterface.php b/src/ConfigInterface.php index 1b162e9..40fa3bc 100644 --- a/src/ConfigInterface.php +++ b/src/ConfigInterface.php @@ -42,15 +42,15 @@ interface ConfigInterface * * @return string */ - public function getApiKey(); + public function getDevKey(); /** - * Sets the Appsflyer API key. + * Sets the Appsflyer DEV key. * - * @param string $apiKey + * @param string $devKey * @return $this */ - public function setApiKey($apiKey); + public function setDevKey($devKey); /** * Returns the Appsflyer API version. diff --git a/src/Core/Api.php b/src/Core/Api.php index d96dedb..4a68e8d 100644 --- a/src/Core/Api.php +++ b/src/Core/Api.php @@ -31,6 +31,7 @@ use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\TransferException; +use GuzzleHttp\RequestOptions; abstract class Api implements ApiInterface { @@ -152,9 +153,8 @@ abstract class Api implements ApiInterface public function execute($httpMethod, $url, array $parameters = []) { try { - $parameters = Utility::prepareParameters($parameters); - - $response = $this->getClient()->{$httpMethod}('/' . $url, ['query' => $parameters]); + // $parameters = Utility::prepareParameters($parameters); + $response = $this->getClient()->{$httpMethod}('/' . $url, $parameters); return json_decode((string) $response->getBody(), true); } catch (ClientException $e) { @@ -186,7 +186,7 @@ abstract class Api implements ApiInterface $stack->push(Middleware::mapRequest(function (RequestInterface $request) { $config = $this->config; - $request = $request->withHeader('authentication', base64_encode($config->getApiKey())); + $request = $request->withHeader('authentication', $config->getDevKey()); return $request; })); diff --git a/src/Data/InAppEventType.php b/src/Data/InAppEventType.php new file mode 100644 index 0000000..096104f --- /dev/null +++ b/src/Data/InAppEventType.php @@ -0,0 +1,53 @@ + + * @see https://support.appsflyer.com/hc/en-us/articles/115005544169-Rich-In-App-Events-Android-and-iOS#EventTypes + */ +class InAppEventType +{ + + const LEVEL_ACHIEVED = 'af_level_achieved'; + const ADD_PAYMENT_INFO = 'af_add_payment_info'; + const ADD_TO_CART = 'af_add_to_cart'; + const ADD_TO_WISH_LIST = 'af_add_to_wishlist'; + const COMPLETE_REGISTRATION = 'af_complete_registration'; + const TUTORIAL_COMPLETION = 'af_tutorial_completion'; + const INITIATED_CHECKOUT = 'af_initiated_checkout'; + const PURCHASE = 'af_purchase'; + const RATE = 'af_rate'; + const SEARCH = 'af_search'; + const SPENT_CREDIT = 'af_spent_credits'; + const ACHIEVEMENT_UNLOCKED = 'af_achievement_unlocked'; + const CONTENT_VIEW = 'af_content_view'; + const LIST_VIEW = 'af_list_view'; + const TRAVEL_BOOKING = 'af_travel_booking'; + const SHARE = 'af_share'; + const INVITE = 'af_invite'; + const LOGIN = 'af_login'; + const RE_ENGAGE = 'af_re_engage'; + const OPENED_FROM_PUSH_NOTIFICATION = 'af_opened_from_push_notification'; + const UPDATE = 'af_update'; + +} diff --git a/src/Utility.php b/src/Utility.php index bcd2b46..c880897 100644 --- a/src/Utility.php +++ b/src/Utility.php @@ -32,7 +32,7 @@ class Utility $toConvert = [ 'amount', 'price' ]; if (self::needsAmountConversion($parameters)) { - if ($converter = Stripe::getAmountConverter()) { + if ($converter = Appsflyer::getAmountConverter()) { foreach ($toConvert as $to) { if (isset($parameters[$to])) { $parameters[$to] = forward_static_call_array(