wcc-api 0.5.0 → 0.5.1

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: 8b9ffb1ca9873f835817d010c263b3119ebd9d7f
4
- data.tar.gz: b9c2eb273451c15f9448852e4aba17ae6482cd65
3
+ metadata.gz: 0c0b6f43132217782441bec2a54a9d046110bf83
4
+ data.tar.gz: dba5e3f10029efa9cb252474bd7763a3764cd9e4
5
5
  SHA512:
6
- metadata.gz: 3363843ade51012c9619dc76949268190b76bce8d8cb4b684034e1bb222c39f589e91f2d27786354c6794baeda43a3cc480ab6d9e02dd0366412c984397af503
7
- data.tar.gz: 3d48bb1a95ba2b631d3f976f07f74dfaf47909417570e1be8ce489b06bd83279043fef88204b1f18b163ecbf38483462ae08eb196f31ae4ceaf18f6fa8e3a8dd
6
+ metadata.gz: 725780f28f63a96972d70e5c7cd4596c5e4a8bb22955123db4f8d0f30c9ed30aec5cba14a1ccc65359cb0178f1c487d2e431967861f20e87f4fa8a93b2b215e1
7
+ data.tar.gz: f46f334b4a6c7c202f22898039350a54e7ccd8de6724c9e88cfe19fe3333db6d09c0fa6a4ae80a4f473a42439e513d2327b4e40dc82f6141f9577c4a153364ef
@@ -2,6 +2,6 @@
2
2
 
3
3
  module WCC
4
4
  module API
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
6
6
  end
7
7
  end
data/wcc-api.gemspec CHANGED
@@ -15,8 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/watermarkchurch/wcc-api'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0")
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.files = Dir['lib/**/*'] + %w[LICENSE.txt README.md wcc-api.gemspec]
20
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
20
  spec.require_paths = ['lib']
22
21
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Watermark Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-01 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wcc-base
@@ -210,23 +210,12 @@ description: Holds common code used in our applications that host APIs and those
210
210
  consume them.
211
211
  email:
212
212
  - dev@watermark.org
213
- executables:
214
- - rspec
213
+ executables: []
215
214
  extensions: []
216
215
  extra_rdoc_files: []
217
216
  files:
218
- - ".circleci/config.yml"
219
- - ".env.example"
220
- - ".gitignore"
221
- - ".rspec"
222
- - ".rubocop.yml"
223
- - ".rubocop_todo.yml"
224
- - Gemfile
225
- - Guardfile
226
217
  - LICENSE.txt
227
218
  - README.md
228
- - Rakefile
229
- - bin/rspec
230
219
  - lib/wcc/api.rb
231
220
  - lib/wcc/api/active_record_shim.rb
232
221
  - lib/wcc/api/base_query.rb
@@ -246,10 +235,6 @@ files:
246
235
  - lib/wcc/api/rspec/pagination_examples.rb
247
236
  - lib/wcc/api/version.rb
248
237
  - lib/wcc/api/view_helpers.rb
249
- - spec/fixtures/contentful/entries.json
250
- - spec/spec_helper.rb
251
- - spec/support/fixtures_helper.rb
252
- - spec/wcc/api/rest_client_spec.rb
253
238
  - wcc-api.gemspec
254
239
  homepage: https://github.com/watermarkchurch/wcc-api
255
240
  licenses:
@@ -271,13 +256,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
256
  version: '0'
272
257
  requirements: []
273
258
  rubyforge_project:
274
- rubygems_version: 2.5.2.3
259
+ rubygems_version: 2.6.11
275
260
  signing_key:
276
261
  specification_version: 4
277
262
  summary: Holds common code used in our applications that host APIs and those that
278
263
  consume them.
