Browse Source

Fixed some bugs in api configuration.

New class created with the event type constants.
master
José Lorente 6 years ago
parent
commit
df8a344066
  1. 6
      src/Api/InAppEvent.php
  2. 4
      src/Appsflyer.php
  3. 8
      src/ConfigInterface.php
  4. 8
      src/Core/Api.php
  5. 53
      src/Data/InAppEventType.php
  6. 2
      src/Utility.php

6
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 <jose.lorente.martin@gmail.com>
* @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
]);
}
}

4
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();
}
/**

8
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.

8
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;
}));

53
src/Data/InAppEventType.php

@ -0,0 +1,53 @@
<?php
/**
* Part of the Appsflyer package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Appsflyer
* @version 1.0.0
* @author Jose Lorente
* @license BSD License (3-clause)
* @copyright (c) 2018, Jose Lorente
*/
namespace Jlorente\Appsflyer\Data;
/**
* Class InAppEventType.
*
* @author Jose Lorente <jose.lorente.martin@gmail.com>
* @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';
}

2
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(

Loading…
Cancel
Save