wcc-blogs-client 0.1.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 +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +21 -0
- data/.rubocop_todo.yml +46 -0
- data/Gemfile +6 -0
- data/README.md +0 -0
- data/lib/wcc/blogs/client.rb +42 -0
- data/lib/wcc/blogs/errors.rb +12 -0
- data/lib/wcc/blogs/post.rb +109 -0
- data/lib/wcc/blogs/version.rb +7 -0
- data/lib/wcc/blogs.rb +52 -0
- data/wcc-blogs-client.gemspec +35 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1738d588e81003474759f99c0a06d8350e7bb9c
|
4
|
+
data.tar.gz: db3d3d0507abb807cd3c1d18fb975ce6d7114659
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 274c5a18525eeb9693f2004882e9141cf9d8d2659b2b4a9cb874800b6674b0420e0963d35c6a5e715b1f69f2b18dec4b1e837608a6968b207aae05c886461227
|
7
|
+
data.tar.gz: c1c70c4f76d8631b5d5a90b04c4e7302ccbed22e001cb2b252d18f1858333f376e1ee1c3bbcc38f1c79b0b8e57a083889f754c18a58d8e8dcae88957e0579867
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Metrics/BlockLength:
|
4
|
+
Exclude:
|
5
|
+
- 'wcc-blogs-client.gemspec'
|
6
|
+
- 'spec/**/*'
|
7
|
+
|
8
|
+
Style/ClassAndModuleChildren:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/Documentation:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/MultilineBlockChain:
|
15
|
+
Exclude:
|
16
|
+
- 'spec/**/*'
|
17
|
+
|
18
|
+
Style/BlockDelimiters:
|
19
|
+
Exclude:
|
20
|
+
# we like the `let(:foo) {}` syntax in specs
|
21
|
+
- 'spec/**/*.rb'
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2019-05-09 17:07:57 -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: 1
|
17
|
+
# Configuration parameters: AllowSafeAssignment.
|
18
|
+
Lint/AssignmentInCondition:
|
19
|
+
Exclude:
|
20
|
+
- 'lib/wcc/blogs/client.rb'
|
21
|
+
|
22
|
+
# Offense count: 1
|
23
|
+
Metrics/AbcSize:
|
24
|
+
Max: 17
|
25
|
+
|
26
|
+
# Offense count: 3
|
27
|
+
# Cop supports --auto-correct.
|
28
|
+
# Configuration parameters: EnforcedStyle.
|
29
|
+
# SupportedStyles: line_count_dependent, lambda, literal
|
30
|
+
Style/Lambda:
|
31
|
+
Exclude:
|
32
|
+
- 'lib/wcc/blogs/client.rb'
|
33
|
+
|
34
|
+
# Offense count: 1
|
35
|
+
# Cop supports --auto-correct.
|
36
|
+
# Configuration parameters: EnforcedStyleForMultiline.
|
37
|
+
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
|
38
|
+
Style/TrailingCommaInHashLiteral:
|
39
|
+
Exclude:
|
40
|
+
- 'lib/wcc/blogs/client.rb'
|
41
|
+
|
42
|
+
# Offense count: 7
|
43
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
44
|
+
# URISchemes: http, https
|
45
|
+
Metrics/LineLength:
|
46
|
+
Max: 106
|
data/Gemfile
ADDED
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::Blogs
|
4
|
+
class Client
|
5
|
+
def initialize(config:)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
REDIRECT_HANDLER =
|
10
|
+
->(resp) {
|
11
|
+
location = resp.headers['Location']
|
12
|
+
digest = File.basename(location).gsub(/\.(fragment|json)$/, '')
|
13
|
+
|
14
|
+
@config.cache.fetch(['BlogPost', digest, File.extname(location)]) do
|
15
|
+
get(location, resp.effective_url)
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
19
|
+
RESPONSE_HANDLERS = {
|
20
|
+
404 => ->(resp) {
|
21
|
+
raise WCC::Blogs::NotFoundException, "Blog post '#{resp.effective_url}' does not exist"
|
22
|
+
},
|
23
|
+
200 => ->(resp) {
|
24
|
+
resp.body
|
25
|
+
},
|
26
|
+
301 => REDIRECT_HANDLER,
|
27
|
+
302 => REDIRECT_HANDLER,
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
def get(path, base = @config.base_url)
|
31
|
+
url = URI.join(base, path)
|
32
|
+
|
33
|
+
resp = Typhoeus.get(url, followlocation: false)
|
34
|
+
|
35
|
+
if handler = RESPONSE_HANDLERS[resp.code]
|
36
|
+
return instance_exec(resp, &handler)
|
37
|
+
end
|
38
|
+
|
39
|
+
raise WCC::Blogs::ApiException, "#{resp.return_code}: #{resp.effective_url}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::Blogs
|
4
|
+
class Post
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
def self.find(slug)
|
8
|
+
path = '/blog/' + slug.sub(%r{^/}, '') + '.json'
|
9
|
+
new(JSON.parse(WCC::Blogs.client.get(path))).tap do |blog|
|
10
|
+
raise WCC::Blogs::NotFoundException, "Blog post '#{slug}' is not published" unless blog.published?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :raw
|
15
|
+
|
16
|
+
def initialize(raw)
|
17
|
+
@raw = raw
|
18
|
+
end
|
19
|
+
|
20
|
+
def author_full_name
|
21
|
+
return unless author
|
22
|
+
|
23
|
+
[author.firstName, author.lastName].compact.join(' ')
|
24
|
+
end
|
25
|
+
|
26
|
+
def date
|
27
|
+
publish_at || created_at
|
28
|
+
end
|
29
|
+
|
30
|
+
def html
|
31
|
+
@html ||=
|
32
|
+
WCC::Blogs.config.cache.fetch(['BlogPost', fragment_path]) do
|
33
|
+
WCC::Blogs.client.get(fragment_path, host || WCC::Blogs.config.base_url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def published?
|
38
|
+
return false if publishing_targets.empty?
|
39
|
+
|
40
|
+
publishing_targets.any? { |t| t['key'] == WCC::Blogs.config.publishing_target } &&
|
41
|
+
(publish_at.nil? || publish_at.empty? || (Time.parse(publish_at) <= Time.now))
|
42
|
+
end
|
43
|
+
|
44
|
+
def time_to_read
|
45
|
+
# TODO
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_param
|
50
|
+
slug.sub(%r{^/}, '')
|
51
|
+
end
|
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
|
+
updated_at
|
66
|
+
created_at
|
67
|
+
publish_at
|
68
|
+
fragment_path
|
69
|
+
].each do |method|
|
70
|
+
attribute = camelcase(method)
|
71
|
+
|
72
|
+
define_method method do
|
73
|
+
raw[attribute]
|
74
|
+
end
|
75
|
+
|
76
|
+
alias_method attribute, method if attribute != method
|
77
|
+
end
|
78
|
+
|
79
|
+
%w[
|
80
|
+
author
|
81
|
+
hero_image
|
82
|
+
thumbnail_image
|
83
|
+
].each do |method|
|
84
|
+
attribute = camelcase(method)
|
85
|
+
|
86
|
+
define_method method do
|
87
|
+
OpenStruct.new(raw[attribute]) if raw[attribute]
|
88
|
+
end
|
89
|
+
|
90
|
+
alias_method attribute, method if attribute != method
|
91
|
+
end
|
92
|
+
|
93
|
+
%w[
|
94
|
+
publishing_targets
|
95
|
+
].each do |method|
|
96
|
+
attribute = camelcase(method)
|
97
|
+
|
98
|
+
define_method method do
|
99
|
+
return [] unless raw[attribute]
|
100
|
+
|
101
|
+
raw[attribute].map { |val| OpenStruct.new(val) if val }
|
102
|
+
end
|
103
|
+
|
104
|
+
alias_method attribute, method if attribute != method
|
105
|
+
end
|
106
|
+
|
107
|
+
alias cache_key digest
|
108
|
+
end
|
109
|
+
end
|
data/lib/wcc/blogs.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'wcc/blogs/client'
|
4
|
+
require 'wcc/blogs/errors'
|
5
|
+
require 'wcc/blogs/post'
|
6
|
+
|
7
|
+
module WCC::Blogs
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
yield config
|
11
|
+
|
12
|
+
@client = WCC::Blogs::Client.new(config: config)
|
13
|
+
|
14
|
+
config
|
15
|
+
end
|
16
|
+
|
17
|
+
def client
|
18
|
+
@client || raise(WCC::Blogs::NotConfiguredException, 'Not configured')
|
19
|
+
end
|
20
|
+
|
21
|
+
def config
|
22
|
+
Config.instance
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Config
|
27
|
+
include Singleton
|
28
|
+
|
29
|
+
attr_accessor :publishing_target
|
30
|
+
attr_writer :base_url, :cache, :query_url
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
@base_url || 'https://wcc-papyrus.herokuapp.com'
|
34
|
+
end
|
35
|
+
|
36
|
+
def cache
|
37
|
+
@cache || NilCache.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def query_url
|
41
|
+
@query_url || 'https://papyrus.wcc/graphql'
|
42
|
+
end
|
43
|
+
|
44
|
+
class NilCache
|
45
|
+
def clear; end
|
46
|
+
|
47
|
+
def fetch(*_args)
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'wcc/blogs/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'wcc-blogs-client'
|
9
|
+
spec.version = WCC::Blogs::VERSION
|
10
|
+
spec.authors = ['Watermark Dev']
|
11
|
+
spec.email = ['dev@watermark.org']
|
12
|
+
|
13
|
+
spec.summary = File.readlines(File.expand_path('README.md', __dir__)).join
|
14
|
+
spec.description = 'Simple Client for accessing WCC Blog library content'
|
15
|
+
spec.homepage = 'https://github.com/watermarkchurch/papyrus/wcc-blogs-client'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.required_ruby_version = '>= 2.3'
|
19
|
+
|
20
|
+
spec.files =
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'typhoeus', '~> 1.3'
|
28
|
+
spec.add_runtime_dependency 'wcc-base'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.60.0'
|
34
|
+
spec.add_development_dependency 'webmock', '~> 3.0'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wcc-blogs-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Watermark Dev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: wcc-base
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_junit_formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.3.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.60.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.60.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: Simple Client for accessing WCC Blog library content
|
112
|
+
email:
|
113
|
+
- dev@watermark.org
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".rubocop_todo.yml"
|
121
|
+
- Gemfile
|
122
|
+
- README.md
|
123
|
+
- lib/wcc/blogs.rb
|
124
|
+
- lib/wcc/blogs/client.rb
|
125
|
+
- lib/wcc/blogs/errors.rb
|
126
|
+
- lib/wcc/blogs/post.rb
|
127
|
+
- lib/wcc/blogs/version.rb
|
128
|
+
- wcc-blogs-client.gemspec
|
129
|
+
homepage: https://github.com/watermarkchurch/papyrus/wcc-blogs-client
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '2.3'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.6.11
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: ''
|
153
|
+
test_files: []
|