279
- test_files:
280
- - spec/fixtures/contentful/entries.json
281
- - spec/spec_helper.rb
282
- - spec/support/fixtures_helper.rb
283
- - spec/wcc/api/rest_client_spec.rb
264
+ test_files: []
data/.circleci/config.yml DELETED
@@ -1,41 +0,0 @@
1
- version: 2
2
- jobs:
3
- build:
4
- docker:
5
- - image: circleci/ruby:2.3.3-node
6
- steps:
7
- - checkout
8
- # Restore bundle cache
9
- - restore_cache:
10
- key: gem-{{ checksum "wcc-api.gemspec" }}
11
-
12
- # copy env
13
- - run: cp .env.example .env
14
-
15
- # Bundle install dependencies
16
- - run: bundle install --path /tmp/vendor/bundle
17
-
18
- # Store bundle cache
19
- - save_cache:
20
- key: gem-{{ checksum "wcc-api.gemspec" }}
21
- paths:
22
- - /tmp/vendor/bundle
23
-
24
- # run rubocop
25
- - type: shell
26
- command: |
27
- bundle exec rubocop
28
-
29
- # Run rspec in parallel
30
- - type: shell
31
- command: |
32
- bundle exec rspec --profile 10 \
33
- --format RspecJunitFormatter \
34
- --out test_results/rspec.xml \
35
- --format documentation \
36
- --order rand \
37
- $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
38
-
39
- # Save test results for timing analysis
40
- - store_test_results:
41
- path: test_results
data/.env.example DELETED
File without changes
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,190 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- AllCops:
4
- DisplayCopNames: true
5
- TargetRubyVersion: 2.3
6
- Exclude:
7
- # generated by rails/binstubs
8
- - 'bin/**/*'
9
-
10
- # generated by guard
11
- - 'Guardfile'
12
-
13
- # 3rd party
14
- - 'vendor/**/*'
15
- - 'lib/**/*'
16
-
17
- Style/Documentation:
18
- Enabled: false
19
-
20
- Style/BlockDelimiters:
21
- Exclude:
22
- # we like the `let(:foo) {}` syntax in specs
23
- - 'spec/**/*.rb'
24
-
25
- Style/ClassAndModuleChildren:
26
- EnforcedStyle: compact
27
-
28
- Style/FormatStringToken:
29
- EnforcedStyle: template
30
-
31
- Style/RegexpLiteral:
32
- Enabled: false
33
-
34
- Metrics/BlockLength:
35
- Exclude:
36
- # spec files that might have a big describe
37
- - 'spec/**/*.rb'
38
-
39
- Style/BracesAroundHashParameters:
40
- Enabled: false
41
-
42
- Lint/AssignmentInCondition:
43
- Enabled: false
44
-
45
- Style/EmptyMethod:
46
- EnforcedStyle: expanded
47
-
48
- Style/Alias:
49
- EnforcedStyle: prefer_alias_method
50
-
51
- Style/NumericPredicate:
52
- EnforcedStyle: comparison
53
-
54
- Layout/AlignParameters:
55
- EnforcedStyle: with_fixed_indentation
56
-
57
- Layout/IndentFirstHashElement:
58
- EnforcedStyle: consistent
59
-
60
- Layout/AlignHash:
61
- # allow coder to get around alignment rules by explicitly defining the hash param
62
- EnforcedLastArgumentHashStyle: ignore_explicit
63
-
64
- Layout/MultilineMethodCallIndentation:
65
- EnforcedStyle: indented
66
-
67
- Layout/MultilineOperationIndentation:
68
- EnforcedStyle: indented
69
-
70
- Rails:
71
- Enabled: true
72
-
73
- # These are all the cops that are disabled in the default configuration.
74
-
75
- Layout/FirstArrayElementLineBreak:
76
- Description: >-
77
- Checks for a line break before the first element in a
78
- multi-line array.
79
- Enabled: true
80
-
81
- Layout/FirstHashElementLineBreak:
82
- Description: >-
83
- Checks for a line break before the first element in a
84
- multi-line hash.
85
- Enabled: true
86
-
87
- Layout/FirstMethodArgumentLineBreak:
88
- Description: >-
89
- Checks for a line break before the first argument in a
90
- multi-line method call.
91
- Enabled: false
92
-
93
- Layout/FirstMethodParameterLineBreak:
94
- Description: >-
95
- Checks for a line break before the first parameter in a
96
- multi-line method parameter definition.
97
- Enabled: true
98
-
99
- Layout/MultilineAssignmentLayout:
100
- Description: 'Check for a newline after the assignment operator in multi-line assignments.'
101
- StyleGuide: '#indent-conditional-assignment'
102
- Enabled: true
103
-
104
- Rails/SaveBang:
105
- Description: 'Identifies possible cases where Active Record save! or related should be used.'
106
- StyleGuide: 'https://github.com/bbatsov/rails-style-guide#save-bang'
107
- Enabled: false
108
-
109
- Style/AutoResourceCleanup:
110
- Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
111
- Enabled: true
112
-
113
- Style/CollectionMethods:
114
- Description: 'Preferred collection methods.'
115
- StyleGuide: '#map-find-select-reduce-size'
116
- Enabled: true
117
-
118
- Style/Copyright:
119
- Description: 'Include a copyright notice in each file before any code.'
120
- Enabled: false
121
-
122
- Style/DocumentationMethod:
123
- Description: 'Public methods.'
124
- Enabled: false
125
- Exclude:
126
- - 'spec/**/*'
127
- - 'test/**/*'
128
-
129
- Style/ImplicitRuntimeError:
130
- Description: >-
131
- Use `raise` or `fail` with an explicit exception class and
132
- message, rather than just a message.
133
- Enabled: true
134
-
135
- Style/InlineComment:
136
- Description: 'Avoid trailing inline comments.'
137
- Enabled: true
138
-
139
- Style/MethodCallWithArgsParentheses:
140
- Description: 'Use parentheses for method calls with arguments.'
141
- StyleGuide: '#method-invocation-parens'
142
- Enabled: false
143
-
144
- Style/MethodCalledOnDoEndBlock:
145
- Description: 'Avoid chaining a method call on a do...end block.'
146
- StyleGuide: '#single-line-blocks'
147
- # TODO: enable after fixing todos
148
- Enabled: false
149
- Exclude:
150
- - 'spec/**/*'
151
-
152
- Style/MissingElse:
153
- Description: >-
154
- Require if/case expressions to have an else branches.
155
- If enabled, it is recommended that
156
- Style/UnlessElse and Style/EmptyElse be enabled.
157
- This will conflict with Style/EmptyElse if
158
- Style/EmptyElse is configured to style "both"
159
- Enabled: false
160
- EnforcedStyle: both
161
- SupportedStyles:
162
- # if - warn when an if expression is missing an else branch
163
- # case - warn when a case expression is missing an else branch
164
- # both - warn when an if or case expression is missing an else branch
165
- - if
166
- - case
167
- - both
168
-
169
- Style/OptionHash:
170
- Description: "Don't use option hashes when you can use keyword arguments."
171
- Enabled: true
172
-
173
- Style/ReturnNil:
174
- Description: 'Use return instead of return nil.'
175
- Enabled: true
176
-
177
- Style/Send:
178
- Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
179
- StyleGuide: '#prefer-public-send'
180
- Enabled: true
181
- Exclude:
182
- - 'spec/**/*'
183
-
184
- Style/StringMethods:
185
- Description: 'Checks if configured preferred methods are used over non-preferred.'
186
- Enabled: false
187
-
188
- Style/SingleLineBlockParams:
189
- Description: 'Enforces the names of some block params.'
190
- Enabled: false
data/.rubocop_todo.yml DELETED
@@ -1,63 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2019-02-11 12:22:05 -0600 using RuboCop version 0.64.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: 2
10
- Metrics/AbcSize:
11
- Max: 56
12
-
13
- # Offense count: 1
14
- # Configuration parameters: CountComments, ExcludedMethods.
15
- # ExcludedMethods: refine
16
- Metrics/BlockLength:
17
- Max: 31
18
-
19
- # Offense count: 4
20
- # Configuration parameters: CountComments, ExcludedMethods.
21
- Metrics/MethodLength:
22
- Max: 25
23
-
24
- # Offense count: 2
25
- # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
26
- # NamePrefix: is_, has_, have_
27
- # NamePrefixBlacklist: is_, has_, have_
28
- # NameWhitelist: is_a?
29
- # MethodDefinitionMacros: define_method, define_singleton_method
30
- Naming/PredicateName:
31
- Exclude:
32
- - 'spec/**/*'
33
- - 'lib/wcc/api/json/pagination.rb'
34
-
35
- # Offense count: 5
36
- # Cop supports --auto-correct.
37
- # Configuration parameters: AutoCorrect, EnforcedStyle.
38
- # SupportedStyles: nested, compact
39
- Style/ClassAndModuleChildren:
40
- Exclude:
41
- - 'lib/wcc/api/railtie.rb'
42
- - 'lib/wcc/api/rest_client/http_adapter.rb'
43
- - 'lib/wcc/api/rest_client/typhoeus_adapter.rb'
44
- - 'lib/wcc/api/version.rb'
45
-
46
- # Offense count: 2
47
- # Cop supports --auto-correct.
48
- Style/IfUnlessModifier:
49
- Exclude:
50
- - 'lib/wcc/api/json/pagination.rb'
51
-
52
- # Offense count: 1
53
- # Configuration parameters: SuspiciousParamNames.
54
- # SuspiciousParamNames: options, opts, args, params, parameters
55
- Style/OptionHash:
56
- Exclude:
57
- - 'lib/wcc/api/controller_helpers.rb'
58
-
59
- # Offense count: 11
60
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
61
- # URISchemes: http, https
62
- Metrics/LineLength:
63
- Max: 142
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in wcc-api.gemspec
6
- gemspec
data/Guardfile DELETED
@@ -1,32 +0,0 @@
1
- directories %w[lib spec]
2
-
3
- group :red_green_refactor, halt_on_fail: true do
4
- guard :rspec, cmd: 'bundle exec rspec --order rand', all_on_start: false do
5
- require 'guard/rspec/dsl'
6
- dsl = Guard::RSpec::Dsl.new(self)
7
-
8
- # RSpec files
9
- rspec = dsl.rspec
10
- watch(rspec.spec_helper) { rspec.spec_dir }
11
- watch(rspec.spec_support) { rspec.spec_dir }
12
- watch(rspec.spec_files)
13
-
14
- # Ruby files
15
- ruby = dsl.ruby
16
- dsl.watch_spec_files_for(ruby.lib_files)
17
- end
18
-
19
- guard :rubocop, cli: ['--display-cop-names'] do
20
- watch(%r{.+\.rb$})
21
- watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
22
- end
23
- end
24
-
25
- group :autofix do
26
- guard :rubocop, all_on_start: false, cli: ['--auto-correct', '--display-cop-names'] do
27
- watch(%r{.+\.rb$})
28
- watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
- end
30
- end
31
-
32
- scope group: :red_green_refactor
data/Rakefile DELETED
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
data/bin/rspec DELETED
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #
5
- # This file was generated by Bundler.
6
- #
7
- # The application 'rspec' is installed as part of a gem, and
8
- # this file is here to facilitate running it.
9
- #
10
-
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
14
-
15
- require 'rubygems'
16
- require 'bundler/setup'
17
-
18
- load Gem.bin_path('rspec-core', 'rspec')
@@ -1,80 +0,0 @@
1
- {
2
- "sys": {
3
- "type": "Array"
4
- },
5
- "total": 63,
6
- "skip": 0,
7
- "limit": 2,
8
- "items": [
9
- {
10
- "sys": {
11
- "space": {
12
- "sys": {
13
- "type": "Link",
14
- "linkType": "Space",
15
- "id": "hw5pse7y1ojx"
16
- }
17
- },
18
- "id": "6xJzDTX2HCo0u4QKIuGCOu",
19
- "type": "Entry",
20
- "createdAt": "2018-11-02T19:09:46.884Z",
21
- "updatedAt": "2018-11-02T19:09:46.884Z",
22
- "environment": {
23
- "sys": {
24
- "id": "gburgett",
25
- "type": "Link",
26
- "linkType": "Environment"
27
- }
28
- },
29
- "revision": 1,
30
- "contentType": {
31
- "sys": {
32
- "type": "Link",
33
- "linkType": "ContentType",
34
- "id": "menuButton"
35
- }
36
- },
37
- "locale": "en-US"
38
- },
39
- "fields": {
40
- "text": "What We Believe",
41
- "externalLink": "http://www.watermark.org/fort-worth/about/beliefs"
42
- }
43
- },
44
- {
45
- "sys": {
46
- "space": {
47
- "sys": {
48
- "type": "Link",
49
- "linkType": "Space",
50
- "id": "hw5pse7y1ojx"
51
- }
52
- },
53
- "id": "5yozzvgItUSYu4eI8yQ0ee",
54
- "type": "Entry",
55
- "createdAt": "2018-11-02T19:09:51.627Z",
56
- "updatedAt": "2018-11-02T19:09:51.627Z",
57
- "environment": {
58
- "sys": {
59
- "id": "gburgett",
60
- "type": "Link",
61
- "linkType": "Environment"
62
- }
63
- },
64
- "revision": 1,
65
- "contentType": {
66
- "sys": {
67
- "type": "Link",
68
- "linkType": "ContentType",
69
- "id": "section-block-text"
70
- }
71
- },
72
- "locale": "en-US"
73
- },
74
- "fields": {
75
- "internalTitle": "Frisco - Life Stage: Kids' Ministry",
76
- "body": "## Kids' Ministry\n\nKids' Ministry is availible for infants and children through 5th grade at both 9 AM and 11 AM services. "
77
- }
78
- }
79
- ]
80
- }
data/spec/spec_helper.rb DELETED
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- SPEC_DIR = File.dirname(__FILE__)
4
- FIXTURES_DIR = File.join(SPEC_DIR, 'fixtures')
5
-
6
- $LOAD_PATH.unshift File.join(SPEC_DIR, '..', 'lib')
7
- $LOAD_PATH.unshift SPEC_DIR
8
-
9
- require 'dotenv'
10
- Dotenv.load
11
-
12
- require 'webmock/rspec'
13
- Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
14
-
15
- require 'wcc/api'
16
-
17
- RSpec.configure do |config|
18
- config.expect_with :rspec do |expectations|
19
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20
- end
21
-
22
- config.mock_with :rspec do |mocks|
23
- mocks.verify_partial_doubles = true
24
- end
25
-
26
- config.shared_context_metadata_behavior = :apply_to_host_groups
27
-
28
- config.include FixturesHelper
29
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module FixturesHelper
4
- def load_fixture(file_name)
5
- file = "#{File.dirname(__FILE__)}/../fixtures/#{file_name}"
6
- return File.read(file) if File.exist?(file)
7
- end
8
- end
@@ -1,296 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'wcc/api/rest_client'
5
-
6
- RSpec.describe WCC::API::RestClient do
7
- describe 'initialize' do
8
- after do
9
- described_class::ADAPTERS = {
10
- typhoeus: ['typhoeus', '~> 1.0'],
11
- http: ['http', '> 1.0', '< 3.0']
12
- }.freeze
13
- end
14
-
15
- it 'fails to load when no adapter gem found' do
16
- expect do
17
- described_class::ADAPTERS = {
18
- asdf: ['asdf', '~> 1.0']
19
- }.freeze
20
-
21
- described_class.new(
22
- api_url: 'https://cdn.contentful.com'
23
- )
24
- end.to raise_error(ArgumentError)
25
- end
26
-
27
- it 'fails to load when gem is wrong version' do
28
- expect do
29
- described_class::ADAPTERS = {
30
- http: ['http', '< 1.0']
31
- }.freeze
32
-
33
- described_class.new(
34
- api_url: 'https://cdn.contentful.com'
35
- )
36
- end.to raise_error(ArgumentError)
37
- end
38
-
39
- it 'fails to load when adapter is not invokeable' do
40
- described_class::ADAPTERS = {}.freeze
41
-
42
- expect do
43
- described_class::ADAPTERS = {
44
- http: ['http', '< 1.0']
45
- }.freeze
46
-
47
- described_class.new(
48
- api_url: 'https://cdn.contentful.com',
49
- adapter: :whoopsie
50
- )
51
- end.to raise_error(ArgumentError)
52
- end
53
- end
54
-
55
- described_class::ADAPTERS.keys.each do |adapter|
56
- context "with #{adapter} adapter" do
57
- subject(:client) do
58
- described_class.new(
59
- api_url: 'https://cdn.contentful.com/spaces/1234',
60
- adapter: adapter
61
- )
62
- end
63
-
64
- let(:entries) do
65
- ::JSON.parse(load_fixture('contentful/entries.json'))
66
- end
67
-
68
- describe 'get' do
69
- it 'gets entries with query params' do
70
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries?limit=2')
71
- .to_return(body: load_fixture('contentful/entries.json'))
72
-
73
- # act
74
- resp = client.get('entries', limit: 2)
75
-
76
- # assert
77
- resp.assert_ok!
78
- expect(resp.code).to eq(200)
79
- expect(resp.to_json['items'].map { |i| i.dig('sys', 'id') }).to eq(
80
- %w[6xJzDTX2HCo0u4QKIuGCOu 5yozzvgItUSYu4eI8yQ0ee]
81
- )
82
- end
83
-
84
- it 'can query entries with query param' do
85
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
86
- .with(query: {
87
- 'content_type' => 'menuButton',
88
- 'fields.text' => 'Ministries'
89
- })
90
- .to_return(body: load_fixture('contentful/entries.json'))
91
-
92
- # act
93
- resp = client.get('entries',
94
- content_type: 'menuButton',
95
- 'fields.text' => 'Ministries')
96
-
97
- # assert
98
- resp.assert_ok!
99
- expect(resp.code).to eq(200)
100
- expect(resp.to_json['items'].map { |i| i.dig('sys', 'id') }).to eq(
101
- %w[6xJzDTX2HCo0u4QKIuGCOu 5yozzvgItUSYu4eI8yQ0ee]
102
- )
103
- end
104
-
105
- it 'follows redirects' do
106
- stub_request(:get, 'http://jtj.watermark.org/api')
107
- .to_return(status: 301, headers: { 'Location' => 'https://jtj.watermark.org/api' })
108
- stub_request(:get, 'https://jtj.watermark.org/api')
109
- .to_return(body: '{ "links": { "entries": "/entries" } }')
110
-
111
- client = described_class.new(
112
- api_url: 'http://jtj.watermark.org/'
113
- )
114
-
115
- # act
116
- resp = client.get('/api')
117
-
118
- # assert
119
- resp.assert_ok!
120
- expect(resp.to_json['links']).to_not be_nil
121
- end
122
-
123
- it 'paginates directly when block given' do
124
- page1 = entries.merge('total' => 7)
125
- page2 = entries.merge('total' => 7, 'skip' => 2)
126
- page3 = entries.merge('total' => 7, 'skip' => 4)
127
- page4 = entries.merge('total' => 7, 'skip' => 6)
128
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
129
- .with(query: { 'limit' => 2 })
130
- .to_return(body: page1.to_json)
131
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
132
- .with(query: { 'limit' => 2, 'skip' => 2 })
133
- .to_return(body: page2.to_json)
134
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
135
- .with(query: { 'limit' => 2, 'skip' => 4 })
136
- .to_return(body: page3.to_json)
137
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
138
- .with(query: { 'limit' => 2, 'skip' => 6 })
139
- .to_return(body: page4.to_json)
140
-
141
- # act
142
- resp = client.get('entries', limit: 2)
143
-
144
- # assert
145
- resp.assert_ok!
146
- num_pages = 0
147
- resp.each_page do |page|
148
- expect(page.to_json['items'].length).to be <= 2
149
- num_pages += 1
150
- end
151
- expect(num_pages).to eq(4)
152
- end
153
-
154
- it 'does lazy pagination' do
155
- page1 = entries.merge('total' => 7)
156
- page2 = entries.merge('total' => 7, 'skip' => 2)
157
- page3 = entries.merge('total' => 7, 'skip' => 4)
158
- page4 = entries.merge('total' => 7, 'skip' => 6, 'items' => [entries['items'][0]])
159
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
160
- .with(query: { 'limit' => 2 })
161
- .to_return(body: page1.to_json)
162
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
163
- .with(query: { 'limit' => 2, 'skip' => 2 })
164
- .to_return(body: page2.to_json)
165
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
166
- .with(query: { 'limit' => 2, 'skip' => 4 })
167
- .to_return(body: page3.to_json)
168
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
169
- .with(query: { 'limit' => 2, 'skip' => 6 })
170
- .to_return(body: page4.to_json)
171
-
172
- # act
173
- resp = client.get('entries', limit: 2)
174
-
175
- # assert
176
- resp.assert_ok!
177
- pages = resp.each_page
178
- expect(pages).to be_a(Enumerator::Lazy)
179
- pages =
180
- pages.map do |page|
181
- expect(page.to_json['items'].length).to be <= 2
182
- page.to_json['items']
183
- end
184
- pages = pages.force
185
- expect(pages.length).to eq(4)
186
- expect(pages.flatten.map { |c| c.dig('sys', 'id') })
187
- .to eq(%w[
188
- 6xJzDTX2HCo0u4QKIuGCOu
189
- 5yozzvgItUSYu4eI8yQ0ee
190
- 6xJzDTX2HCo0u4QKIuGCOu
191
- 5yozzvgItUSYu4eI8yQ0ee
192
- 6xJzDTX2HCo0u4QKIuGCOu
193
- 5yozzvgItUSYu4eI8yQ0ee
194
- 6xJzDTX2HCo0u4QKIuGCOu
195
- ])
196
- end
197
-
198
- it 'does not paginate if only the first page is taken' do
199
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
200
- .with(query: { 'limit' => 2 })
201
- .to_return(body: load_fixture('contentful/entries.json'))
202
-
203
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
204
- .with(query: { 'limit' => 2, 'skip' => 2 })
205
- .to_raise(StandardError.new('Should not execute request for second page'))
206
-
207
- # act
208
- resp = client.get('entries', limit: 2)
209
-
210
- # assert
211
- resp.assert_ok!
212
- items = resp.items.take(2)
213
- expect(items.map { |c| c.dig('sys', 'id') }.force)
214
- .to eq(%w[
215
- 6xJzDTX2HCo0u4QKIuGCOu
216
- 5yozzvgItUSYu4eI8yQ0ee
217
- ])
218
- end
219
-
220
- it 'memoizes pages' do
221
- page1 = entries.merge('total' => 4)
222
- page2 = entries.merge('total' => 4, 'skip' => 2)
223
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
224
- .with(query: { 'limit' => 2 })
225
- .to_return(body: page1.to_json)
226
- .times(1)
227
- stub_request(:get, 'https://cdn.contentful.com/spaces/1234/entries')
228
- .with(query: { 'limit' => 2, 'skip' => 2 })
229
- .to_return(body: page2.to_json)
230
- .times(1)
231
-
232
- # act
233
- resp = client.get('entries', limit: 2)
234
-
235
- # assert
236
- resp.assert_ok!
237
- # first pagination
238
- expect(resp.items.count).to eq(4)
239
- # should be memoized
240
- expect(resp.items.map { |c| c.dig('sys', 'id') }.force)
241
- .to eq(%w[
242
- 6xJzDTX2HCo0u4QKIuGCOu
243
- 5yozzvgItUSYu4eI8yQ0ee
244
- 6xJzDTX2HCo0u4QKIuGCOu
245
- 5yozzvgItUSYu4eI8yQ0ee
246
- ])
247
- end
248
- end
249
-
250
- describe 'post' do
251
- it 'performs a post with body' do
252
- stub_request(:post, 'https://cdn.contentful.com/spaces/1234/entries')
253
- .with(body: '{"test":"data"}')
254
- .to_return(status: 204)
255
-
256
- # act
257
- resp = client.post('entries', { 'test' => 'data' })
258
-
259
- # assert
260
- resp.assert_ok!
261
- expect(resp.status).to eq(204)
262
- end
263
- end
264
-
265
- describe 'put' do
266
- it 'performs a put with body' do
267
- stub_request(:put, 'https://cdn.contentful.com/spaces/1234/entries/123')
268
- .with(body: '{"test":"data"}')
269
- .to_return(body: '{"test":"data"}')
270
-
271
- # act
272
- resp = client.put('entries/123', { 'test' => 'data' })
273
-
274
- # assert
275
- resp.assert_ok!
276
- expect(resp.status).to eq(200)
277
- expect(resp.body).to eq({ 'test' => 'data' })
278
- end
279
- end
280
-
281
- describe 'delete' do
282
- it 'performs a delete' do
283
- stub_request(:delete, 'https://cdn.contentful.com/spaces/1234/entries/123')
284
- .to_return(status: 204)
285
-
286
- # act
287
- resp = client.delete('entries/123')
288
-
289
- # assert
290
- resp.assert_ok!
291
- expect(resp.status).to eq(204)
292
- end
293
- end
294
- end
295
- end
296
- end