wcc-blogs-client 0.4.1 → 0.5.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 +4 -4
- data/lib/wcc/blogs/client.rb +23 -10
- data/lib/wcc/blogs/post_summary.rb +1 -1
- data/lib/wcc/blogs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c78893a25c9e2252d2f9d74b98edda330431acb
|
4
|
+
data.tar.gz: 1279b6a5b6b9187e263fd08b44f6a8d49c41d59b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c934c2e891686e538d28c971493a6be00b52271b0030e2fcd63db63ba6c88867d2cf2056fe0af7887e34b34e9a0ae859992f93f6adf9490a21159021a6d2cc8
|
7
|
+
data.tar.gz: 4c78ff0155b8544737013998abf1ff0918948049306c9d3a89c40c6e4177bb10b99236538d1f254c7cb2bae28652682124cb9d2b4ceb1dd1c32f4ba7deeb64d5
|
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,29 @@ 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
|
|
37
43
|
def blog_list(property: nil, year: nil)
|
38
|
-
property ||=
|
44
|
+
property ||= default_property
|
45
|
+
raise ArgumentError, 'No Property given' unless property
|
46
|
+
|
39
47
|
path = base_path + '/property/' + property + '/blog'
|
40
48
|
path += '/' + year if year
|
41
49
|
get(path).assert_ok!
|
42
50
|
end
|
43
51
|
|
44
|
-
def blog_show(slug, digest: nil)
|
52
|
+
def blog_show(slug, digest: nil)
|
45
53
|
path = base_path + '/blog/' + slug.sub(%r{^/}, '')
|
46
54
|
path += '/' + digest + '.json' if digest
|
47
55
|
|
48
56
|
get(path).tap do |resp|
|
49
57
|
resp.assert_ok!
|
50
|
-
|
51
|
-
|
52
|
-
raise WCC::Blogs::NotFoundException,
|
53
|
-
"Blog post '#{slug}' is not published to #{publishing_target}"
|
58
|
+
check_default_property(resp)
|
54
59
|
end
|
55
60
|
rescue WCC::Blogs::Client::NotFoundError => e
|
56
61
|
raise WCC::Blogs::NotFoundException, e.message
|
@@ -73,6 +78,14 @@ module WCC::Blogs
|
|
73
78
|
end
|
74
79
|
end
|
75
80
|
|
81
|
+
def check_default_property(resp)
|
82
|
+
return unless default_property
|
83
|
+
return if resp.raw['publishedProperties'].any? { |t| t['key'] == default_property }
|
84
|
+
|
85
|
+
raise WCC::Blogs::NotFoundException,
|
86
|
+
"Blog post '#{resp.raw['slug']}' is not published to #{default_property}"
|
87
|
+
end
|
88
|
+
|
76
89
|
def default_connection
|
77
90
|
::Faraday.new do |faraday|
|
78
91
|
faraday.use :http_cache,
|
@@ -24,7 +24,6 @@ module WCC::Blogs
|
|
24
24
|
'title',
|
25
25
|
'subtitle',
|
26
26
|
'slug',
|
27
|
-
'author',
|
28
27
|
'digest'
|
29
28
|
) do |camelcase|
|
30
29
|
raw[camelcase]
|
@@ -40,6 +39,7 @@ module WCC::Blogs
|
|
40
39
|
end
|
41
40
|
|
42
41
|
define_camelcase_alias(
|
42
|
+
'author',
|
43
43
|
'thumbnail_image'
|
44
44
|
) do |camelcase|
|
45
45
|
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
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.5.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: 2019-11-
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|