wcc-blogs-client 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ea9c98dc8b5e8886d97ab7adf328cf694485a77
4
- data.tar.gz: 0d5fbf107cf251a77b4040985911343a6d438d03
3
+ metadata.gz: 0c78893a25c9e2252d2f9d74b98edda330431acb
4
+ data.tar.gz: 1279b6a5b6b9187e263fd08b44f6a8d49c41d59b
5
5
  SHA512:
6
- metadata.gz: 7fe9014018bde8b41d86788370ffce146293d3c1957f801bef609873829179f9e8f06e73362b230c48f4df4218a453eb1889f1d4ddbdec558b57e9c311569b1f
7
- data.tar.gz: 5835d4e614e6cd2b7bd76cba97d252c70d7b4c4b37722fcda0b46260e155fe1e01e8cb8c9eba7aae0e46c29b8e7935efe1a04ae373aea87e29f9d97391fe6f2b
6
+ metadata.gz: 9c934c2e891686e538d28c971493a6be00b52271b0030e2fcd63db63ba6c88867d2cf2056fe0af7887e34b34e9a0ae859992f93f6adf9490a21159021a6d2cc8
7
+ data.tar.gz: 4c78ff0155b8544737013998abf1ff0918948049306c9d3a89c40c6e4177bb10b99236538d1f254c7cb2bae28652682124cb9d2b4ceb1dd1c32f4ba7deeb64d5
@@ -6,10 +6,14 @@ require_relative 'client/response'
6
6
 
7
7
  module WCC::Blogs
8
8
  class Client
9
- attr_reader :base_url, :publishing_target, :base_path
9
+ attr_reader :base_url, :default_property, :base_path
10
10
 
11
- def initialize(publishing_target:, **options)
12
- @publishing_target = publishing_target
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 ||= publishing_target
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 ||= publishing_target
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) # rubocop:disable Metrics/AbcSize
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
- next if resp.raw['publishedProperties'].any? { |t| t['key'] == publishing_target }
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]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Blogs
5
- VERSION = '0.4.1'.freeze
5
+ VERSION = '0.5.0'.freeze
6
6
  end
7
7
  end
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.1
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-14 00:00:00.000000000 Z
11
+ date: 2019-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday