wcc-blogs-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +2 -8
- data/lib/wcc/blogs/metadata.rb +35 -0
- data/lib/wcc/blogs/post.rb +32 -63
- data/lib/wcc/blogs/utils.rb +21 -0
- data/lib/wcc/blogs/version.rb +1 -1
- data/lib/wcc/blogs.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91c71241330bf18f4d6561c4b34a44ef9a4d9a36
|
4
|
+
data.tar.gz: b822af919ef3a0521440c9f82050ca94e1b59e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f0fec0ce8116c8fa79af618abe0b4a580796b1368b0b1ad963b24b3e7648f31c4dda3ab569a5dfa45fe440750cb959721e1cc29f7f1e99ab8d51ff589eb8ea
|
7
|
+
data.tar.gz: 5403a6f4122e7a23002afb7c2dfdfe07840e008316adcc7f1bf3812d92f303a115dec900a1a62fc4c2860c07b26f763121842370651ea47f91cafa6001714538
|
data/.rubocop.yml
CHANGED
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-
|
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:
|
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
|
data/lib/wcc/blogs/post.rb
CHANGED
@@ -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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
].each do |method|
|
81
|
-
attribute = camelcase(method)
|
66
|
+
define_camelcase_alias(
|
67
|
+
'date'
|
68
|
+
) do |camelcase|
|
69
|
+
value = raw[camelcase]
|
82
70
|
|
83
|
-
|
84
|
-
value = raw[attribute]
|
85
|
-
return unless value && value.length
|
71
|
+
return unless value && value.length
|
86
72
|
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
alias_method attribute, method if attribute != method
|
73
|
+
Time.parse(value)
|
91
74
|
end
|
92
75
|
|
93
|
-
|
94
|
-
author
|
95
|
-
hero_image
|
96
|
-
thumbnail_image
|
97
|
-
|
98
|
-
|
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
|
-
|
108
|
-
|
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
|
-
|
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
|
data/lib/wcc/blogs/version.rb
CHANGED
data/lib/wcc/blogs.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.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-
|
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
|