Commit 41ab8073 authored by Mikael Löwgren's avatar Mikael Löwgren

Removed var_dumps, put api_url in config.

parent 50772c0f
......@@ -14,26 +14,19 @@ class FolderController extends BaseController {
* @return FolderResponse[]
*/
public function list(string $rootFolderId = null ): array {
//$queryParameters = ['libraryId' => 'Image'];
//root={
// "id": 10092,
// "type": "Folder"
// }&maxDepth=2&maxReturn=20&offset=0&workspace
$queryParameters['root'] = "{ \"id\":".$parentFolderId.", \"type\":\"Folder\"}";
//$queryParameters['root'] = "{ \"id\":10092, \"type\":\"Folder\"}";
$queryParameters['maxDepth'] = '2';
$queryParameters['maxReturn'] = '20';
$queryParameters['offset'] = '0';
$queryParameters['workspace'] = '';
//var_dump( $this->apiHttpClient->getConfig() );
$response = $this->apiHttpClient->get('/rest/asset/v1/folders.json', [RequestOptions::QUERY => $queryParameters]);
$responseData = \GuzzleHttp\json_decode($response->getBody(), true);
$result = [];
var_dump( $responseData['result'] );
foreach ($responseData['result'] as $rawFolder) {
$result[] = FolderResponse::fromArray($rawFolder);
}
......
......@@ -55,29 +55,20 @@ class ImageController extends BaseController {
['name' => 'file', 'contents' => fopen($pathToFile, 'r')],
['name' => 'name', 'contents' => $image->getName()],
['name' => 'folder', 'contents' => "{ \"id\":".$image->getFolderId().", \"type\":\"Folder\" }"],
//['name' => 'tags', 'contents' => $image->getTags()],
//['name' => 'tags', 'contents' => $image->getTags()],
['name' => 'description', 'contents' => 'My Description'],
['name' => 'description', 'contents' => $image->getDescription() ],
['name' => 'insertOnly', 'contents' => 'true']
],
'headers' => ['name' => 'Content-Type', 'contents' => 'text/plain' ] //Might need headers Content-Type text/plain
];
var_dump( $options );
$response = $this->apiHttpClient->post('/rest/asset/v1/files.json', $options);
if ($response->getStatusCode() !== 200) {
throw new TransferException('Non-successful response to upload: '.$response->getStatusCode().' '.$response->getReasonPhrase());
}
var_dump( $response->getBody()->getContents() );
/*
$assetUrl = $response->getHeader('Location')[0];
$imageId = str_replace('https://api-v1/images/', '', $assetUrl); //TODO Need to understand why replace here
// Sometimes the API doesn't realize the image we just uploaded exists. Retry up to 5 times.
return $this->retryGuzzle(5, function() use ($imageId) { return $this->get($imageId); });*/
$responseData = \GuzzleHttp\json_decode($response->getBody(), true);
var_dump( $responseData );
return ImageResponse::fromArray( reset($responseData['result']) );
}
......
......@@ -5,6 +5,9 @@ namespace QBNK\MarketoApi;
class Credentials
{
/** @var string */
protected $api_url;
/** @var string */
protected $clientId;
......@@ -15,7 +18,8 @@ class Credentials
* @param string $clientId
* @param string $clientSecret
*/
public function __construct($clientId, $clientSecret) {
public function __construct($api_url, $clientId, $clientSecret) {
$this->api_url = $api_url;
$this->clientId = $clientId;
$this->clientSecret($clientSecret);
}
......@@ -41,4 +45,22 @@ class Credentials
public function getClientSecret(): string {
return $this->clientSecret();
}
/**
* @return string
*/
public function getApiUrl(): string
{
return $this->api_url;
}
/**
* @param string $api_url
* @return Credentials
*/
public function setApiUrl(string $api_url): Credentials
{
$this->api_url = $api_url;
return $this;
}
}
\ No newline at end of file
......@@ -19,8 +19,8 @@ class MarketoApi
{
public const API_URL = 'https://509-APS-230.mktorest.com'; //Aptio instance, need to be property for future?
public const API_TOKEN_URL = 'identity/oauth/token'; //Not sure if this is applicable for marketo
public const API_URL = 'https://not_used_check_config.com';
public const API_TOKEN_URL = 'identity/oauth/token';
/** @var Credentials */
protected $credentials;
......@@ -37,7 +37,7 @@ class MarketoApi
/** @var ImageController */
protected $imageController;
public function __construct(Credentials $credentials, array $options = []) {
public function __construct( Credentials $credentials, array $options = []) {
$this->credentials = $credentials;
}
......@@ -46,7 +46,7 @@ class MarketoApi
$handlerStack = HandlerStack::create();
$oauthClient = new Client([
'base_uri' => self::API_URL,
'base_uri' => $this->credentials->getApiUrl(),
'verify' => true,
'headers' => [
'User-Agent' => 'marketo-apiwrapper/1 (guzzle: 6)',
......@@ -56,7 +56,8 @@ class MarketoApi
ClientCredentials::CONFIG_CLIENT_ID => $this->credentials->getClientId(),
ClientCredentials::CONFIG_CLIENT_SECRET => $this->credentials->getClientSecret(),
ClientCredentials::CONFIG_AUTH_LOCATION => RequestOptions::QUERY,
ClientCredentials::CONFIG_TOKEN_URL => self::API_URL."/".self::API_TOKEN_URL
//ClientCredentials::CONFIG_TOKEN_URL => self::API_URL."/".self::API_TOKEN_URL
ClientCredentials::CONFIG_TOKEN_URL => $this->credentials->getApiUrl()."/".self::API_TOKEN_URL
];
......@@ -72,7 +73,7 @@ class MarketoApi
$apiClient = new Client([
'handler' => $handlerStack,
'auth' => 'oauth2',
'base_uri' => self::API_URL.'/rest/assets/v1/folders.json',
'base_uri' => $this->credentials->getApiUrl().'/rest/assets/v1/folders.json',
'headers' => [
'Accept' => 'application/json',
'Content-type' => 'application/json',
......
......@@ -120,8 +120,7 @@ class Image implements JsonSerializable
->setName((string)$data['name'])
->setDescription((string)$data['description'])
->setFolderId((string)$data['folder']['id'])
//->setExternalData((string)$data['externalData'])
; //TODO: Check if tags are applicable for Marketo
;
return $instance;
}
......@@ -133,8 +132,9 @@ class Image implements JsonSerializable
* @since 5.4.0
*/
public function jsonSerialize() {
//TODO: Check if tags are applicable for Marketo
return [
'id' => $this->getId(),
'name' => $this->getName(),
'folderId' => $this->getFolderId(),
'description' => $this->getDescription(),
......
......@@ -84,10 +84,7 @@ class ImageResponse extends Image
$instance
->setId((string)$data['id'])
->setMimeType((string)$data['mimeType'])
//->setWidth((int)$data['width'])
//->setHeight((int)$data['height'])
->setFileSize((int)$data['size'])
//->setChecksum((string)$data['checksum'])
->setPreviewUrl((string)$data['url'])
;
......
......@@ -38,14 +38,14 @@ class MarketoClientCredentials extends ClientCredentials
unset($body["scope"]);
$requestOptions[RequestOptions::QUERY] = $body;
if ($additionalOptions = $this->getAdditionalOptions()) {
$requestOptions = array_merge_recursive($requestOptions, $additionalOptions);
}
var_dump( "before get");
var_dump( $this->config[self::CONFIG_TOKEN_URL], $requestOptions );
$response = $this->client->get($this->config[self::CONFIG_TOKEN_URL], $requestOptions);
var_dump($response );
$data = json_decode($response->getBody()->__toString(), true);
return new AccessToken($data['access_token'], $data['token_type'], $data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment