Skip to content

Commit 570aeef

Browse files
author
vagrant
committed
First public release of basic APIs
1 parent edc8749 commit 570aeef

36 files changed

+2298
-105
lines changed

CHANGELOG.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
#Changelog
2-
All Notable changes to `:package_name` will be documented in this file
2+
All notable changes will be documented in this file
33

4-
## NEXT - YYYY-MM-DD
4+
## 0.1 - April 20th, 2015
55

6-
### Added
7-
- Nothing
8-
9-
### Deprecated
10-
- Nothing
11-
12-
### Fixed
13-
- Nothing
14-
15-
### Remove
16-
- Nothing
17-
18-
### Security
19-
- Nothing
6+
Initial public release.

CONTRIBUTING.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Contributing
22

33
Contributions are **welcome** and will be fully **credited**.
4-
5-
We accept contributions via Pull Requests on [Github](https://github.com/thephpleague/:package_name).
6-
4+
Send Pull Requests or open issues please.
75

86
## Pull Requests
97

@@ -25,7 +23,7 @@ We accept contributions via Pull Requests on [Github](https://github.com/thephpl
2523
## Running Tests
2624

2725
``` bash
28-
$ phpunit
26+
phpunit
2927
```
3028

3129

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The MIT License (MIT)
22

3-
Copyright (c) 2013 :author_name <:author_email>
3+
Copyright (c) 2015 Bruno Skvorc (@bitfalls)
44

55
> Permission is hereby granted, free of charge, to any person obtaining a copy
66
> of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ Please see [CONTRIBUTING](https://github.com/thephpleague/:package_name/blob/mas
4444

4545
## License
4646

47-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
47+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"extra": {
3636
"branch-alias": {
37-
"dev-master": "1.0-dev"
37+
"dev-master": "0.2-dev"
3838
}
3939
}
4040
}

src/Abstracts/Api.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ abstract class Api implements \Swader\Diffbot\Interfaces\Api
2222
/** @var array Settings on which optional fields to fetch */
2323
protected $fieldSettings = [];
2424

25+
/** @var array Other API specific options */
26+
protected $otherOptions = [];
27+
2528
/** @var Diffbot The parent class which spawned this one */
2629
protected $diffbot;
2730

@@ -101,6 +104,11 @@ public function buildUrl()
101104
$url .= '&fields=' . $fieldString;
102105
}
103106

107+
// Add Other Options
108+
foreach ($this->otherOptions as $option => $value) {
109+
$url .= '&'.$option . '=' . $value;
110+
}
111+
104112
return $url;
105113
}
106114

src/Api/Analyze.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,39 @@ class Analyze extends Api
1111

1212
/** @var string API URL to which to send the request */
1313
protected $apiUrl = 'http://api.diffbot.com/v3/analyze';
14+
15+
/**
16+
* If set to false, will not extract article comments in a Discussion
17+
* entity embedded in the Article / Product entity. By default, it will.
18+
* @param bool $bool
19+
* @return $this
20+
*/
21+
public function setDiscussion($bool = true)
22+
{
23+
$this->otherOptions['discussion'] = ($bool) ? 'true' : 'false';
24+
25+
return $this;
26+
}
27+
28+
/**
29+
* By default the Analyze API will fully extract all pages that match an
30+
* existing Automatic API -- articles, products or image pages. Set mode
31+
* to a specific page-type (e.g., mode=article) to extract content only
32+
* from that specific page-type. All other pages will simply return the
33+
* default Analyze fields.
34+
*
35+
* @param string $mode article, product or image
36+
* @return $this
37+
*/
38+
public function setMode($mode)
39+
{
40+
if (!in_array($mode, ['article', 'product', 'image'])) {
41+
$error = 'Only "article", "product" and "image" modes supported.';
42+
throw new \InvalidArgumentException($error);
43+
}
44+
$this->otherOptions['mode'] = $mode;
45+
46+
return $this;
47+
}
48+
1449
}

src/Api/Article.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,57 @@ class Article extends Api
1111

1212
/** @var string API URL to which to send the request */
1313
protected $apiUrl = 'http://api.diffbot.com/v3/article';
14+
15+
/**
16+
* @see Swader\Diffbot\Entity\Article::getSentiment()
17+
* @param $bool
18+
* @return $this
19+
*/
20+
public function setSentiment($bool)
21+
{
22+
$this->fieldSettings['sentiment'] = (bool)$bool;
23+
24+
return $this;
25+
}
26+
27+
/**
28+
* If set to false, Diffbot will not auto-concat several pages of a
29+
* multi-page article into one. Defaults to true, max 20 pages.
30+
*
31+
* @see http://support.diffbot.com/automatic-apis/handling-multiple-page-articles/
32+
* @param bool $bool
33+
* @return $this
34+
*/
35+
public function setPaging($bool = true)
36+
{
37+
$this->otherOptions['paging'] = ($bool) ? 'true' : 'false';
38+
39+
return $this;
40+
}
41+
42+
/**
43+
* Set the maximum number of automatically-generated tags to return.
44+
* By default a maximum of five tags will be returned.
45+
* @param int $max
46+
* @return $this
47+
*/
48+
public function setMaxTags($max = 5)
49+
{
50+
$this->otherOptions['maxTags'] = (int)$max;
51+
52+
return $this;
53+
}
54+
55+
/**
56+
* If set to false, will not extract article comments in a Discussion
57+
* entity embedded in the Article entity. By default, it will.
58+
* @param bool $bool
59+
* @return $this
60+
*/
61+
public function setDiscussion($bool = true)
62+
{
63+
$this->otherOptions['discussion'] = ($bool) ? 'true' : 'false';
64+
65+
return $this;
66+
}
1467
}

