wcc-blogs-client 0.7.2 → 0.7.4

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
  SHA256:
3
- metadata.gz: 31db17ab6f4a265987b00b832872f9012ab6eb28c4fbbbb64796b0095e3662a3
4
- data.tar.gz: c6722de62467c9c08fc0eca404a17e2bb269203ed49ac7cfd27ad0b2749d9d0f
3
+ metadata.gz: 87ed8ad6c2bba6a5ec40b965ac6e851d83500a937772af594031025641477d10
4
+ data.tar.gz: 0f8da147c4fd4351c8b49330eed0b137135ae06a1563c1c87ce733eacf228ca4
5
5
  SHA512:
6
- metadata.gz: fa5fc97d7196188bb4a31f74c822aa79c1c5f161e4f97bb0a7be36461640d9260746609b55b044a06a14f5a561dc2f7a83370305178fa278cc7a3f4ef4b00a66
7
- data.tar.gz: 59b189fa06be52a11a85d2d4f9a3d0f1d5b2747e396dc19848d88b24fc59ddf5091f643b6157d67f0b55537774899dd69360c716722ae3ac763a3475ae99839e
6
+ metadata.gz: 5955d420482431af87ef23296d2bc5824b129afcae1ee6b7c3311ad28db927d53252b6ed3a366f829e6151f5b099b23ade0b857afa608afd5a315dcdbb646824
7
+ data.tar.gz: 6c2735ee2b49e9ec94c73a6501d116954ddc32ec8584cd92dfa419a2b3db2768085e3cddf2b14fe8097a9575e4da34807eab1605068450bf7811d7e9cbeb311e
data/.rubocop.yml CHANGED
@@ -1,31 +1,13 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  AllCops:
4
- DisplayCopNames: true
5
2
  TargetRubyVersion: 2.3
6
-
7
- Lint/AssignmentInCondition:
8
- Enabled: false
9
-
10
- Metrics/BlockLength:
3
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4
+ # to ignore them, so only the ones explicitly set in this file are enabled.
5
+ DisabledByDefault: true
11
6
  Exclude:
7
+ - '**/templates/**/*'
8
+ - '**/vendor/**/*'
9
+ Include:
10
+ - 'lib/**/*'
11
+ - 'Gemfile'
12
12
  - 'wcc-blogs-client.gemspec'
13
- - 'spec/**/*'
14
-
15
- Style/ClassAndModuleChildren:
16
- Enabled: false
17
-
18
- Style/Documentation:
19
- Enabled: false
20
13
 
21
- Style/DoubleNegation:
22
- Enabled: false
23
-
24
- Style/MultilineBlockChain:
25
- Exclude:
26
- - 'spec/**/*'
27
-
28
- Style/BlockDelimiters:
29
- Exclude:
30
- # we like the `let(:foo) {}` syntax in specs
31
- - 'spec/**/*.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.6
@@ -8,6 +8,15 @@ module WCC::Blogs
8
8
  class Client
9
9
  attr_reader :base_url, :default_property, :base_path
10
10
 
11
+ def options
12
+ {
13
+ default_property: @default_property,
14
+ base_url: @base_url,
15
+ connection: @connection,
16
+ query_defaults: @query_defaults
17
+ }
18
+ end
19
+
11
20
  def initialize(**options)
12
21
  if options[:publishing_target]
13
22
  raise ArgumentError, 'publishing_target has been renamed to default_property'
@@ -18,7 +27,9 @@ module WCC::Blogs
18
27
  @base_path = base_url.path == '' ? '/api/v1' : base_url.path
19
28
  @base_url = base_url.to_s
20
29
  @connection = options[:connection] || default_connection
21
- @query_defaults = options[:query_defaults] || {}
30
+ @query_defaults = options.slice(:preview)
31
+ @query_defaults[:preview] = 'devslikepizza' if options[:preview] == true
32
+ @query_defaults.merge!(options[:query_defaults] || {})
22
33
  end
23
34
 
