wcc-blogs-client 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cc54b2ea711debb4b4cd66ff1741ad5c159316d
4
- data.tar.gz: e1c666d7b2f98185a8e8b7bd668f2ec95d6d3769
3
+ metadata.gz: 91c71241330bf18f4d6561c4b34a44ef9a4d9a36
4
+ data.tar.gz: b822af919ef3a0521440c9f82050ca94e1b59e1a
5
5
  SHA512:
6
- metadata.gz: 4f09bf8377c4c0e7ab5e5842ea587f4138bec8278acd4ff8cb1ad04eafe0761f2f88f700bfb674f4b20ae2f19d850cf99c8b2cc6ea0d071a5ef974c1db66b61e
7
- data.tar.gz: eefc6154686859afbd7b1db05726ca756820dbd25f2009359112f5b353fcc6b66dec552f3bb5f777c35da4c49bbc75acd079407660a272a2fddc06f6f42f4796
6
+ metadata.gz: e2f0fec0ce8116c8fa79af618abe0b4a580796b1368b0b1ad963b24b3e7648f31c4dda3ab569a5dfa45fe440750cb959721e1cc29f7f1e99ab8d51ff589eb8ea
7
+ data.tar.gz: 5403a6f4122e7a23002afb7c2dfdfe07840e008316adcc7f1bf3812d92f303a115dec900a1a62fc4c2860c07b26f763121842370651ea47f91cafa6001714538
data/.rubocop.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
+ Lint/AssignmentInCondition:
4
+ Enabled: false
5
+
3
6
  Metrics/BlockLength:
4
7
  Exclude:
5
8
  - 'wcc-blogs-client.gemspec'
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-05-10 13:54:26 -0500 using RuboCop version 0.60.0.
3
+ # on 2019-05-13 14:26:19 -0500 using RuboCop version 0.60.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -13,12 +13,6 @@ Gemspec/RequiredRubyVersion:
13
13
  Exclude:
14
14
  - 'wcc-blogs-client.gemspec'
15
15
 
16
- # Offense count: 1
17
- # Configuration parameters: AllowSafeAssignment.
18
- Lint/AssignmentInCondition:
19
- Exclude:
20
- - 'lib/wcc/blogs/client.rb'
21
-
22
16
  # Offense count: 3
23
17
  # Cop supports --auto-correct.
24
18
  # Configuration parameters: EnforcedStyle.
@@ -43,7 +37,7 @@ Style/TrailingCommaInHashLiteral:
43
37
  Exclude:
44
38
  - 'lib/wcc/blogs/client.rb'
45
39
 
46
- # Offense count: 6
40
+ # Offense count: 8
47
41
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
48
42
  # URISchemes: http, https
49
43
  Metrics/LineLength:
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WCC::Blogs
4
+ class Metadata
5
+ extend WCC::Blogs::Utils
6
+
7
+ attr_reader :raw
8
+
9
+ def initialize(raw)
10
+ @raw = raw
11
+ end
12
+
13
+ define_camelcase_alias(
14
+ 'id',
15
+ 'canonical_link',
16
+ 'meta_description',
17
+ 'meta_flag'
18
+ ) do |camelcase|
19
+ raw[camelcase]
20
+ end
21
+
22
+ define_camelcase_alias('meta_keywords') do |camelcase|
23
+ return [] unless keywords = raw[camelcase]
24
+
25
+ # Currently the json looks like this:
26
+ # "metaKeywords": {
27
+ # "metaKeywords": "regeneration, recovery"
28
+ # },
29
+ # TODO: make it like this - "metaKeywords": "regeneration, recovery"
30
+ keywords = keywords[camelcase] if keywords.is_a?(Hash) && keywords[camelcase]
31
+
32
+ keywords
33
+ end
34
+ end
35
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module WCC::Blogs
4
4
  class Post
5
+ extend WCC::Blogs::Utils
5
6
  require 'time'
6
7
 
7
8
  def self.find(slug)
@@ -23,10 +24,6 @@ module WCC::Blogs
23
24
  [author.firstName, author.lastName].compact.join(' ')
24
25
  end
25
26
 
26
- def date
27
- publish_at || created_at
28
- end
29
-
30
27
  def html
31
28
  @html ||=
32
29
  WCC::Blogs.config.cache.fetch(['BlogPost', fragment_path]) do
@@ -34,11 +31,14 @@ module WCC::Blogs
34
31
  end
35
32
  end
36
33
 
34
+ def metadata
35
+ WCC::Blogs::Metadata.new(raw['metadata']) if raw['metadata']
36
+ end
37
+
37
38
  def published?
38
39
  return false if publishing_targets.empty?
39
40
 
40
- publishing_targets.any? { |t| t['key'] == WCC::Blogs.config.publishing_target } &&
41
- (!publish_at || (publish_at <= Time.now))
41
+ publishing_targets.any? { |t| t['key'] == WCC::Blogs.config.publishing_target }
42
42
  end
43
43
 
44
44
  def time_to_read
@@ -50,72 +50,41 @@ module WCC::Blogs
50
50
  slug.sub(%r{^/}, '')
51
51
  end
52
52
 
53
- def self.camelcase(str)
54
- str.gsub(/_(\w)/) { Regexp.last_match(1).upcase }
55
- end
56
-
57
- %w[
58
- id
59
- title
60
- subtitle
61
- slug
62
- host
63
- path
64
- digest
65
- fragment_path
66
- ].each do |method|
67
- attribute = camelcase(method)
68
-
69
- define_method method do
70
- raw[attribute]
71
- end
72
-
73
- alias_method attribute, method if attribute != method
53
+ define_camelcase_alias(
54
+ 'id',
55
+ 'title',
56
+ 'subtitle',
57
+ 'slug',
58
+ 'host',
59
+ 'path',
60
+ 'digest',
61
+ 'fragment_path'
62
+ ) do |camelcase|
63
+ raw[camelcase]
74
64
  end
75
65
 
76
- %w[
77
- created_at
78
- publish_at
79
- updated_at
80
- ].each do |method|
81
- attribute = camelcase(method)
66
+ define_camelcase_alias(
67
+ 'date'
68
+ ) do |camelcase|
69
+ value = raw[camelcase]
82
70
 
83
- define_method method do
84
- value = raw[attribute]
85
- return unless value && value.length
71
+ return unless value && value.length
86
72
 
87
- Time.parse(value)
88
- end
89
-
90
- alias_method attribute, method if attribute != method
73
+ Time.parse(value)
91
74
  end
92
75
 
93
- %w[
94
- author
95
- hero_image
96
- thumbnail_image
97
- ].each do |method|
98
- attribute = camelcase(method)
99
-
100
- define_method method do
101
- OpenStruct.new(raw[attribute]) if raw[attribute]
102
- end
103
-
104
- alias_method attribute, method if attribute != method
76
+ define_camelcase_alias(
77
+ 'author',
78
+ 'hero_image',
79
+ 'thumbnail_image'
80
+ ) do |camelcase|
81
+ OpenStruct.new(raw[camelcase]) if raw[camelcase]
105
82
  end
106
83
 
107
- %w[
108
- publishing_targets
109
- ].each do |method|
110
- attribute = camelcase(method)
111
-
112
- define_method method do
113
- return [] unless raw[attribute]
114
-
115
- raw[attribute].map { |val| OpenStruct.new(val) if val }
116
- end
84
+ define_camelcase_alias('publishing_targets') do |camelcase|
85
+ return [] unless raw[camelcase]
117
86
 
118
- alias_method attribute, method if attribute != method
87
+ raw[camelcase].map { |val| OpenStruct.new(val) if val }
119
88
  end
120
89
 
121
90
  alias cache_key digest
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WCC::Blogs
4
+ module Utils
5
+ def camelcase(term)
6
+ term
7
+ .to_s
8
+ .gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
9
+ .gsub(%r{/}, '::')
10
+ end
11
+
12
+ def define_camelcase_alias(*underscore_method_names, &block)
13
+ underscore_method_names.each do |method|
14
+ attribute = camelcase(method)
15
+
16
+ define_method(method) { instance_exec(attribute, &block) }
17
+ alias_method attribute, method if attribute != method
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Blogs
5
- VERSION = '0.2.0'.freeze
5
+ VERSION = '0.3.0'.freeze
6
6
  end
7
7
  end
data/lib/wcc/blogs.rb CHANGED
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'wcc'
4
+
5
+ require 'wcc/blogs/utils'
6
+
4
7
  require 'wcc/blogs/client'
5
8
  require 'wcc/blogs/errors'
9
+
10
+ require 'wcc/blogs/metadata'
6
11
  require 'wcc/blogs/post'
7
12
 
8
13
  module WCC::Blogs
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.2.0
4
+ version: 0.3.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-05-10 00:00:00.000000000 Z
11
+ date: 2019-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -124,7 +124,9 @@ files:
124
124
  - lib/wcc/blogs.rb
125
125
  - lib/wcc/blogs/client.rb
126
126
  - lib/wcc/blogs/errors.rb
127
+ - lib/wcc/blogs/metadata.rb
127
128
  - lib/wcc/blogs/post.rb
129
+ - lib/wcc/blogs/utils.rb
128
130
  - lib/wcc/blogs/version.rb
129
131
  - wcc-blogs-client.gemspec
130
132
  homepage: https://github.com/watermarkchurch/papyrus/wcc-blogs-client