Skip to content

Commit 52ba387

Browse files
committed
Some more classes and tests added
1 parent f8577f0 commit 52ba387

File tree

11 files changed

+576
-287
lines changed

11 files changed

+576
-287
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"autoload-dev": {
3131
"psr-4": {
32-
"Swader\\Diffbot\\Test\\": "tests"
32+
"Swader\\Diffbot\\Test\\": "tests/"
3333
}
3434
},
3535
"extra": {

src/Abstracts/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function call()
104104
return $this->diffbot->getEntityFactory()->createAppropriate($response);
105105
}
106106

107-
protected function buildUrl()
107+
public function buildUrl()
108108
{
109109
$url = rtrim($this->apiUrl, '/') . '/';
110110

src/Api/Analyze.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,4 @@ public static function getOptionalFields()
1919
{
2020
return self::$optionalFields;
2121
}
22-
23-
public function call()
24-
{
25-
26-
}
2722
}

src/Api/Article.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,4 @@ public static function getOptionalFields()
1919
{
2020
return self::$optionalFields;
2121
}
22-
23-
public function setImagesHeight($bool = null)
24-
{
25-
$this->fieldSettings['images(height)'] = ($bool) ? (bool)$bool : false;
26-
return $this;
27-
}
28-
29-
public function getImagesHeight()
30-
{
31-
return (isset($this->fieldSettings['images(height)'])) ? $this->fieldSettings['images(height)'] : false;
32-
}
33-
34-
public function setImagesWidth($bool = null)
35-
{
36-
$this->fieldSettings['images(width)'] = ($bool) ? (bool)$bool : false;
37-
return $this;
38-
}
39-
40-
public function getImagesWidth()
41-
{
42-
return (isset($this->fieldSettings['images(width)'])) ? $this->fieldSettings['images(width)'] : false;
43-
}
44-
45-
public function setVideosNaturalHeight($bool = null)
46-
{
47-
$this->fieldSettings['videos(naturalHeight)'] = ($bool) ? (bool)$bool : false;
48-
return $this;
49-
}
50-
51-
public function getVideosNaturalHeight()
52-
{
53-
return (isset($this->fieldSettings['videos(naturalHeight)']))
54-
? $this->fieldSettings['videos(naturalHeight)'] : false;
55-
}
56-
57-
public function setVideosNaturalWidth($bool = null)
58-
{
59-
$this->fieldSettings['videos(naturalWidth)'] = ($bool) ? (bool)$bool : false;
60-
return $this;
61-
}
62-
63-
public function getVideosNaturalWidth()
64-
{
65-
return (isset($this->fieldSettings['videos(naturalWidth)']))
66-
? $this->fieldSettings['videos(naturalWidth)'] : false;
67-
}
68-
69-
public function call()
70-
{
71-
72-
}
7322
}

src/Api/Image.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,4 @@ public static function getOptionalFields()
2626
{
2727
return self::$optionalFields;
2828
}
29-
30-
public function call()
31-
{
32-
33-
}
3429
}