24
35
  # performs an HTTP GET request to the specified path within the configured
@@ -99,7 +110,6 @@ module WCC::Blogs
99
110
  store: default_cache_store,
100
111
  serializer: Marshal
101
112
  faraday.response :logger, (Rails.logger if defined?(Rails)), headers: false, bodies: false
102
- faraday.adapter :typhoeus
103
113
  end
104
114
  end
105
115
 
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/caching'
4
+
3
5
  module WCC::Blogs
4
6
  class Collection
5
7
  extend WCC::Blogs::Utils
8
+ include WCC::Blogs::Concerns::Caching
6
9
 
7
- def self.find(key = nil)
8
- new(WCC::Blogs.client.collection_show(key).raw, client: WCC::Blogs.client)
10
+ def self.find(key = nil, client: WCC::Blogs.client)
11
+ new(client.collection_show(key).raw, client: client)
9
12
  end
10
13
 
11
14
  attr_reader :raw
@@ -45,6 +48,10 @@ module WCC::Blogs
45
48
  OpenStruct.new(raw['_links'] || {})
46
49
  end
47
50
 
48
- alias cache_key digest
51
+ private
52
+
53
+ def cache_key_without_version
54
+ "WCC::Blogs::Collection/#{key}"
55
+ end
49
56
  end
50
57
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WCC::Blogs::Concerns
4
+ module Caching
5
+ def cache_key
6
+ unless defined?(ActiveRecord::Base) &&
7
+ ActiveRecord::Base.respond_to?(:cache_versioning) &&
8
+ ActiveRecord::Base.cache_versioning == true
9
+ return cache_key_with_version
10
+ end
11
+
12
+ cache_key_without_version
13
+ end
14
+
15
+ # https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching
16
+ def cache_key_with_version
17
+ [cache_key_without_version, cache_version].join('/')
18
+ end
19
+
20
+ def cache_version
21
+ updated_at&.to_i
22
+ end
23
+ end
24
+ end
@@ -12,11 +12,12 @@ module WCC::Blogs
12
12
  end
13
13
 
14
14
  def full_post
15
- Post.new(@client.get(_links.self).raw)
15
+ Post.new(@client.get(_links.self).raw, client: @client)
16
16
  end
17
17
 
18
18
  define_camelcase_alias(
19
19
  'title',
20
+ 'subtitle',
20
21
  'slug'
21
22
  ) do |camelcase|
22
23
  raw[camelcase]
@@ -1,16 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/caching'
4
+
3
5
  module WCC::Blogs
4
6
  class Post
5
7
  extend WCC::Blogs::Utils
8
+ include WCC::Blogs::Concerns::Caching
6
9
  require 'time'
7
10
 
8
- def self.find(slug)
9
- new(WCC::Blogs.client.blog_show(slug).raw, client: WCC::Blogs.client)
11
+ def self.find(slug, client: WCC::Blogs.client)
12
+ new(client.blog_show(slug).raw, client: client)
10
13
  end
11
14
 
12
- def self.find_all
13
- PostSummary.find_all.map(&:full_post)
15
+ def self.find_all(client: WCC::Blogs.client)
16
+ PostSummary.find_all(client: client).map(&:full_post)
14
17
  end
15
18
 
16
19
  attr_reader :raw
@@ -26,6 +29,7 @@ module WCC::Blogs
26
29
 
27
30
  def html
28
31
  @html ||= @client.get(_links.fragment)
32
+ .assert_ok!
29
33
  .body
30
34
  .force_encoding('UTF-8')
31
35
  end
@@ -38,11 +42,6 @@ module WCC::Blogs
38
42
  true
39
43
  end
40
44
 
41
- def time_to_read
42
- # TODO
43
- nil
44
- end
45
-
46
45
  def to_param
47
46
  slug.sub(%r{^/}, '')
48
47
  end
@@ -57,11 +56,14 @@ module WCC::Blogs
57
56
  'path',
58
57
  'digest',
59
58
  'fragment_path',
60
- 'read_time'
59
+ 'read_time',
60
+ 'word_count'
61
61
  ) do |camelcase|
62
62
  raw[camelcase]
63
63
  end
64
64
 
65
+ alias time_to_read read_time
66
+
65
67
  define_camelcase_alias(
66
68
  'date',
67
69
  'updated_at'
@@ -103,6 +105,10 @@ module WCC::Blogs
103
105
  related.map { |val| WCC::Blogs::LinkedBlogPostSummary.new(val, client: @client) }
104
106
  end
105
107
 
106
- alias cache_key digest
108
+ private
109
+
110
+ def cache_key_without_version
111
+ "WCC::Blogs::Post/#{slug}"
112
+ end
107
113
  end
108
114
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/caching'
4
+
3
5
  module WCC::Blogs
4
6
  class PostSummary
5
7
  extend WCC::Blogs::Utils
8
+ include WCC::Blogs::Concerns::Caching
6
9
 
7
- def self.find_all
8
- WCC::Blogs.client.blog_list.items.map do |summary|
9
- new(summary, client: WCC::Blogs.client)
10
+ def self.find_all(client: WCC::Blogs.client)
11
+ client.blog_list.items.map do |summary|
12
+ new(summary, client: client)
10
13
  end
11
14
  end
12
15
 
@@ -18,7 +21,7 @@ module WCC::Blogs
18
21
  end
19
22
 
20
23
  def full_post
21
- Post.new(@client.get(_links.self).raw)
24
+ Post.new(@client.get(_links.self).raw, client: @client)
22
25
  end
23
26
 
24
27
  define_camelcase_alias(
@@ -27,7 +30,8 @@ module WCC::Blogs
27
30
  'subtitle',
28
31
  'slug',
29
32
  'digest',
30
- 'read_time'
33
+ 'read_time',
34
+ 'word_count'
31
35
  ) do |camelcase|
32
36
  raw[camelcase]
33
37
  end
@@ -64,6 +68,10 @@ module WCC::Blogs
64
68
  values.map { |val| OpenStruct.new(val) if val }
65
69
  end
66
70
 
67
- alias cache_key digest
71
+ private
72
+
73
+ def cache_key_without_version
74
+ "WCC::Blogs::PostSummary/#{slug}"
75
+ end
68
76
  end
69
77
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/caching'
4
+
3
5
  module WCC::Blogs
4
6
  class Property
5
7
  extend WCC::Blogs::Utils
8
+ include WCC::Blogs::Concerns::Caching
6
9
  require 'time'
7
10
 
8
- def self.find(property = nil)
9
- new(WCC::Blogs.client.property_show(property).raw, client: WCC::Blogs.client)
11
+ def self.find(property = nil, client: WCC::Blogs.client)
12
+ new(client.property_show(property).raw, client: client)
10
13
  end
11
14
 
12
15
  attr_reader :raw
@@ -41,6 +44,10 @@ module WCC::Blogs
41
44
  targets.map { |val| OpenStruct.new(val) if val }
42
45
  end
43
46
 
44
- alias cache_key digest
47
+ private
48
+
49
+ def cache_key_without_version
50
+ "WCC::Blogs::Property/#{key}"
51
+ end
45
52
  end
46
53
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module Blogs
5
- VERSION = '0.7.2'
5
+ VERSION = '0.7.4'
6
6
  end
7
7
  end
data/lib/wcc/blogs.rb CHANGED
@@ -17,10 +17,14 @@ require 'wcc/blogs/collection_summary'
17
17
 
18
18
  module WCC::Blogs
19
19
  class << self
20
- attr_writer :client
20
+ attr_writer :client, :preview_client
21
21
 
22
22
  def client
23
23
  @client || raise(WCC::Blogs::NotConfiguredException, 'Not configured')
24
24
  end
25
+
26
+ def preview_client
27
+ @preview_client ||= WCC::Blogs::Client.new(**client.options.merge(preview: true))
28
+ end
25
29
  end
26
30
  end
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_runtime_dependency 'faraday', '~> 0.15.4'
28
- spec.add_runtime_dependency 'faraday-http-cache', '~> 1.3'
27
+ spec.add_runtime_dependency 'faraday', '>= 0.15.4'
28
+ spec.add_runtime_dependency 'faraday-http-cache', '>= 1.3'
29
29
  spec.add_runtime_dependency 'wcc-base'
30
30
 
31
31
  spec.add_development_dependency 'guard', '~> 2.15'
@@ -34,7 +34,6 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'rake', '~> 12.3'
35
35
  spec.add_development_dependency 'rspec', '~> 3.0'
36
36
  spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3.0'
37
- spec.add_development_dependency 'rubocop', '~> 0.60.0'
38
- spec.add_development_dependency 'typhoeus'
37
+ spec.add_development_dependency 'rubocop', '~> 0.71.0'
39
38
  spec.add_development_dependency 'webmock', '~> 3.0'
40
39
  end
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-blogs-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.15.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.15.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday-http-cache
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
@@ -142,28 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.60.0
145
+ version: 0.71.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.60.0
153
- - !ruby/object:Gem::Dependency
154
- name: typhoeus
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
152
+ version: 0.71.0
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: webmock
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +173,7 @@ extra_rdoc_files: []
187
173
  files:
188
174
  - ".gitignore"
189
175
  - ".rubocop.yml"
190
- - ".rubocop_todo.yml"
176
+ - ".ruby-version"
191
177
  - Gemfile
192
178
  - Guardfile
193
179
  - README.md
@@ -197,6 +183,7 @@ files:
197
183
  - lib/wcc/blogs/client/response.rb
198
184
  - lib/wcc/blogs/collection.rb
199
185
  - lib/wcc/blogs/collection_summary.rb
186
+ - lib/wcc/blogs/concerns/caching.rb
200
187
  - lib/wcc/blogs/errors.rb
201
188
  - lib/wcc/blogs/linked_blog_post_summary.rb
202
189
  - lib/wcc/blogs/metadata.rb
@@ -210,7 +197,7 @@ homepage: https://github.com/watermarkchurch/papyrus/wcc-blogs-client
210
197
  licenses:
211
198
  - MIT
212
199
  metadata: {}
213
- post_install_message:
200
+ post_install_message:
214
201
  rdoc_options: []
215
202
  require_paths:
216
203
  - lib
@@ -225,9 +212,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
212
  - !ruby/object:Gem::Version
226
213
  version: '0'
227
214
  requirements: []
228
- rubyforge_project:
229
- rubygems_version: 2.7.6
230
- signing_key:
215
+ rubygems_version: 3.1.6
216
+ signing_key:
231
217
  specification_version: 4
232
218
  summary: ''
233
219
  test_files: []
data/.rubocop_todo.yml DELETED
@@ -1,44 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2019-05-13 14:26:19 -0500 using RuboCop version 0.60.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
13
- Exclude:
14
- - 'wcc-blogs-client.gemspec'
15
-
16
- # Offense count: 3
17
- # Cop supports --auto-correct.
18
- # Configuration parameters: EnforcedStyle.
19
- # SupportedStyles: line_count_dependent, lambda, literal
20
- Style/Lambda:
21
- Exclude:
22
- - 'lib/wcc/blogs/client.rb'
23
-
24
- # Offense count: 1
25
- # Cop supports --auto-correct.
26
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
27
- # SupportedStyles: single_quotes, double_quotes
28
- Style/StringLiterals:
29
- Exclude:
30
- - 'Rakefile'
31
-
32
- # Offense count: 1
33
- # Cop supports --auto-correct.
34
- # Configuration parameters: EnforcedStyleForMultiline.
35
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
36
- Style/TrailingCommaInHashLiteral:
37
- Exclude:
38
- - 'lib/wcc/blogs/client.rb'
39
-
40
- # Offense count: 8
41
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
42
- # URISchemes: http, https
43
- Metrics/LineLength:
44
- Max: 106