Skip to content

Commit 7efc706

Browse files
committed
Add all metadata fields in iOS
1 parent a858ea3 commit 7efc706

File tree

4 files changed

+254
-8
lines changed

4 files changed

+254
-8
lines changed

Sources/Metadata.swift

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,60 @@ public class ParselyMetadata {
2727
*/
2828
public init(canonical_url: String? = nil,
2929
pub_date: Date? = nil,
30+
save_date: Date? = nil,
3031
title: String? = nil,
3132
authors: Array<String>? = nil,
3233
image_url: String? = nil,
3334
section: String? = nil,
3435
tags: Array<String>? = nil,
3536
duration: TimeInterval? = nil,
36-
page_type: String? = nil) {
37+
page_type: String? = nil
38+
urls: String? = nil,
39+
post_id: String? = nil,
40+
pub_date_tmsp: Date? = nil,
41+
custom_metadata: String? = nil,
42+
save_date_tmsp: Date? = nil,
43+
thumb_url: String? = nil,
44+
full_content_word_count: Int? = nil,
45+
share_urls: Array<String>? = nil,
46+
data_source: String? = nil,
47+
canonical_hash: String? = nil,
48+
canonical_hash64: String? = nil,
49+
video_platform: String? = nil,
50+
language: String? = nil,
51+
full_content: String? = nil,
52+
full_content_sha512: String? = nil,
53+
network_id_str: String? = nil,
54+
network_canonical: String? = nil,
55+
content_enrichments: Dictionary<String, Any>? = nil) {
3756
self.canonical_url = canonical_url
3857
self.pub_date = pub_date
58+
self.save_date = save_date
3959
self.title = title
4060
self.authors = authors
4161
self.image_url = image_url
4262
self.section = section
4363
self.tags = tags
4464
self.duration = duration
4565
self.page_type = page_type
66+
self.urls = urls
67+
self.post_id = post_id
68+
self.pub_date_tmsp = pub_date_tmsp
69+
self.custom_metadata = custom_metadata
70+
self.save_date_tmsp = save_date_tmsp
71+
self.thumb_url = thumb_url
72+
self.full_content_word_count = full_content_word_count
73+
self.share_urls = share_urls
74+
self.data_source = data_source
75+
self.canonical_hash = canonical_hash
76+
self.canonical_hash64 = canonical_hash64
77+
self.video_platform = video_platform
78+
self.language = language
79+
self.full_content = full_content
80+
self.full_content_sha512 = full_content_sha512
81+
self.network_id_str = network_id_str
82+
self.network_canonical = network_canonical
83+
self.content_enrichments = content_enrichments
4684
}
4785

4886
func toDict() -> Dictionary<String, Any> {
@@ -54,6 +92,9 @@ public class ParselyMetadata {
5492
if let pub_date {
5593
metas["pub_date"] = String(format:"%i", pub_date.millisecondsSince1970)
5694
}
95+
if let save_date {
96+
metas["save_date"] = String(format:"%i", save_date.millisecondsSince1970)
97+
}
5798
if let title {
5899
metas["title"] = title
59100
}
@@ -75,7 +116,60 @@ public class ParselyMetadata {
75116
if let page_type {
76117
metas["page_type"] = page_type
77118
}
78-
119+
if let urls {
120+
metas["urls"] = urls
121+
}
122+
if let post_id {
123+
metas["post_id"] = post_id
124+
}
125+
if let pub_date_tmsp {
126+
metas["pub_date_tmsp"] = String(format:"%i", pub_date_tmsp.millisecondsSince1970)
127+
}
128+
if let custom_metadata {
129+
metas["custom_metadata"] = custom_metadata
130+
}
131+
if let save_date_tmsp {
132+
metas["save_date_tmsp"] = String(format:"%i", save_date_tmsp.millisecondsSince1970)
133+
}
134+
if let thumb_url {
135+
metas["thumb_url"] = thumb_url
136+
}
137+
if let full_content_word_count {
138+
metas["full_content_word_count"] = full_content_word_count
139+
}
140+
if let share_urls {
141+
metas["share_urls"] = share_urls
142+
}
143+
if let data_source {
144+
metas["data_source"] = data_source
145+
}
146+
if let canonical_hash {
147+
metas["canonical_hash"] = canonical_hash
148+
}
149+
if let canonical_hash64 {
150+
metas["canonical_hash64"] = canonical_hash64
151+
}
152+
if let video_platform {
153+
metas["video_platform"] = video_platform
154+
}
155+
if let language {
156+
metas["language"] = language
157+
}
158+
if let full_content {
159+
metas["full_content"] = full_content
160+
}
161+
if let full_content_sha512 {
162+
metas["full_content_sha512"] = full_content_sha512
163+
}
164+
if let network_id_str {
165+
metas["network_id_str"] = network_id_str
166+
}
167+
if let network_canonical {
168+
metas["network_canonical"] = network_canonical
169+
}
170+
if let content_enrichments {
171+
metas["content_enrichments"] = content_enrichments
172+
}
79173
return metas
80174
}
81175
}

Tests/MetadataTests.swift

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,32 @@ class MetadataTests: XCTestCase {
66
let expected: Dictionary<String, Any> = [
77
"canonical_url": "http://parsely-test.com",
88
"pub_date": Date(),
9+
"save_date": Date(),
910
"title": "a title.",
1011
"authors": ["Yogi Berra"],
1112
"image_url": "http://parsely-test.com/image2",
1213
"section": "Things my mother says",
1314
"tags": ["tag1", "tag2"],
1415
"duration": TimeInterval(100),
15-
"page_type": "post"
16+
"page_type": "post",
17+
"urls": "http://parsely-test.com",
18+
"post_id": "1",
19+
"pub_date_tmsp": Date(),
20+
"custom_metadata": "hedgehogs",
21+
"save_date_tmsp": Date(),
22+
"thumb_url": "http://parsely-test.com/image2",
23+
"full_content_word_count": 100,
24+
"share_urls": ["http://parsely-test.com"],
25+
"data_source": "the moon",
26+
"canonical_hash": "hash_browns",
27+
"canonical_hash64": "hash_browns64",
28+
"video_platform": "youtube",
29+
"language": "en",
30+
"full_content": "the full content of the article",
31+
"full_content_sha512": "what is this?",
32+
"network_id_str": "abc",
33+
"network_canonical": "network canonical"
34+
1635
]
1736

1837
func testToDictEmpty() {
@@ -33,16 +52,37 @@ class MetadataTests: XCTestCase {
3352
let metasUnderTest = ParselyMetadata(
3453
canonical_url: expected["canonical_url"] as? String,
3554
pub_date: expected["pub_date"] as? Date,
55+
save_date: expected["save_date"] as? Date,
3656
title: expected["title"] as? String,
3757
authors: expected["authors"] as? Array<String>,
3858
image_url: expected["image_url"] as? String,
3959
section: expected["section"] as? String,
4060
tags: expected["tags"] as? Array<String>,
4161
duration: expected["duration"] as? TimeInterval,
42-
page_type: expected["page_type"] as? String
62+
page_type: expected["page_type"] as? String,
63+
urls: expected["urls"] as? String,
64+
post_id: expected["post_id"] as? String,
65+
pub_date_tmsp: expected["pub_date_tmsp"] as? Date,
66+
custom_metadata: expected["custom_metadata"] as? String,
67+
save_date_tmsp: expected["save_date_tmsp"] as? Date,
68+
thumb_url: expected["thumb_url"] as? String,
69+
full_content_word_count: expected["full_content_word_count"] as? Int,
70+
share_urls: expected["share_urls"] as? Array<String>,
71+
data_source: expected["data_source"] as? String,
72+
canonical_hash: expected["canonical_hash"] as? String,
73+
canonical_hash64: expected["canonical_hash64"] as? String,
74+
video_platform: expected["video_platform"] as? String,
75+
language: expected["language"] as? String,
76+
full_content: expected["full_content"] as? String,
77+
full_content_sha512: expected["full_content_sha512"] as? String,
78+
network_id_str: expected["network_id_str"] as? String,
79+
network_canonical: expected["network_canonical"] as? String
4380
)
4481
let actual: Dictionary<String, Any> = metasUnderTest.toDict()
4582
let pubDateUnix: String = String(format:"%i", (expected["pub_date"]! as! Date).millisecondsSince1970)
83+
let saveDateUnix: String = String(format:"%i", (expected["save_date"]! as! Date).millisecondsSince1970)
84+
let pubDateTmspUnix: String = String(format:"%i", (expected["pub_date_tmsp"]! as! Date).millisecondsSince1970)
85+
let saveDateTmspUnix: String = String(format:"%i", (expected["save_date_tmsp"]! as! Date).millisecondsSince1970)
4686
XCTAssertFalse(actual.isEmpty, "Creating a ParselyMetadataobject with many parameters results in a " +
4787
"non-empty object")
4888
XCTAssertEqual(actual["link"]! as! String, expected["canonical_url"]! as! String,
@@ -51,6 +91,9 @@ class MetadataTests: XCTestCase {
5191
XCTAssertEqual(actual["pub_date"]! as! String, pubDateUnix,
5292
"The pub_date field in the result of ParselyMetadata.toDict should match the pub_date argument " +
5393
"used at initialization")
94+
XCTAssertEqual(actual["save_date"]! as! String, pubDateUnix,
95+
"The save_date field in the result of ParselyMetadata.toDict should match the save_date argument " +
96+
"used at initialization")
5497
XCTAssertEqual(actual["title"]! as! String, expected["title"]! as! String,
5598
"The title field in the result of ParselyMetadata.toDict should match the title argument " +
5699
"used at initialization")
@@ -71,7 +114,58 @@ class MetadataTests: XCTestCase {
71114
"used at initialization")
72115
XCTAssertEqual(actual["page_type"]! as! String, expected["page_type"]! as! String,
73116
"The page_type field in the result of ParselyMetadata.toDict should match the page_type argument " +
74-
"used at initialization")
117+
"used at initialization")
118+
XCTAssertEqual(actual["urls"]! as! String, expected["urls"]! as! String,
119+
"The urls field in the result of ParselyMetadata.toDict should match the urls argument " +
120+
"used at initialization")
121+
XCTAssertEqual(actual["post_id"]! as! String, expected["post_id"]! as! String,
122+
"The post_id field in the result of ParselyMetadata.toDict should match the post_id argument " +
123+
"used at initialization")
124+
XCTAssertEqual(actual["pub_date_tmsp"]! as! String, pubDateTmspUnix,
125+
"The pub_date_tmsp field in the result of ParselyMetadata.toDict should match the pub_date_tmsp argument " +
126+
"used at initialization")
127+
XCTAssertEqual(actual["custom_metadata"]! as! String, expected["custom_metadata"]! as! String,
128+
"The custom_metadata field in the result of ParselyMetadata.toDict should match the custom_metadata argument " +
129+
"used at initialization")
130+
XCTAssertEqual(actual["save_date_tmsp"]! as! String, saveDateTmspUnix,
131+
"The save_date_tmsp field in the result of ParselyMetadata.toDict should match the save_date_tmsp argument " +
132+
"used at initialization")
133+
XCTAssertEqual(actual["thumb_url"]! as! String, expected["thumb_url"]! as! String,
134+
"The thumb_url field in the result of ParselyMetadata.toDict should match the thumb_url argument " +
135+
"used at initialization")
136+
XCTAssertEqual(actual["full_content_word_count"]! as! Int, expected["full_content_word_count"]! as! Int,
137+
"The full_content_word_count field in the result of ParselyMetadata.toDict should match the full_content_word_count argument " +
138+
"used at initialization")
139+
XCTAssertEqual(actual["share_urls"]! as! Array<String>, expected["share_urls"]! as! Array<String>,
140+
"The share_urls field in the result of ParselyMetadata.toDict should match the share_urls argument " +
141+
"used at initialization")
142+
XCTAssertEqual(actual["data_source"]! as! String, expected["data_source"]! as! String,
143+
"The data_source field in the result of ParselyMetadata.toDict should match the data_source argument " +
144+
"used at initialization")
145+
XCTAssertEqual(actual["canonical_hash"]! as! String, expected["canonical_hash"]! as! String,
146+
"The canonical_hash field in the result of ParselyMetadata.toDict should match the canonical_hash argument " +
147+
"used at initialization")
148+
XCTAssertEqual(actual["canonical_hash64"]! as! String, expected["canonical_hash64"]! as! String,
149+
"The canonical_hash64 field in the result of ParselyMetadata.toDict should match the canonical_hash64 argument " +
150+
"used at initialization")
151+
XCTAssertEqual(actual["video_platform"]! as! String, expected["video_platform"]! as! String,
152+
"The video_platform field in the result of ParselyMetadata.toDict should match the video_platform argument " +
153+
"used at initialization")
154+
XCTAssertEqual(actual["language"]! as! String, expected["language"]! as! String,
155+
"The language field in the result of ParselyMetadata.toDict should match the language argument " +
156+
"used at initialization")
157+
XCTAssertEqual(actual["full_content"]! as! String, expected["full_content"]! as! String,
158+
"The full_content field in the result of ParselyMetadata.toDict should match the full_content argument " +
159+
"used at initialization")
160+
XCTAssertEqual(actual["full_content_sha512"]! as! String, expected["full_content_sha512"]! as! String,
161+
"The full_content_sha512 field in the result of ParselyMetadata.toDict should match the full_content_sha512 argument " +
162+
"used at initialization")
163+
XCTAssertEqual(actual["network_id_str"]! as! String, expected["network_id_str"]! as! String,
164+
"The network_id_str field in the result of ParselyMetadata.toDict should match the network_id_str argument " +
165+
"used at initialization")
166+
XCTAssertEqual(actual["network_canonical"]! as! String, expected["network_canonical"]! as! String,
167+
"The network_canonical field in the result of ParselyMetadata.toDict should match the network_canonical argument " +
168+
"used at initialization")
75169
}
76170

77171
func testMetadata() {

Tests/RequestBuilderTests.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@ class RequestBuilderTests: XCTestCase {
88
let exampleMetadata: ParselyMetadata = ParselyMetadata(
99
canonical_url:"http://parsely-test.com",
1010
pub_date: Date(timeIntervalSince1970: 3),
11+
save_date: Date(timeIntervalSince1970: 4),
1112
title: "a title.",
1213
authors: ["Yogi Berra"],
1314
image_url: "http://parsely-test.com/image2",
1415
section: "Things my mother says",
1516
tags: ["tag1", "tag2"],
1617
duration: TimeInterval(100),
17-
page_type: "post"
18+
page_type: "post",
19+
urls: ["http://parsely-test.com/1", "http://parsely-test.com/2"],
20+
post_id: "1",
21+
pub_date_tmsp: Date(timeIntervalSince1970: 5),
22+
custom_metadata: "custom",
23+
save_date_tmsp: Date(timeIntervalSince1970: 6),
24+
thumb_url: "http://parsely-test.com/thumb",
25+
full_content_word_count: 1000,
26+
share_urls: ["http://parsely-test.com/share1", "http://parsely-test.com/share2"],
27+
data_source: "test",
28+
canonical_hash: "hash",
29+
canonical_hash64: "hash64",
30+
video_platform: "youtube",
31+
language: "en",
32+
full_content: "full content",
33+
full_content_sha512: "full content sha512",
34+
network_id_str: "network id",
35+
network_canonical: "http://parsely-test.com/network_canonical",
36+
content_enrichments: {"enrichment1": "value1", "enrichment2": "value2"}
1837
)
1938
return [Event(
2039
"pageview",

Tests/VideoTests.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,32 @@ class VideoTests: ParselyTestCase {
7373
let firstTestMetadata = ParselyMetadata(
7474
canonical_url: testUrl,
7575
pub_date: Date(),
76+
save_date: Date(),
7677
title: "test",
7778
authors: nil,
7879
image_url: nil,
7980
section: testSectionFirst,
8081
tags: nil,
8182
duration: nil,
82-
page_type: nil
83+
page_type: "post",
84+
urls: nil,
85+
post_id: nil,
86+
pub_date_tmsp: nil,
87+
custom_metadata: nil,
88+
save_date_tmsp: nil,
89+
thumb_url: nil,
90+
full_content_word_count: nil,
91+
share_urls: nil,
92+
data_source: nil,
93+
canonical_hash: nil,
94+
canonical_hash64: nil,
95+
video_platform: nil,
96+
language: nil,
97+
full_content: nil,
98+
full_content_sha512: nil,
99+
network_id_str: nil,
100+
network_canonical: nil,
101+
content_enrichments: nil
83102
)
84103

85104
videoManager.trackPlay(
@@ -100,13 +119,33 @@ class VideoTests: ParselyTestCase {
100119
let secondTestMetadata = ParselyMetadata(
101120
canonical_url: testUrl,
102121
pub_date: Date(),
122+
save_date: Date(),
103123
title: "test",
104124
authors: nil,
105125
image_url: nil,
106126
section: testSectionSecond,
107127
tags: nil,
108128
duration: nil,
109-
page_type: nil
129+
page_type: nil,
130+
page_type: "post",
131+
urls: nil,
132+
post_id: nil,
133+
pub_date_tmsp: nil,
134+
custom_metadata: nil,
135+
save_date_tmsp: nil,
136+
thumb_url: nil,
137+
full_content_word_count: nil,
138+
share_urls: nil,
139+
data_source: nil,
140+
canonical_hash: nil,
141+
canonical_hash64: nil,
142+
video_platform: nil,
143+
language: nil,
144+
full_content: nil,
145+
full_content_sha512: nil,
146+
network_id_str: nil,
147+
network_canonical: nil,
148+
content_enrichments: nil
110149
)
111150

112151
videoManager.trackPlay(

0 commit comments

Comments
 (0)