Skip to content

Commit ba0b663

Browse files
authored
Merge pull request #8 from m4olivei/7-advertisingSettings
Issue #7 add support for advertisingSettings document property.
2 parents c6d9a21 + d621a16 commit ba0b663

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed

autoload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function autoload679875ef60343fd604aa0fa4d353e67e($class) {
77
if ($classes === null) {
88
$classes = array(
99
'chapterthree\\applenewsapi\\document' => '/src/Document.php',
10+
'chapterthree\\applenewsapi\\document\\advertisingsettings' => '/src/Document/AdvertisingSettings.php',
1011
'chapterthree\\applenewsapi\\document\\anchor' => '/src/Document/Anchor.php',
1112
'chapterthree\\applenewsapi\\document\\animations\\componentanimations\\appearanimation' => '/src/Document/Animations/ComponentAnimations/AppearAnimation.php',
1213
'chapterthree\\applenewsapi\\document\\animations\\componentanimations\\componentanimation' => '/src/Document/Animations/ComponentAnimations/ComponentAnimation.php',
@@ -62,6 +63,7 @@ function autoload679875ef60343fd604aa0fa4d353e67e($class) {
6263
'chapterthree\\applenewsapi\\document\\components\\video' => '/src/Document/Components/Video.php',
6364
'chapterthree\\applenewsapi\\document\\contentinset' => '/src/Document/ContentInset.php',
6465
'chapterthree\\applenewsapi\\document\\galleryitem' => '/src/Document/GalleryItem.php',
66+
'chapterthree\\applenewsapi\\document\\layouts\\advertisinglayout' => '/src/Document/Layouts/AdvertisingLayout.php',
6567
'chapterthree\\applenewsapi\\document\\layouts\\componentlayout' => '/src/Document/Layouts/ComponentLayout.php',
6668
'chapterthree\\applenewsapi\\document\\layouts\\layout' => '/src/Document/Layouts/Layout.php',
6769
'chapterthree\\applenewsapi\\document\\margin' => '/src/Document/Margin.php',

src/Document.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace ChapterThree\AppleNewsAPI;
99

10+
use ChapterThree\AppleNewsAPI\Document\AdvertisingSettings;
1011
use ChapterThree\AppleNewsAPI\Document\Base;
1112
use ChapterThree\AppleNewsAPI\Document\Components\Component;
1213
use ChapterThree\AppleNewsAPI\Document\Components\ComponentNested;
@@ -31,6 +32,7 @@ class Document extends Base {
3132
protected $components;
3233
protected $componentTextStyles;
3334

35+
protected $advertisingSettings;
3436
protected $subtitle;
3537
protected $metadata;
3638
protected $documentStyle;
@@ -65,6 +67,7 @@ public function __construct($identifier, $title, $language, Layout $layout) {
6567
*/
6668
protected function optional() {
6769
return array_merge(parent::optional(), array(
70+
'advertisingSettings',
6871
'subtitle',
6972
'metadata',
7073
'documentStyle',
@@ -227,6 +230,30 @@ public function addComponentTextStyle($name, ComponentTextStyle $component_text_
227230
return $this;
228231
}
229232

233+
/**
234+
* Getter for advertisingSettings.
235+
*/
236+
public function getAdvertisingSettings() {
237+
return $this->advertisingSettings;
238+
}
239+
240+
/**
241+
* Setter for advertisingSettings.
242+
*
243+
* @param AdvertisingSettings $value
244+
*
245+
* @return $this
246+
*/
247+
public function setAdvertisingSettings($value) {
248+
if (is_object($value) && !$value instanceof AdvertisingSettings) {
249+
$this->triggerError('Object not of type AdvertisingSettings');
250+
}
251+
else {
252+
$this->advertisingSettings = $value;
253+
}
254+
return $this;
255+
}
256+
230257
/**
231258
* Getter for subtitle.
232259
*/

src/Document/AdvertisingSettings.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Apple News Document Advertising Settings.
6+
*/
7+
8+
namespace ChapterThree\AppleNewsAPI\Document;
9+
use ChapterThree\AppleNewsAPI\Document\Layouts\AdvertisingLayout;
10+
11+
/**
12+
* Apple News Document Advertising Settings.
13+
*/
14+
class AdvertisingSettings extends Base {
15+
16+
protected $bannerType;
17+
protected $frequency;
18+
protected $layout;
19+
20+
const BANNER_TYPE_ANY = 'any';
21+
const BANNER_TYPE_STANDARD = 'standard';
22+
const BANNER_TYPE_DOUBLE = 'double_height';
23+
const BANNER_TYPE_LARGE = 'large';
24+
25+
/**
26+
* Define optional properties.
27+
*/
28+
protected function optional() {
29+
return array_merge(parent::optional(), array(
30+
'bannerType',
31+
'frequency',
32+
'layout',
33+
));
34+
}
35+
36+
/**
37+
* Getter for bannerType.
38+
*/
39+
public function getBannerType() {
40+
return $this->bannerType;
41+
}
42+
43+
/**
44+
* Setting for bannerType.
45+
*
46+
* @param string $bannerType
47+
* The banner type that should be shown. One of 'any', 'standard',
48+
* 'double_height', and 'large'.
49+
*
50+
* @return $this
51+
*/
52+
public function setBannerType($bannerType) {
53+
if (!in_array($bannerType, [
54+
self::BANNER_TYPE_ANY,
55+
self::BANNER_TYPE_DOUBLE,
56+
self::BANNER_TYPE_LARGE,
57+
self::BANNER_TYPE_STANDARD,
58+
])) {
59+
$this->triggerError('Invalid value for bannerType advertisingSettings.');
60+
}
61+
else {
62+
$this->bannerType = $bannerType;
63+
}
64+
return $this;
65+
}
66+
67+
/**
68+
* Getter for frequency.
69+
*/
70+
public function getFrequency() {
71+
return $this->frequency;
72+
}
73+
74+
/**
75+
* Setter for frequency.
76+
*
77+
* @param int $frequency
78+
* A number between 0 and 10 defining the frequency for automatically
79+
* inserting advertising components into articles.
80+
*
81+
* @return $this
82+
*/
83+
public function setFrequency($frequency) {
84+
if ($frequency >= 0 && $frequency <= 10) {
85+
$this->frequency = $frequency;
86+
}
87+
else {
88+
$this->triggerError('Invalid value for frequency advertisingSettings.');
89+
}
90+
return $this;
91+
}
92+
93+
/**
94+
* Getter for layout.
95+
*/
96+
public function getLayout() {
97+
return $this->layout;
98+
}
99+
100+
/**
101+
* Setter for layout.
102+
*
103+
* @param AdvertisingLayout $layout
104+
* Layout object that currently supports only margin.
105+
*
106+
* @return $this
107+
*/
108+
public function setLayout(AdvertisingLayout $layout) {
109+
$this->layout = $layout;
110+
return $this;
111+
}
112+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* An Apple News Document Advertising Layout.
6+
*/
7+
8+
namespace ChapterThree\AppleNewsAPI\Document\Layouts;
9+
10+
use ChapterThree\AppleNewsAPI\Document\Base;
11+
use ChapterThree\AppleNewsAPI\Document\Margin;
12+
13+
/**
14+
* An Apple News Document Advertising Layout.
15+
*/
16+
class AdvertisingLayout extends Base {
17+
18+
protected $margin;
19+
20+
/**
21+
* Getter for margin.
22+
*/
23+
public function getMargin() {
24+
return $this->margin;
25+
}
26+
27+
/**
28+
* Setter for margin.
29+
*
30+
* @param Margin $value
31+
* Margin.
32+
*
33+
* @return $this
34+
*/
35+
public function setMargin($value) {
36+
if (is_object($value) && !$value instanceof Margin) {
37+
$this->triggerError('Object not of type Margin');
38+
}
39+
else {
40+
$this->margin = $value;
41+
}
42+
return $this;
43+
}
44+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Tests for ChapterThree\AppleNewsAPI\Document\AdvertisingSettings.
6+
*/
7+
8+
use ChapterThree\AppleNewsAPI\Document\AdvertisingSettings;
9+
use ChapterThree\AppleNewsAPI\Document\Layouts\AdvertisingLayout;
10+
use ChapterThree\AppleNewsAPI\Document\Margin;
11+
12+
class AdvertisingSettingsTest extends PHPUnit_Framework_TestCase {
13+
14+
/**
15+
* Setting properties and outputting JSON.
16+
*/
17+
public function testSetters() {
18+
$obj = new AdvertisingSettings();
19+
20+
$expected = '{}';
21+
$this->assertEquals($expected, $obj->json());
22+
23+
$expected = '{"bannerType":"large","frequency":5,"layout":{"margin":{"top":10,"bottom":10}}}';
24+
$obj->setBannerType('any');
25+
$obj->setBannerType('double_height');
26+
$obj->setBannerType('standard');
27+
$obj->setBannerType('large');
28+
29+
$obj->setFrequency(0);
30+
$obj->setFrequency(10);
31+
$obj->setFrequency(5);
32+
33+
$ad_layout = new AdvertisingLayout();
34+
$ad_layout->setMargin(new Margin(10, 10));
35+
$obj->setLayout($ad_layout);
36+
$this->assertEquals($expected, $obj->json());
37+
}
38+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Tests for ChapterThree\AppleNewsAPI\Document\Layouts\AdvertisingLayout
6+
*/
7+
8+
use ChapterThree\AppleNewsAPI\Document\Layouts\AdvertisingLayout;
9+
use ChapterThree\AppleNewsAPI\Document\Margin;
10+
11+
class AdvertisingLayoutTest extends PHPUnit_Framework_TestCase {
12+
13+
/**
14+
* Settings properties and outputting JSON.
15+
*/
16+
public function testSetters() {
17+
$expected = '{"margin":{"top":10,"bottom":10}}';
18+
$obj = new AdvertisingLayout();
19+
$obj->setMargin(new Margin(10, 10));
20+
$this->assertEquals($expected, $obj->json());
21+
}
22+
}

0 commit comments

Comments
 (0)