Skip to content

Commit

Permalink
Merge branch 'release/1.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyl77 committed Jun 14, 2017
2 parents fbb580a + 69e7dbb commit 9377ed9
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Filestack-php Changelog

## 1.1.6 (June 14, 2017)
- Added Image Tagging and Safe For Work functionalities

## 1.1.5 (May 31, 2017)
- Updated source header to Filestack-Source

Expand Down
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ $extras = [
$filepath = '/path/to/file';
$filelink = $client->upload($filepath);

// get metadata of file
# get metadata of file
$metadata = $client->getMetaData($filelink->handle, $fields);

// get content of a file
# get content of a file
$content = $client->getContent($filelink->handle);

// download a file
# download a file
$destination = '/path/to/file';
$result = $client->download($filelink->handle, $destination);

// overwrite a file
# overwrite a file
$filelink2 = $client->overwrite('/path/to/file', $filelink->handle);
```

Expand All @@ -85,31 +85,58 @@ use Filestack\filelink;

$file = new Filelink('pGj2wWfBTMuXhWe2J3bL', 'YOUR_API_KEY');

// transforming an image
# transforming an image
$transformed_filelink = $filelink
->circle()
->blur(['amount' => '20'])
->save();

// get metadata
# get metadata
$metadata = $filelink->getMetaData();

// get content of a file
# get content of a file
$content = $filelink->getContent();

$filepath = '/path/to/file';

// download a file
# download a file
$filelink->download($filepath);

// overwrite remote file with local file
# overwrite remote file with local file
$filelink->overwrite($filepath);

// delete remote file
# delete remote file
$filelink->delete();

```

### Tagging files and detecting safe for work content

```php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;

$security = new FilestackSecurity('YOUR_SECURITY_SECRET');
$client = new FilestackClient('YOUR_API_KEY', $security);

$file_handle = 'bzjSo5gAT76ra25sjk4c';

# get tags with client
$result_json = $client->getTags($file_handle);

# get tags with filelink
$filelink = new Filelink($file_handle, 'YOUR_API_KEY', $security);

$json_result = $filelink->getTags();

# get safe for work flag with client
$result_json = $client->getSafeForWork($file_handle);

# get safe for work flag with filelink
$json_result = $filelink->getSafeForWork();

```

For more examples, see the [examples/](examples/) folder in this project.

## Versioning
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
32 changes: 32 additions & 0 deletions examples/get-safe-for-work.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;
use Filestack\Filelink;
use Filestack\FilestackException;

$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_secret = 'YOUR_FILESTACK_SECURITY_SECRET';

$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);

$file_handle = 'bzjSo5gAT76ra25sjk4c';

# get sfw flag with client
$result_json = $client->getSafeForWork($file_handle);
var_dump($result_json);

# get sfw flag with filelink
$filelink = new Filelink($file_handle,
$test_api_key, $security);

$json_result = $filelink->getSafeForWork();
var_dump($json_result);

# example json result
/*
{
"sfw": true
}
*/

46 changes: 46 additions & 0 deletions examples/image-tagging.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
use Filestack\FilestackClient;
use Filestack\FilestackSecurity;
use Filestack\Filelink;
use Filestack\FilestackException;

$test_api_key = 'YOUR_FILESTACK_API_KEY';
$test_secret = 'YOUR_FILESTACK_SECURITY_SECRET';

$security = new FilestackSecurity($test_secret);
$client = new FilestackClient($test_api_key, $security);

$file_handle = 'bzjSo5gAT76ra25sjk4c';

# get tags with client
$result_json = $client->getTags($file_handle);
var_dump($result_json);

# get tags with filelink
$filelink = new Filelink($file_handle,
$test_api_key, $security);

$json_result = $filelink->getTags();
var_dump($json_result);

# example json result
/*
{
"tags": {
"auto": {
"accipitriformes": 58,
"beak": 90,
"bird": 97,
"bird of prey": 95,
"fauna": 84,
"great grey owl": 89,
"hawk": 66,
"owl": 97,
"vertebrate": 92,
"wildlife": 81
},
"user": null
}
}
*/

26 changes: 26 additions & 0 deletions filestack/Filelink.php
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,32 @@ public function setTransformUrl($method, $options = [])
$method, $options);
}

/**
* Get the sfw (safe for work) flag for this filelink
*
* @throws FilestackException if API call fails, e.g 404 file not found
*
* @return json
*/
public function getSafeForWork()
{
$result = $this->sendGetSafeForWork($this->handle, $this->security);
return $result;
}

/**
* Get the tags for this filelink
*
* @throws FilestackException if API call fails, e.g 404 file not found
*
* @return json
*/
public function getTags()
{
$result = $this->sendGetTags($this->handle, $this->security);
return $result;
}

/**
* Applied array of transformation tasks to this file link.
*
Expand Down
31 changes: 31 additions & 0 deletions filestack/FilestackClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,38 @@ public function getMetaData($url, $fields = [])

// call CommonMixin function
$result = $this->sendGetMetaData($url, $fields, $this->security);
return $result;
}

/**
* Get sfw (safe for work) flag of a filelink
*
* @param string $handle Filestack filelink handle
*
* @throws FilestackException if API call fails
*
* @return json
*/
public function getSafeForWork($handle)
{
// call CommonMixin function
$result = $this->sendGetSafeForWork($handle, $this->security);
return $result;
}

/**
* Get tags of a filelink
*
* @param string $handle Filestack filelink handle
*
* @throws FilestackException if API call fails
*
* @return json
*/
public function getTags($handle)
{
// call CommonMixin function
$result = $this->sendGetTags($handle, $this->security);
return $result;
}

Expand Down
62 changes: 62 additions & 0 deletions filestack/mixins/CommonMixin.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,68 @@ protected function sendGetMetaData($url, $fields = [], $security = null)
return $json_response;
}

/**
* Get the safe for work (sfw) flag of a filelink.
*
* @param string $handle Filestack file handle
* @param FilestackSecurity $security Filestack security object if
* security settings is turned on
*
* @throws FilestackException if API call fails, e.g 404 file not found
*
* @return json
*/
protected function sendGetSafeForWork($handle, $security)
{
$url = sprintf('%s/sfw/security=policy:%s,signature:%s/%s',
FilestackConfig::CDN_URL,
$security->policy,
$security->signature,
$handle);

$response = $this->sendRequest('GET', $url);
$status_code = $response->getStatusCode();

if ($status_code !== 200) {
throw new FilestackException($response->getBody(), $status_code);
}

$json_response = json_decode($response->getBody(), true);

return $json_response;
}

/**
* Get the tags of a filelink.
*
* @param string $handle Filestack file handle
* @param FilestackSecurity $security Filestack security object if
* security settings is turned on
*
* @throws FilestackException if API call fails, e.g 404 file not found
*
* @return json
*/
protected function sendGetTags($handle, $security)
{
$url = sprintf('%s/tags/security=policy:%s,signature:%s/%s',
FilestackConfig::CDN_URL,
$security->policy,
$security->signature,
$handle);

$response = $this->sendRequest('GET', $url);
$status_code = $response->getStatusCode();

if ($status_code !== 200) {
throw new FilestackException($response->getBody(), $status_code);
}

$json_response = json_decode($response->getBody(), true);

return $json_response;
}

/**
* Overwrite a file in cloud storage
*
Expand Down
Loading

0 comments on commit 9377ed9

Please sign in to comment.