wcc-blogs-client 0.4.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +4 -0
- data/Guardfile +2 -0
- data/Rakefile +2 -0
- data/lib/wcc/blogs.rb +3 -0
- data/lib/wcc/blogs/client.rb +28 -10
- data/lib/wcc/blogs/client/response.rb +3 -1
- data/lib/wcc/blogs/collection.rb +49 -0
- data/lib/wcc/blogs/collection_summary.rb +28 -0
- data/lib/wcc/blogs/linked_blog_post_summary.rb +37 -0
- data/lib/wcc/blogs/post.rb +13 -5
- data/lib/wcc/blogs/post_summary.rb +7 -3
- data/lib/wcc/blogs/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c03beda095634dc9f7f82d9c993c17abb348ecb6cc5522955fad8679481a3891
|
4
|
+
data.tar.gz: 317d01f728b21a3b00bbe4680cfe6648c6a3f2b9ce3e4f30834608793cb7f15f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c86bb404e416d09a4cfb2d220963e72cb9f198e0a24aeb735c19500d544ca5e71a2a904e79c18a8ada419754337dc887ee88dc6a5466f690c93526570193a38
|
7
|
+
data.tar.gz: 3690cbbfa7fe6716be0426106c288eef1e58e2f42f9ceee3cfbe19fe4312f07ff4ee7a0c3d112398fb04c9818d0d52903591c66e443e1559d3b830efbf35146a
|
data/.rubocop.yml
CHANGED
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/lib/wcc/blogs.rb
CHANGED
@@ -10,7 +10,10 @@ require 'wcc/blogs/errors'
|
|
10
10
|
require 'wcc/blogs/metadata'
|
11
11
|
require 'wcc/blogs/post'
|
12
12
|
require 'wcc/blogs/post_summary'
|
13
|
+
require 'wcc/blogs/linked_blog_post_summary'
|
13
14
|
require 'wcc/blogs/property'
|
15
|
+
require 'wcc/blogs/collection'
|
16
|
+
require 'wcc/blogs/collection_summary'
|
14
17
|
|
15
18
|
module WCC::Blogs
|
16
19
|
class << self
|
data/lib/wcc/blogs/client.rb
CHANGED
@@ -6,10 +6,14 @@ require_relative 'client/response'
|
|
6
6
|
|
7
7
|
module WCC::Blogs
|
8
8
|
class Client
|
9
|
-
attr_reader :base_url, :
|
9
|
+
attr_reader :base_url, :default_property, :base_path
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
|
11
|
+
def initialize(**options)
|
12
|
+
if options[:publishing_target]
|
13
|
+
raise ArgumentError, 'publishing_target has been renamed to default_property'
|
14
|
+
end
|
15
|
+
|
16
|
+
@default_property = options[:default_property]
|
13
17
|
base_url = URI.parse(options[:base_url] || 'https://di0v2frwtdqnv.cloudfront.net')
|
14
18
|
@base_path = base_url.path == '' ? '/api/v1' : base_url.path
|
15
19
|
@base_url = base_url.to_s
|
@@ -29,28 +33,34 @@ module WCC::Blogs
|
|
29
33
|
end
|
30
34
|
|
31
35
|
def property_show(property = nil)
|
32
|
-
property ||=
|
36
|
+
property ||= default_property
|
37
|
+
raise ArgumentError, 'No Property given' unless property
|
38
|
+
|
33
39
|
path = base_path + '/property/' + property
|
34
40
|
get(path).assert_ok!
|
35
41
|
end
|
36
42
|
|
43
|
+
def collection_show(key)
|
44
|
+
path = base_path + '/collection/' + key
|
45
|
+
get(path).assert_ok!
|
46
|
+
end
|
47
|
+
|
37
48
|
def blog_list(property: nil, year: nil)
|
38
|
-
property ||=
|
49
|
+
property ||= default_property
|
50
|
+
raise ArgumentError, 'No Property given' unless property
|
51
|
+
|
39
52
|
path = base_path + '/property/' + property + '/blog'
|
40
53
|
path += '/' + year if year
|
41
54
|
get(path).assert_ok!
|
42
55
|
end
|
43
56
|
|
44
|
-
def blog_show(slug, digest: nil)
|
57
|
+
def blog_show(slug, digest: nil)
|
45
58
|
path = base_path + '/blog/' + slug.sub(%r{^/}, '')
|
46
59
|
path += '/' + digest + '.json' if digest
|
47
60
|
|
48
61
|
get(path).tap do |resp|
|
49
62
|
resp.assert_ok!
|
50
|
-
|
51
|
-
|
52
|
-
raise WCC::Blogs::NotFoundException,
|
53
|
-
"Blog post '#{slug}' is not published to #{publishing_target}"
|
63
|
+
check_default_property(resp)
|
54
64
|
end
|
55
65
|
rescue WCC::Blogs::Client::NotFoundError => e
|
56
66
|
raise WCC::Blogs::NotFoundException, e.message
|
@@ -73,6 +83,14 @@ module WCC::Blogs
|
|
73
83
|
end
|
74
84
|
end
|
75
85
|
|
86
|
+
def check_default_property(resp)
|
87
|
+
return unless default_property
|
88
|
+
return if resp.raw['publishedProperties'].any? { |t| t['key'] == default_property }
|
89
|
+
|
90
|
+
raise WCC::Blogs::NotFoundException,
|
91
|
+
"Blog post '#{resp.raw['slug']}' is not published to #{default_property}"
|
92
|
+
end
|
93
|
+
|
76
94
|
def default_connection
|
77
95
|
::Faraday.new do |faraday|
|
78
96
|
faraday.use :http_cache,
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
module WCC::Blogs
|
@@ -18,7 +20,7 @@ module WCC::Blogs
|
|
18
20
|
alias_method :to_json, :raw
|
19
21
|
|
20
22
|
def next_page_url
|
21
|
-
raw.dig('_links', '
|
23
|
+
raw.dig('_links', 'next')
|
22
24
|
end
|
23
25
|
|
24
26
|
def next_page?
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::Blogs
|
4
|
+
class Collection
|
5
|
+
extend WCC::Blogs::Utils
|
6
|
+
|
7
|
+
def self.find(key = nil)
|
8
|
+
new(WCC::Blogs.client.collection_show(key).raw, client: WCC::Blogs.client)
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :raw
|
12
|
+
|
13
|
+
def initialize(raw, client: WCC::Blogs.client)
|
14
|
+
@raw = raw
|
15
|
+
@client = client
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_param
|
19
|
+
key
|
20
|
+
end
|
21
|
+
|
22
|
+
define_camelcase_alias(
|
23
|
+
'key',
|
24
|
+
'title',
|
25
|
+
'digest'
|
26
|
+
) do |camelcase|
|
27
|
+
raw[camelcase]
|
28
|
+
end
|
29
|
+
|
30
|
+
define_camelcase_alias(
|
31
|
+
'hero_image'
|
32
|
+
) do |camelcase|
|
33
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
34
|
+
end
|
35
|
+
|
36
|
+
def posts
|
37
|
+
@posts ||=
|
38
|
+
(raw['posts'] || []).map do |summary|
|
39
|
+
PostSummary.new(summary, client: @client)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def _links
|
44
|
+
OpenStruct.new(raw['_links'] || {})
|
45
|
+
end
|
46
|
+
|
47
|
+
alias cache_key digest
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::Blogs
|
4
|
+
class CollectionSummary
|
5
|
+
extend WCC::Blogs::Utils
|
6
|
+
|
7
|
+
attr_reader :raw
|
8
|
+
|
9
|
+
def initialize(raw, client: WCC::Blogs.client)
|
10
|
+
@raw = raw
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
define_camelcase_alias(
|
15
|
+
'key',
|
16
|
+
'title'
|
17
|
+
) do |camelcase|
|
18
|
+
raw[camelcase]
|
19
|
+
end
|
20
|
+
|
21
|
+
def posts
|
22
|
+
@posts ||=
|
23
|
+
(raw['posts'] || []).map do |summary|
|
24
|
+
WCC::Blogs::LinkedBlogPostSummary.new(summary, client: @client)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::Blogs
|
4
|
+
class LinkedBlogPostSummary
|
5
|
+
extend WCC::Blogs::Utils
|
6
|
+
|
7
|
+
attr_reader :raw
|
8
|
+
|
9
|
+
def initialize(raw, client: WCC::Blogs.client)
|
10
|
+
@raw = raw
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_post
|
15
|
+
Post.new(@client.get(_links.self).raw)
|
16
|
+
end
|
17
|
+
|
18
|
+
define_camelcase_alias(
|
19
|
+
'title',
|
20
|
+
'slug'
|
21
|
+
) do |camelcase|
|
22
|
+
raw[camelcase]
|
23
|
+
end
|
24
|
+
|
25
|
+
define_camelcase_alias(
|
26
|
+
'date'
|
27
|
+
) do |camelcase|
|
28
|
+
value = raw[camelcase]
|
29
|
+
|
30
|
+
Time.parse(value) if value&.length
|
31
|
+
end
|
32
|
+
|
33
|
+
def _links
|
34
|
+
OpenStruct.new(raw['_links'] || {})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/wcc/blogs/post.rb
CHANGED
@@ -21,9 +21,7 @@ module WCC::Blogs
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def author_full_name
|
24
|
-
|
25
|
-
|
26
|
-
[author.firstName, author.lastName].compact.join(' ')
|
24
|
+
author&.fullName
|
27
25
|
end
|
28
26
|
|
29
27
|
def html
|
@@ -69,13 +67,14 @@ module WCC::Blogs
|
|
69
67
|
) do |camelcase|
|
70
68
|
value = raw[camelcase]
|
71
69
|
|
72
|
-
Time.parse(value) if value
|
70
|
+
Time.parse(value) if value&.length
|
73
71
|
end
|
74
72
|
|
75
73
|
define_camelcase_alias(
|
76
74
|
'author',
|
77
75
|
'hero_image',
|
78
|
-
'thumbnail_image'
|
76
|
+
'thumbnail_image',
|
77
|
+
'flags'
|
79
78
|
) do |camelcase|
|
80
79
|
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
81
80
|
end
|
@@ -94,6 +93,15 @@ module WCC::Blogs
|
|
94
93
|
targets.map { |val| OpenStruct.new(val) if val }
|
95
94
|
end
|
96
95
|
|
96
|
+
def collection
|
97
|
+
CollectionSummary.new(raw['collection'], client: @client) if raw['collection']
|
98
|
+
end
|
99
|
+
|
100
|
+
define_camelcase_alias('related_posts') do |camelcase|
|
101
|
+
related = raw[camelcase] || []
|
102
|
+
related.map { |val| WCC::Blogs::LinkedBlogPostSummary.new(val, client: @client) }
|
103
|
+
end
|
104
|
+
|
97
105
|
alias cache_key digest
|
98
106
|
end
|
99
107
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WCC::Blogs
|
2
4
|
class PostSummary
|
3
5
|
extend WCC::Blogs::Utils
|
@@ -24,7 +26,6 @@ module WCC::Blogs
|
|
24
26
|
'title',
|
25
27
|
'subtitle',
|
26
28
|
'slug',
|
27
|
-
'author',
|
28
29
|
'digest'
|
29
30
|
) do |camelcase|
|
30
31
|
raw[camelcase]
|
@@ -36,11 +37,14 @@ module WCC::Blogs
|
|
36
37
|
) do |camelcase|
|
37
38
|
value = raw[camelcase]
|
38
39
|
|
39
|
-
Time.parse(value) if value
|
40
|
+
Time.parse(value) if value&.length
|
40
41
|
end
|
41
42
|
|
42
43
|
define_camelcase_alias(
|
43
|
-
'
|
44
|
+
'author',
|
45
|
+
'hero_image',
|
46
|
+
'thumbnail_image',
|
47
|
+
'flags'
|
44
48
|
) do |camelcase|
|
45
49
|
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
46
50
|
end
|
data/lib/wcc/blogs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wcc-blogs-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Watermark Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -195,7 +195,10 @@ files:
|
|
195
195
|
- lib/wcc/blogs.rb
|
196
196
|
- lib/wcc/blogs/client.rb
|
197
197
|
- lib/wcc/blogs/client/response.rb
|
198
|
+
- lib/wcc/blogs/collection.rb
|
199
|
+
- lib/wcc/blogs/collection_summary.rb
|
198
200
|
- lib/wcc/blogs/errors.rb
|
201
|
+
- lib/wcc/blogs/linked_blog_post_summary.rb
|
199
202
|
- lib/wcc/blogs/metadata.rb
|
200
203
|
- lib/wcc/blogs/post.rb
|
201
204
|
- lib/wcc/blogs/post_summary.rb
|
@@ -223,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
226
|
version: '0'
|
224
227
|
requirements: []
|
225
228
|
rubyforge_project:
|
226
|
-
rubygems_version: 2.
|
229
|
+
rubygems_version: 2.7.6
|
227
230
|
signing_key:
|
228
231
|
specification_version: 4
|
229
232
|
summary: ''
|