wcc-api 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/.circleci/config.yml +41 -0
- data/.env.example +0 -0
- data/.rspec +2 -0
- data/.rubocop.yml +190 -0
- data/.rubocop_todo.yml +63 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -1
- data/bin/rspec +18 -0
- data/lib/wcc/api.rb +6 -8
- data/lib/wcc/api/base_query.rb +10 -10
- data/lib/wcc/api/controller_helpers.rb +5 -3
- data/lib/wcc/api/json.rb +2 -0
- data/lib/wcc/api/json/pagination.rb +16 -13
- data/lib/wcc/api/railtie.rb +3 -1
- data/lib/wcc/api/rest_client.rb +83 -0
- data/lib/wcc/api/rest_client/api_error.rb +26 -0
- data/lib/wcc/api/rest_client/http_adapter.rb +19 -0
- data/lib/wcc/api/rest_client/response.rb +135 -0
- data/lib/wcc/api/rest_client/typhoeus_adapter.rb +34 -0
- data/lib/wcc/api/rspec.rb +2 -1
- data/lib/wcc/api/rspec/cache_header_examples.rb +15 -13
- data/lib/wcc/api/rspec/collection_matchers.rb +4 -2
- data/lib/wcc/api/rspec/pagination_examples.rb +8 -8
- data/lib/wcc/api/version.rb +3 -1
- data/lib/wcc/api/view_helpers.rb +3 -3
- data/spec/fixtures/contentful/entries.json +80 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/fixtures_helper.rb +8 -0
- data/spec/wcc/api/rest_client_spec.rb +266 -0
- data/wcc-api.gemspec +23 -13
- metadata +150 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29f4bd81d5f646565f0656931a8078216fb9de58
|
4
|
+
data.tar.gz: ae9b9f7df6dc2955fc353f71ddb6c245905e1b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0561533a5a86c806a60a6ebfc4d99d8689775439a3f1eed22da10fdb62fa7e94eb73617a231920a6d97356b0cd119d26c02a66da2ab864caea1542540e14e95
|
7
|
+
data.tar.gz: 02e635a8449a312b0d1d7f974f91c84beedc5bd39cf62a7ad5bd253556bd4afedba949abbc064675340cbafade4f06652621d86847a8198bf3b1624889fd48a2
|
@@ -0,0 +1,41 @@
|
|
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
ADDED
File without changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,190 @@
|
|
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/IndentHash:
|
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
ADDED
@@ -0,0 +1,63 @@
|
|
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
CHANGED
data/Rakefile
CHANGED
data/bin/rspec
ADDED
@@ -0,0 +1,18 @@
|
|
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')
|
data/lib/wcc/api.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'wcc'
|
2
4
|
require 'wcc/api/version'
|
3
5
|
|
4
|
-
module WCC
|
5
|
-
|
6
|
-
PROJECT_ROOT = File.expand_path(File.join(__FILE__, '..', '..', '..'))
|
7
|
-
end
|
6
|
+
module WCC::API
|
7
|
+
PROJECT_ROOT = File.expand_path(File.join(__FILE__, '..', '..', '..'))
|
8
8
|
end
|
9
9
|
|
10
|
-
if defined?(Rails)
|
11
|
-
require 'wcc/api/railtie'
|
12
|
-
end
|
10
|
+
require 'wcc/api/railtie' if defined?(Rails)
|
13
11
|
|
14
12
|
require 'wcc/api/base_query'
|
15
13
|
require 'wcc/api/json'
|
16
14
|
require 'wcc/api/controller_helpers'
|
15
|
+
require 'wcc/api/rest_client'
|
17
16
|
require 'wcc/api/view_helpers'
|
18
|
-
|
data/lib/wcc/api/base_query.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WCC::API
|
2
4
|
class BaseQuery
|
3
|
-
attr_reader :scope, :paging
|
4
|
-
attr_accessor :limit, :offset
|
5
|
+
attr_reader :scope, :paging, :limit, :offset
|
5
6
|
attr_accessor :filter
|
6
7
|
|
7
8
|
MAX_LIMIT = 50
|
@@ -15,7 +16,7 @@ module WCC::API
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def permitted_keys
|
18
|
-
%i
|
19
|
+
%i[limit offset filter]
|
19
20
|
end
|
20
21
|
|
21
22
|
def default_scope
|
@@ -27,11 +28,11 @@ module WCC::API
|
|
27
28
|
@paging = paging
|
28
29
|
set_defaults
|
29
30
|
permitted_keys.each do |key|
|
30
|
-
|
31
|
+
public_send("#{key}=", params[key]) if params.key?(key)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
|
-
def call(scope=self.scope)
|
35
|
+
def call(scope = self.scope)
|
35
36
|
scope = scope.dup
|
36
37
|
scope = paged(scope)
|
37
38
|
scope = ordered(scope)
|
@@ -39,7 +40,7 @@ module WCC::API
|
|
39
40
|
scope
|
40
41
|
end
|
41
42
|
|
42
|
-
def paged(scope=self.scope)
|
43
|
+
def paged(scope = self.scope)
|
43
44
|
if paging
|
44
45
|
scope
|
45
46
|
.limit(limit)
|
@@ -49,11 +50,11 @@ module WCC::API
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
def ordered(scope=self.scope)
|
53
|
+
def ordered(scope = self.scope)
|
53
54
|
scope
|
54
55
|
end
|
55
56
|
|
56
|
-
def filtered(scope=self.scope)
|
57
|
+
def filtered(scope = self.scope)
|
57
58
|
scope
|
58
59
|
end
|
59
60
|
|
@@ -65,7 +66,7 @@ module WCC::API
|
|
65
66
|
|
66
67
|
def limit=(new_limit)
|
67
68
|
new_limit = new_limit.to_i
|
68
|
-
@limit =
|
69
|
+
@limit = new_limit > MAX_LIMIT ? MAX_LIMIT : new_limit
|
69
70
|
end
|
70
71
|
|
71
72
|
def offset=(new_offset)
|
@@ -85,4 +86,3 @@ module WCC::API
|
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
88
|
-
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WCC::API
|
2
4
|
module ControllerHelpers
|
5
|
+
private
|
3
6
|
|
4
|
-
|
5
|
-
options = {public: true, must_revalidate: true}.merge!(options)
|
7
|
+
def set_cache_headers(scope_or_record, options = {})
|
8
|
+
options = { public: true, must_revalidate: true }.merge!(options)
|
6
9
|
|
7
10
|
if expiry = options.delete(:expiry)
|
8
11
|
expires_in expiry, options.slice(:public, :must_revalidate)
|
@@ -10,6 +13,5 @@ module WCC::API
|
|
10
13
|
|
11
14
|
fresh_when scope_or_record, options.slice(:etag, :public, :last_modified)
|
12
15
|
end
|
13
|
-
|
14
16
|
end
|
15
17
|
end
|