src/Api/Image.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,35 @@ class Image extends Api
1616
* Tells the API call to return the mentions field
1717
* @see https://www.diffbot.com/dev/docs/image/
1818
* @param $bool
19+
* @return $this
1920
*/
2021
public function setMentions($bool)
2122
{
2223
$this->fieldSettings['mentions'] = (bool)$bool;
24+
return $this;
2325
}
2426

2527
/**
2628
* Sets the API call to return the faces field
2729
* @see https://www.diffbot.com/dev/docs/image/
2830
* @param $bool
31+
* @return $this
2932
*/
3033
public function setFaces($bool)
3134
{
3235
$this->fieldSettings['faces'] = (bool)$bool;
36+
return $this;
3337
}
3438

3539
/**
3640
* Sets the API call to return the ocr field.
3741
* @see https://www.diffbot.com/dev/docs/image/
3842
* @param $bool
43+
* @return $this
3944
*/
4045
public function setOcr($bool)
4146
{
4247
$this->fieldSettings['ocr'] = (bool)$bool;
48+
return $this;
4349
}
4450
}

src/Api/Product.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,53 @@ class Product extends Api
1111

1212
/** @var string API URL to which to send the request */
1313
protected $apiUrl = 'http://api.diffbot.com/v3/product';
14+
15+
/**
16+
* If set to false, will not extract article comments in a Discussion
17+
* entity embedded in the Product entity. By default, it will.
18+
* @param bool $bool
19+
* @return $this
20+
*/
21+
public function setDiscussion($bool = true)
22+
{
23+
$this->otherOptions['discussion'] = ($bool) ? 'true' : 'false';
24+
25+
return $this;
26+
}
27+
28+
/**
29+
* @see Swader\Diffbot\Entity\Product::getColors()
30+
* @param $bool
31+
* @return $this
32+
*/
33+
public function setColors($bool)
34+
{
35+
$this->fieldSettings['colors'] = (bool)$bool;
36+
37+
return $this;
38+
}
39+
40+
/**
41+
* @see Swader\Diffbot\Entity\Product::getSize()
42+
* @param $bool
43+
* @return $this
44+
*/
45+
public function setSize($bool)
46+
{
47+
$this->fieldSettings['size'] = (bool)$bool;
48+
49+
return $this;
50+
}
51+
52+
/**
53+
* @see Swader\Diffbot\Entity\Product::isAvailable()
54+
* @param $bool
55+
* @return $this
56+
*/
57+
public function setAvailability($bool)
58+
{
59+
$this->fieldSettings['availability'] = (bool)$bool;
60+
61+
return $this;
62+
}
1463
}

src/Entity/Article.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function getDate()
5151

5252
/**
5353
* Returns the full name of the author, as signed on the article's page
54-
* @return string
54+
* @return string | null
5555
*/
5656
public function getAuthor()
5757
{
58-
return $this->data['author'];
58+
return (isset($this->data['author'])) ? $this->data['author'] : null;
5959
}
6060

6161
/**
@@ -112,6 +112,16 @@ public function getNextPages()
112112
return (isset($this->data['nextPages'])) ? $this->data['nextPages'] : [];
113113
}
114114

115+
/**
116+
* Returns the sentiment score of the analyzed article text, a value randing from
117+
* -1.0 (very negative) to 1.0 (very positive).
118+
* @return float|null
119+
*/
120+
public function getSentiment()
121+
{
122+
return (isset($this->data['sentiment'])) ? $this->data['sentiment'] : null;
123+
}
124+
115125
/**
116126
* Returns an array of images found in the page's content.
117127
*
@@ -167,17 +177,8 @@ public function getImages()
167177
*
168178
* @return array
169179
*/
170-
public function getVideos() {
171-
return (isset($this->data['images'])) ? $this->data['images'] : [];
172-
}
173-
174-
/**
175-
* An internal identifier for Diffbot, used for indexing in their databases
176-
* @return string
177-
*/
178-
public function getDiffbotUri()
180+
public function getVideos()
179181
{
180-
return $this->data['diffbotUri'];
182+
return (isset($this->data['videos'])) ? $this->data['videos'] : [];
181183
}
182-
183184
}

0 commit comments

Comments
 (0)