Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Composer
Marketo-apiwrapper
Commits
41ab8073
Commit
41ab8073
authored
Aug 21, 2019
by
Mikael Löwgren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed var_dumps, put api_url in config.
parent
50772c0f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
39 additions
and
35 deletions
+39
-35
src/Controller/FolderController.php
src/Controller/FolderController.php
+1
-8
src/Controller/ImageController.php
src/Controller/ImageController.php
+2
-11
src/Credentials.php
src/Credentials.php
+23
-1
src/MarketoApi.php
src/MarketoApi.php
+7
-6
src/Model/Image.php
src/Model/Image.php
+3
-3
src/Model/ImageResponse.php
src/Model/ImageResponse.php
+0
-3
src/OAuth/MarketoClientCredentials.php
src/OAuth/MarketoClientCredentials.php
+3
-3
No files found.
src/Controller/FolderController.php
View file @
41ab8073
...
...
@@ -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
);
}
...
...
src/Controller/ImageController.php
View file @
41ab8073
...
...
@@ -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'
])
);
}
...
...
src/Credentials.php
View file @
41ab8073
...
...
@@ -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
src/MarketoApi.php
View file @
41ab8073
...
...
@@ -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'
,
...
...
src/Model/Image.php
View file @
41ab8073
...
...
@@ -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
(),
...
...
src/Model/ImageResponse.php
View file @
41ab8073
...
...
@@ -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'
])
;
...
...
src/OAuth/MarketoClientCredentials.php
View file @
41ab8073
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment