wcc-jtj-client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +28 -0
- data/Gemfile +21 -0
- data/README.md +1 -0
- data/Rakefile +10 -0
- data/lib/wcc/jtj/client/response.rb +105 -0
- data/lib/wcc/jtj/client/responses/base.rb +7 -0
- data/lib/wcc/jtj/client/responses/curriculum_show_response.rb +30 -0
- data/lib/wcc/jtj/client/responses/curriculums_list_response.rb +27 -0
- data/lib/wcc/jtj/client/responses/entries_list_response.rb +27 -0
- data/lib/wcc/jtj/client/responses/entry_show_response.rb +20 -0
- data/lib/wcc/jtj/client/responses/memory_verse_show_response.rb +20 -0
- data/lib/wcc/jtj/client/responses/memory_verses_list_response.rb +27 -0
- data/lib/wcc/jtj/client/responses/root_response.rb +37 -0
- data/lib/wcc/jtj/client/schemas/base.rb +19 -0
- data/lib/wcc/jtj/client/schemas/curriculum_summary.rb +21 -0
- data/lib/wcc/jtj/client/schemas/entry.rb +47 -0
- data/lib/wcc/jtj/client/schemas/entry_summary.rb +21 -0
- data/lib/wcc/jtj/client/schemas/memory_verse.rb +23 -0
- data/lib/wcc/jtj/client/schemas/memory_verse_summary.rb +21 -0
- data/lib/wcc/jtj/client/schemas/scripture.rb +19 -0
- data/lib/wcc/jtj/client/schemas/writer.rb +19 -0
- data/lib/wcc/jtj/client/utils.rb +21 -0
- data/lib/wcc/jtj/client/version.rb +9 -0
- data/lib/wcc/jtj/client.rb +134 -0
- data/lib/wcc-jtj-client.rb +3 -0
- data/wcc-jtj-client.gemspec +27 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd533e65649b2b8f21fd9637c8d41a928a248b07fd8aa9bc0639929ccfe25791
|
4
|
+
data.tar.gz: 1ec8cb8c7344360cbdd4222e42d24b04db6e98a5dd2a812120ff98e011056c04
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b371e59536f7fe43c8d64a3fb618afcde6f96236b06e752186dc23d45fb9ca516e003bf241fdce12fa3b49b08b3ef597282669c542c11ef3abdd96076d5b85fb
|
7
|
+
data.tar.gz: 2b38e61322f9389d94303e5c35929f7d0fd23a98fec705fa7d925b909ffe7fa6294c8b7b51c600e211e1283e633bbfc19ffaee8eaebba9bbdf7578bb6050ed8b
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
Exclude:
|
4
|
+
- '**/templates/**/*'
|
5
|
+
- '**/vendor/**/*'
|
6
|
+
Include:
|
7
|
+
- 'lib/**/*'
|
8
|
+
- 'Gemfile'
|
9
|
+
- 'wcc-jtj-client.gemspec'
|
10
|
+
|
11
|
+
Metrics/LineLength:
|
12
|
+
Max: 120
|
13
|
+
|
14
|
+
Naming/FileName:
|
15
|
+
Exclude:
|
16
|
+
- 'lib/wcc-jtj-client.rb' # Allow "require 'wcc-jtj-client'"
|
17
|
+
|
18
|
+
Style/ClassAndModuleChildren:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/IfUnlessModifier:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/MultilineIfModifier:
|
28
|
+
Enabled: false
|
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in wcc-events-client.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem 'capybara', '>= 2.15'
|
10
|
+
gem 'guard', '~> 2.15'
|
11
|
+
gem 'guard-rspec', '~> 4.7'
|
12
|
+
gem 'guard-rubocop', '~> 1.3'
|
13
|
+
gem 'rake', '~> 12.3'
|
14
|
+
gem 'rspec', '~> 3.0'
|
15
|
+
gem 'rspec_junit_formatter', '~> 0.4.1'
|
16
|
+
gem 'rubocop', '~> 0.59.2', require: false
|
17
|
+
gem 'rubocop-performance', require: false
|
18
|
+
gem 'simplecov', '~> 0.21.2', require: false
|
19
|
+
gem 'simplecov-cobertura', '~> 1.4'
|
20
|
+
gem 'webmock', '~> 3.1'
|
21
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Internal Watermark.org gem, not licensed for external use.
|
data/Rakefile
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module WCC::JTJ
|
6
|
+
class Client
|
7
|
+
Response = Struct.new(:client, :request, :raw_response) do # rubocop:disable Metrics/BlockLength
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :raw_response, :status, :headers
|
11
|
+
alias_method :code, :status
|
12
|
+
|
13
|
+
def raw
|
14
|
+
@raw ||= raw_response.body.to_s
|
15
|
+
end
|
16
|
+
alias_method :to_json, :raw
|
17
|
+
|
18
|
+
def body
|
19
|
+
@body ||= JSON.parse(raw)
|
20
|
+
end
|
21
|
+
def_delegators :body, :[], :dig, :to_h
|
22
|
+
|
23
|
+
def next_page_url
|
24
|
+
body.dig('links', 'next_page')
|
25
|
+
end
|
26
|
+
|
27
|
+
def next_page?
|
28
|
+
!next_page_url.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
def next_page
|
32
|
+
return unless next_page_url
|
33
|
+
return @next_page if @next_page
|
34
|
+
|
35
|
+
np = client.get(next_page_url, request[:query])
|
36
|
+
@next_page = np.assert_ok!
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_ok!
|
40
|
+
return self if status >= 200 && status < 300
|
41
|
+
|
42
|
+
raise ApiError[status], self
|
43
|
+
end
|
44
|
+
|
45
|
+
def each_page(&block)
|
46
|
+
ret = PaginatingEnumerable.new(self)
|
47
|
+
|
48
|
+
if block_given?
|
49
|
+
ret.map(&block)
|
50
|
+
else
|
51
|
+
ret.lazy
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def count
|
56
|
+
total
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class PaginatingEnumerable
|
61
|
+
include Enumerable
|
62
|
+
|
63
|
+
def initialize(initial_page)
|
64
|
+
raise ArgumentError, 'Must provide initial page' unless initial_page
|
65
|
+
|
66
|
+
@initial_page = initial_page
|
67
|
+
end
|
68
|
+
|
69
|
+
def each
|
70
|
+
page = @initial_page
|
71
|
+
puts 'yield page'
|
72
|
+
yield page
|
73
|
+
|
74
|
+
while page.next_page?
|
75
|
+
page = page.next_page
|
76
|
+
yield page
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class ApiError < StandardError
|
82
|
+
attr_reader :response
|
83
|
+
|
84
|
+
def self.[](code)
|
85
|
+
case code
|
86
|
+
when 404
|
87
|
+
NotFoundError
|
88
|
+
else
|
89
|
+
ApiError
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def initialize(response, message = nil)
|
94
|
+
@response = response
|
95
|
+
super(message || "An unexpected error occurred: #{response.status}")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class NotFoundError < ApiError
|
100
|
+
def initialize(response)
|
101
|
+
super(response, 'Resource does not exist')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class CurriculumShowResponse < Base
|
5
|
+
def curriculum
|
6
|
+
@curriculum ||=
|
7
|
+
if raw['curriculum']
|
8
|
+
WCC::JTJ::Client::Schemas::CurriculumSummary.new(
|
9
|
+
raw['curriculum'], client: @client
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def current_week
|
15
|
+
@current_week ||=
|
16
|
+
raw['current_week']&.map do |entry|
|
17
|
+
WCC::JTJ::Client::Schemas::Entry.new(
|
18
|
+
entry, client: @client
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
alias currentWeek current_week
|
23
|
+
|
24
|
+
define_camelcase_alias(
|
25
|
+
'links'
|
26
|
+
) do |camelcase|
|
27
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class CurriculumsListResponse < Base
|
5
|
+
def total
|
6
|
+
raw['total']
|
7
|
+
end
|
8
|
+
alias count total
|
9
|
+
|
10
|
+
def curriculums
|
11
|
+
raw.each_page
|
12
|
+
.flat_map { |page| page['curriculums'] }
|
13
|
+
.map do |raw_curriculum|
|
14
|
+
WCC::JTJ::Client::Schemas::CurriculumSummary.new(
|
15
|
+
raw_curriculum, client: @client
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
define_camelcase_alias(
|
21
|
+
'params',
|
22
|
+
'links'
|
23
|
+
) do |camelcase|
|
24
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class EntriesListResponse < Base
|
5
|
+
def total
|
6
|
+
raw['total']
|
7
|
+
end
|
8
|
+
alias count total
|
9
|
+
|
10
|
+
def entries
|
11
|
+
raw.each_page
|
12
|
+
.flat_map { |page| page['entries'] }
|
13
|
+
.map do |raw_entry|
|
14
|
+
WCC::JTJ::Client::Schemas::EntrySummary.new(
|
15
|
+
raw_entry, client: @client
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
define_camelcase_alias(
|
21
|
+
'params',
|
22
|
+
'links'
|
23
|
+
) do |camelcase|
|
24
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class EntryShowResponse < Base
|
5
|
+
def entry
|
6
|
+
@entry ||=
|
7
|
+
if raw['entry']
|
8
|
+
WCC::JTJ::Client::Schemas::Entry.new(
|
9
|
+
raw['entry'], client: @client
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
define_camelcase_alias(
|
15
|
+
'links'
|
16
|
+
) do |camelcase|
|
17
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class MemoryVerseShowResponse < Base
|
5
|
+
def memory_verse
|
6
|
+
@memory_verse ||=
|
7
|
+
if raw['memory_verse']
|
8
|
+
WCC::JTJ::Client::Schemas::MemoryVerse.new(
|
9
|
+
raw['memory_verse'], client: @client
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
define_camelcase_alias(
|
15
|
+
'links'
|
16
|
+
) do |camelcase|
|
17
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class MemoryVersesListResponse < Base
|
5
|
+
def total
|
6
|
+
raw['total']
|
7
|
+
end
|
8
|
+
alias count total
|
9
|
+
|
10
|
+
def memory_verses
|
11
|
+
raw.each_page
|
12
|
+
.flat_map { |page| page['memory_verses'] }
|
13
|
+
.map do |raw_verse|
|
14
|
+
WCC::JTJ::Client::Schemas::MemoryVerseSummary.new(
|
15
|
+
raw_verse, client: @client
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
define_camelcase_alias(
|
21
|
+
'params',
|
22
|
+
'links'
|
23
|
+
) do |camelcase|
|
24
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Responses
|
4
|
+
class RootResponse < Base
|
5
|
+
def curriculum
|
6
|
+
@curriculum ||=
|
7
|
+
if raw['curriculum']
|
8
|
+
WCC::JTJ::Client::Schemas::CurriculumSummary.new(raw['curriculum'], client: @client)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def latest_entry
|
13
|
+
@latest_entry ||=
|
14
|
+
if raw['latest_entry']
|
15
|
+
WCC::JTJ::Client::Schemas::Entry.new(raw['latest_entry'], client: @client)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias latestEntry latest_entry
|
19
|
+
|
20
|
+
def current_week
|
21
|
+
@current_week ||=
|
22
|
+
raw['current_week']&.map do |summary|
|
23
|
+
WCC::JTJ::Client::Schemas::EntrySummary.new(
|
24
|
+
summary, client: @client
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
alias currentWeek current_week
|
29
|
+
|
30
|
+
define_camelcase_alias(
|
31
|
+
'settings',
|
32
|
+
'links'
|
33
|
+
) do |camelcase|
|
34
|
+
OpenStruct.new(raw[camelcase]) if raw[camelcase]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
# The abstract base class of all schemas
|
7
|
+
class Base
|
8
|
+
extend Forwardable
|
9
|
+
extend WCC::JTJ::Client::Utils
|
10
|
+
|
11
|
+
attr_reader :raw
|
12
|
+
def_delegators :raw, :[], :dig, :to_h, :to_json
|
13
|
+
|
14
|
+
def initialize(raw, client: WCC::JTJ::Client.default)
|
15
|
+
@raw = raw
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class CurriculumSummary < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'title',
|
10
|
+
'start_date',
|
11
|
+
'end_date',
|
12
|
+
'days_of_week'
|
13
|
+
) do |camelcase|
|
14
|
+
raw[camelcase]
|
15
|
+
end
|
16
|
+
|
17
|
+
def links
|
18
|
+
OpenStruct.new(raw['links']) if raw['links']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class Entry < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'date',
|
10
|
+
'title',
|
11
|
+
'central_truth',
|
12
|
+
'reflection',
|
13
|
+
'discussion_questions',
|
14
|
+
'tags'
|
15
|
+
) do |camelcase|
|
16
|
+
raw[camelcase]
|
17
|
+
end
|
18
|
+
|
19
|
+
def scriptures
|
20
|
+
@scriptures ||=
|
21
|
+
raw['scriptures']&.map do |scripture|
|
22
|
+
WCC::JTJ::Client::Schemas::Scripture.new(
|
23
|
+
scripture, client: @client
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def key_verse
|
29
|
+
@key_verse ||=
|
30
|
+
if raw['key_verse']
|
31
|
+
WCC::JTJ::Client::Schemas::Scripture.new(raw['key_verse'], client: @client)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
alias keyVerse key_verse
|
35
|
+
|
36
|
+
def writer
|
37
|
+
@writer ||=
|
38
|
+
if raw['writer']
|
39
|
+
WCC::JTJ::Client::Schemas::Writer.new(raw['writer'], client: @client)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def links
|
44
|
+
OpenStruct.new(raw['links']) if raw['links']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class EntrySummary < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'date',
|
10
|
+
'scripture',
|
11
|
+
'title',
|
12
|
+
'tags'
|
13
|
+
) do |camelcase|
|
14
|
+
raw[camelcase]
|
15
|
+
end
|
16
|
+
|
17
|
+
def links
|
18
|
+
OpenStruct.new(raw['links']) if raw['links']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class MemoryVerse < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'curriculum_id',
|
10
|
+
'reference',
|
11
|
+
'version',
|
12
|
+
'html',
|
13
|
+
'start_date',
|
14
|
+
'end_date'
|
15
|
+
) do |camelcase|
|
16
|
+
raw[camelcase]
|
17
|
+
end
|
18
|
+
|
19
|
+
def links
|
20
|
+
OpenStruct.new(raw['links']) if raw['links']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class MemoryVerseSummary < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'curriculum_id',
|
10
|
+
'reference',
|
11
|
+
'start_date',
|
12
|
+
'end_date'
|
13
|
+
) do |camelcase|
|
14
|
+
raw[camelcase]
|
15
|
+
end
|
16
|
+
|
17
|
+
def links
|
18
|
+
OpenStruct.new(raw['links']) if raw['links']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class Scripture < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'reference',
|
9
|
+
'version',
|
10
|
+
'html'
|
11
|
+
) do |camelcase|
|
12
|
+
raw[camelcase]
|
13
|
+
end
|
14
|
+
|
15
|
+
def links
|
16
|
+
OpenStruct.new(raw['links']) if raw['links']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../utils'
|
4
|
+
|
5
|
+
module WCC::JTJ::Client::Schemas
|
6
|
+
class Writer < Base
|
7
|
+
define_camelcase_alias(
|
8
|
+
'id',
|
9
|
+
'name',
|
10
|
+
'bio'
|
11
|
+
) do |camelcase|
|
12
|
+
raw[camelcase]
|
13
|
+
end
|
14
|
+
|
15
|
+
def links
|
16
|
+
OpenStruct.new(raw['links']) if raw['links']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WCC::JTJ::Client::Utils
|
4
|
+
module_function
|
5
|
+
|
6
|
+
def camelcase(term)
|
7
|
+
term
|
8
|
+
.to_s
|
9
|
+
.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
|
10
|
+
.gsub(%r{/}, '::')
|
11
|
+
end
|
12
|
+
|
13
|
+
def define_camelcase_alias(*underscore_method_names, &block)
|
14
|
+
underscore_method_names.each do |method|
|
15
|
+
attribute = camelcase(method)
|
16
|
+
|
17
|
+
define_method(method) { instance_exec(attribute, &block) }
|
18
|
+
alias_method attribute, method if attribute != method
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
|
5
|
+
require_relative './client/version'
|
6
|
+
require_relative './client/utils'
|
7
|
+
require_relative './client/response'
|
8
|
+
|
9
|
+
require_relative './client/schemas/base'
|
10
|
+
require_relative './client/schemas/curriculum_summary'
|
11
|
+
require_relative './client/schemas/entry_summary'
|
12
|
+
require_relative './client/schemas/entry'
|
13
|
+
require_relative './client/schemas/scripture'
|
14
|
+
require_relative './client/schemas/writer'
|
15
|
+
require_relative './client/schemas/memory_verse_summary'
|
16
|
+
require_relative './client/schemas/memory_verse'
|
17
|
+
|
18
|
+
require_relative './client/responses/base'
|
19
|
+
require_relative './client/responses/root_response'
|
20
|
+
require_relative './client/responses/curriculums_list_response'
|
21
|
+
require_relative './client/responses/curriculum_show_response'
|
22
|
+
require_relative './client/responses/entries_list_response'
|
23
|
+
require_relative './client/responses/entry_show_response'
|
24
|
+
require_relative './client/responses/memory_verses_list_response'
|
25
|
+
require_relative './client/responses/memory_verse_show_response'
|
26
|
+
|
27
|
+
module WCC::JTJ
|
28
|
+
class Client
|
29
|
+
class << self
|
30
|
+
attr_writer :client
|
31
|
+
|
32
|
+
def client
|
33
|
+
@client || raise(StandardError, 'Not configured')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :base_url, :default_property, :base_path
|
38
|
+
|
39
|
+
def options
|
40
|
+
{
|
41
|
+
base_url: @base_url,
|
42
|
+
base_path: @base_path,
|
43
|
+
connection: @connection,
|
44
|
+
query_defaults: @query_defaults
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize(**options)
|
49
|
+
base_url = URI.parse(options[:base_url] || 'https://jtj.watermark.org')
|
50
|
+
@base_path = base_url.path == '' ? '/api' : base_url.path
|
51
|
+
@base_url = base_url.to_s
|
52
|
+
@connection = options[:connection] || Faraday.new
|
53
|
+
@query_defaults = options[:query_defaults] || {}
|
54
|
+
end
|
55
|
+
|
56
|
+
# performs an HTTP GET request to the specified path within the configured
|
57
|
+
# space and environment. Query parameters are merged with the defaults and
|
58
|
+
# appended to the request.
|
59
|
+
def get(path, query = {})
|
60
|
+
url = URI.join(@base_url, path)
|
61
|
+
|
62
|
+
Response.new(self,
|
63
|
+
{ url: url, query: query },
|
64
|
+
get_http(url, query))
|
65
|
+
end
|
66
|
+
|
67
|
+
# rubocop:disable Naming/AccessorMethodName
|
68
|
+
def get_current
|
69
|
+
resp = get(base_path).assert_ok!
|
70
|
+
|
71
|
+
Responses::RootResponse.new(resp, client: self)
|
72
|
+
end
|
73
|
+
|
74
|
+
def list_curriculums
|
75
|
+
path = File.join(base_path, 'curriculums')
|
76
|
+
resp = get(path).assert_ok!
|
77
|
+
|
78
|
+
Responses::CurriculumsListResponse.new(resp, client: self)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_curriculum(id)
|
82
|
+
path = File.join(base_path, 'curriculums', id.to_s)
|
83
|
+
resp = get(path).assert_ok!
|
84
|
+
|
85
|
+
Responses::CurriculumShowResponse.new(resp, client: self)
|
86
|
+
end
|
87
|
+
|
88
|
+
def list_entries(**query)
|
89
|
+
path = File.join(base_path, 'entries')
|
90
|
+
resp = get(path, query).assert_ok!
|
91
|
+
|
92
|
+
Responses::EntriesListResponse.new(resp, client: self)
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_entry(id)
|
96
|
+
path = File.join(base_path, 'entries', id.to_s)
|
97
|
+
resp = get(path).assert_ok!
|
98
|
+
|
99
|
+
Responses::EntryShowResponse.new(resp, client: self)
|
100
|
+
end
|
101
|
+
|
102
|
+
def list_memory_verses(**query)
|
103
|
+
path = File.join(base_path, 'memory_verses')
|
104
|
+
resp = get(path, query).assert_ok!
|
105
|
+
|
106
|
+
Responses::MemoryVersesListResponse.new(resp, client: self)
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_memory_verse(id)
|
110
|
+
path = File.join(base_path, 'memory_verses', id.to_s)
|
111
|
+
resp = get(path).assert_ok!
|
112
|
+
|
113
|
+
Responses::MemoryVerseShowResponse.new(resp, client: self)
|
114
|
+
end
|
115
|
+
# rubocop:enable Naming/AccessorMethodName
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def get_http(url, query, headers = {})
|
120
|
+
q = @query_defaults.merge(query || {})
|
121
|
+
|
122
|
+
loop do
|
123
|
+
resp = @connection.get(url, q, headers)
|
124
|
+
|
125
|
+
if [301, 302, 307].include?(resp.status)
|
126
|
+
url = URI.join(@base_url, resp.headers['Location'])
|
127
|
+
next
|
128
|
+
end
|
129
|
+
|
130
|
+
return resp
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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/jtj/client/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'wcc-jtj-client'
|
9
|
+
spec.version = WCC::JTJ::Client::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 = ''
|
15
|
+
spec.license = 'Not licensed for external use'
|
16
|
+
|
17
|
+
spec.required_ruby_version = '>= 2.3'
|
18
|
+
|
19
|
+
spec.files =
|
20
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'faraday'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wcc-jtj-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: 2022-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: ''
|
28
|
+
email:
|
29
|
+
- dev@watermark.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rubocop.yml"
|
35
|
+
- Gemfile
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/wcc-jtj-client.rb
|
39
|
+
- lib/wcc/jtj/client.rb
|
40
|
+
- lib/wcc/jtj/client/response.rb
|
41
|
+
- lib/wcc/jtj/client/responses/base.rb
|
42
|
+
- lib/wcc/jtj/client/responses/curriculum_show_response.rb
|
43
|
+
- lib/wcc/jtj/client/responses/curriculums_list_response.rb
|
44
|
+
- lib/wcc/jtj/client/responses/entries_list_response.rb
|
45
|
+
- lib/wcc/jtj/client/responses/entry_show_response.rb
|
46
|
+
- lib/wcc/jtj/client/responses/memory_verse_show_response.rb
|
47
|
+
- lib/wcc/jtj/client/responses/memory_verses_list_response.rb
|
48
|
+
- lib/wcc/jtj/client/responses/root_response.rb
|
49
|
+
- lib/wcc/jtj/client/schemas/base.rb
|
50
|
+
- lib/wcc/jtj/client/schemas/curriculum_summary.rb
|
51
|
+
- lib/wcc/jtj/client/schemas/entry.rb
|
52
|
+
- lib/wcc/jtj/client/schemas/entry_summary.rb
|
53
|
+
- lib/wcc/jtj/client/schemas/memory_verse.rb
|
54
|
+
- lib/wcc/jtj/client/schemas/memory_verse_summary.rb
|
55
|
+
- lib/wcc/jtj/client/schemas/scripture.rb
|
56
|
+
- lib/wcc/jtj/client/schemas/writer.rb
|
57
|
+
- lib/wcc/jtj/client/utils.rb
|
58
|
+
- lib/wcc/jtj/client/version.rb
|
59
|
+
- wcc-jtj-client.gemspec
|
60
|
+
homepage:
|
61
|
+
licenses:
|
62
|
+
- Not licensed for external use
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '2.3'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubygems_version: 3.1.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Internal Watermark.org gem, not licensed for external use.
|
83
|
+
test_files: []
|