src/Entity/Article.php

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
<?php
2+
3+
namespace Swader\Diffbot\Entity;
4+
5+
use Swader\Diffbot\Abstracts\Entity;
6+
7+
class Article extends Entity
8+
{
9+
/**
10+
* Should always return "article"
11+
* @return string
12+
*/
13+
public function getType()
14+
{
15+
return $this->objects['type'];
16+
}
17+
18+
/**
19+
* Returns the URL which was crawled
20+
* @return string
21+
*/
22+
public function getPageUrl()
23+
{
24+
return $this->objects['pageUrl'];
25+
}
26+
27+
/**
28+
* Returns page Url which was resolved by redirects, if any.
29+
* For example, crawling a bitly link will make this method return the ultimate destination's URL
30+
* @return string
31+
*/
32+
public function getResolvedPageUrl()
33+
{
34+
return (isset($this->objects['resolvedPageUrl'])) ? $this->objects['resolvedPageUrl'] : $this->getPageUrl();
35+
}
36+
37+
/**
38+
* Returns title of article as deducted by Diffbot
39+
* @return string
40+
*/
41+
public function getTitle()
42+
{
43+
return $this->objects['title'];
44+
}
45+
46+
/**
47+
* Returns plaintext version of article (no HTML) as parsed by Diffbot.
48+
* Only the content is returned, the text in the surrounding (layout etc) elements is ignored.
49+
* @return string
50+
*/
51+
public function getText()
52+
{
53+
return $this->objects['text'];
54+
}
55+
56+
/**
57+
* Returns full HTML of the article's content - only the content, not the surrounding layout HTML.
58+
* @return string
59+
*/
60+
public function getHtml()
61+
{
62+
return $this->objects['html'];
63+
}
64+
65+
/**
66+
* Returns date as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3
67+
* Example date: "Wed, 18 Dec 2013 00:00:00 GMT"
68+
* Note that this is "strtotime" friendly for further conversions
69+
* @todo add more formats as method arguments
70+
* @return string
71+
*/
72+
public function getDate()
73+
{
74+
return $this->objects['date'];
75+
}
76+
77+
/**
78+
* Returns the full name of the author, as signed on the article's page
79+
* @return string
80+
*/
81+
public function getAuthor()
82+
{
83+
return $this->objects['author'];
84+
}
85+
86+
/**
87+
* The array returned will contain all tags that Diffbot's AI concluded match the content
88+
*
89+
* Note that these are *not* the meta tags as defined by the author, but machine learned ones.
90+
* Note also that tags may differ depending on URL. Visiting a bitly link vs visiting a fully resolved one
91+
* will sometimes yield different results. It is currently unknown why this happens.
92+
* The format of the array is:
93+
*
94+
* [
95+
* [
96+
* "id": 133907,
97+
* "count": 3,
98+
* "prevalence": 0.3103448275862069,
99+
* "label": "Apache HTTP Server",
100+
* "type": "Http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#InformationEntity",
101+
* "uri": "http://dbpedia.org/resource/Apache_HTTP_Server"
102+
* ],
103+
* [
104+
* "id": 208652,
105+
* "count": 5,
106+
* "prevalence": 0.5172413793103449,
107+
* "label": "PHP",
108+
* "type": "Http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#InformationEntity",
109+
* "uri": "http://dbpedia.org/resource/PHP"
110+
* ]
111+
* ]
112+
*
113+
* @return array
114+
*/
115+
public function getTags()
116+
{
117+
return $this->objects['tags'];
118+
}
119+
120+
/**
121+
* Alias for getLang()
122+
* @see getLang()
123+
* @return string
124+
*/
125+
public function getHumanLanguage()
126+
{
127+
return $this->getLang();
128+
}
129+
130+
/**
131+
* Returns the human language as determined by Diffbot when looking at content.
132+
* The code returned is a two-character ISO 639-1 code: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
133+
* @return string
134+
*/
135+
public function getLang()
136+
{
137+
return $this->objects['humanLanguage'];
138+
}
139+
140+
/**
141+
* Number of pages automatically concatenated to form the text or html response.
142+
* By default, Diffbot will automatically concatenate up to 20 pages of an article.
143+
* @see http://support.diffbot.com/automatic-apis/handling-multiple-page-articles/
144+
* @return int
145+
*/
146+
public function getNumPages()
147+
{
148+
return (isset($this->objects['numPages'])) ? $this->objects['numPages'] : 1;
149+
}
150+
151+
/**
152+
* Array of all page URLs concatenated in a multipage article.
153+
* Empty array if article was not concatenated before being returned.
154+
* @see http://support.diffbot.com/automatic-apis/handling-multiple-page-articles/
155+
* @return array
156+
*/
157+
public function getNextPages()
158+
{
159+
return (isset($this->objects['nextPages'])) ? $this->objects['nextPages'] : [];
160+
}
161+
162+
/**
163+
* Returns an array of images found in the article's content.
164+
*
165+
* Note that this (tries) to ignore content-unrelated images like ads arounds the page, etc.
166+
* The format of the array will be:
167+
*
168+
* [
169+
* {
170+
* "height": 808,
171+
* "diffbotUri": "image|3|-543943368",
172+
* "naturalHeight": 808,
173+
* "width": 717,
174+
* "primary": true,
175+
* "naturalWidth": 717,
176+
* "url": "https://example.com/image1.png"
177+
* },
178+
* {
179+
* "height": 506,
180+
* "diffbotUri": "image|3|-844014913",
181+
* "naturalHeight": 506,
182+
* "width": 715,
183+
* "naturalWidth": 715,
184+
* "url": "https://example.com/image1.jpeg"
185+
* }
186+
* ]
187+
*
188+
* @return array
189+
*/
190+
public function getImages()
191+
{
192+
return (isset($this->objects['images'])) ? $this->objects['images'] : [];
193+
}
194+
195+
/**
196+
* Returns an array of videos found in the article's content.
197+
*
198+
* The format of the array will be:
199+
*
200+
* [
201+
* {
202+
* "diffbotUri": "video|3|-1138675744",
203+
* "primary": true,
204+
* "url": "http://player.vimeo.com/video/22439234"
205+
* },
206+
* {
207+
* "diffbotUri": "video|3|-1138675744",
208+
* "primary": true,
209+
* "url": "http://player.vimeo.com/video/22439234"
210+
* }
211+
* ]
212+
*
213+
* @return array
214+
*/
215+
public function getVideos() {
216+
return (isset($this->objects['images'])) ? $this->objects['images'] : [];
217+
}
218+
219+
/**
220+
* An internal identifier for Diffbot, used for indexing in their databases
221+
* @return string
222+
*/
223+
public function getDiffbotUri()
224+
{
225+
return $this->objects['diffbotUri'];
226+
}
227+
228+
public function getLinks() {
229+
230+
}
231+
232+
public function getMeta() {
233+
234+
}
235+
236+
public function getQueryString() {
237+
238+
}
239+
}

src/Entity/Product.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,22 @@ public function getTitle()
4141
{
4242
return $this->objects['title'];
4343
}
44+
45+
/**
46+
* Returns Stock Keeping Unit -- store/vendor inventory number or identifier.
47+
* @return string
48+
*/
49+
public function getSku()
50+
{
51+
return $this->objects['sku'];
52+
}
53+
54+
/**
55+
* offerPrice separated into its constituent parts: amount, symbol, and full text.
56+
* @return array
57+
*/
58+
public function getOfferPriceDetails()
59+
{
60+
return $this->objects['offerPriceDetails'];
61+
}
4462
}

0 commit comments

Comments
 (0)