api_client_builder 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +18 -0
- data/Jenkinsfile +50 -2
- data/README.md +25 -0
- data/api_client_builder.gemspec +1 -1
- data/bin/publish.sh +12 -0
- data/docker-compose.override.yml.example +14 -0
- data/docker-compose.yml +13 -0
- data/lib/api_client_builder/url_generator.rb +11 -2
- data/lib/api_client_builder/version.rb +1 -1
- data/spec/lib/api_client_builder/url_generator_spec.rb +26 -3
- metadata +10 -6
- data/build.sh +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f59cebf79d7809c5aaefdf60a84a0d3bd7d797c5bcb17d00d3cfd4c27af7aa6c
|
4
|
+
data.tar.gz: b23e9d509dcb617b8beb41dee7fb499f0dfa8e9bdd4f802b4cde713fd1abb724
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb885f59496c7ff2a11ccdced0a31ff182cd8758ee420c14c3ed78cb3445d0f76b290fe0ee08dcb5f5bef945b3d4a98a04df5f749d7491abcc91d939551ba03
|
7
|
+
data.tar.gz: 00d6a87b521d7dfa9e3e0d92e2ee573d9c73c85b57f37cc9511a0b71467efb09754525a8dff2961171edc82f23414db426b17639c5e442d348c956f9608b46c5
|
data/Dockerfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
FROM instructure/ruby-passenger:2.7
|
2
|
+
|
3
|
+
ENV RAILS_ENV "production"
|
4
|
+
|
5
|
+
USER root
|
6
|
+
|
7
|
+
RUN apt-get update -qq \
|
8
|
+
&& apt-get install -qqy \
|
9
|
+
git \
|
10
|
+
&& rm -rf /var/lib/apt/lists/*
|
11
|
+
|
12
|
+
USER docker
|
13
|
+
|
14
|
+
COPY --chown=docker:docker . .
|
15
|
+
|
16
|
+
RUN bundle install --jobs 8
|
17
|
+
|
18
|
+
CMD ["tail", "-f", "/dev/null"]
|
data/Jenkinsfile
CHANGED
@@ -3,11 +3,59 @@ pipeline {
|
|
3
3
|
label 'docker'
|
4
4
|
}
|
5
5
|
|
6
|
+
options {
|
7
|
+
parallelsAlwaysFailFast()
|
8
|
+
}
|
9
|
+
|
6
10
|
stages {
|
7
|
-
stage('
|
11
|
+
stage('Build') {
|
12
|
+
steps {
|
13
|
+
sh 'docker compose build --pull'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
stage('Spec') {
|
18
|
+
steps {
|
19
|
+
sh 'docker compose run api_client_builder bundle exec rspec --format doc'
|
20
|
+
sh '''
|
21
|
+
image=$(docker ps --all --no-trunc | grep spec | cut -f 1 -d " " | head -n 1)
|
22
|
+
docker cp "$image:/usr/src/app/coverage" .
|
23
|
+
'''
|
24
|
+
sh 'ls -als coverage'
|
25
|
+
}
|
26
|
+
|
27
|
+
post {
|
28
|
+
always {
|
29
|
+
publishHTML target: [
|
30
|
+
allowMissing: false,
|
31
|
+
alwaysLinkToLastBuild: false,
|
32
|
+
keepAll: true,
|
33
|
+
reportDir: 'coverage',
|
34
|
+
reportFiles: 'index.html',
|
35
|
+
reportName: 'Coverage Report'
|
36
|
+
]
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
stage('Publish') {
|
42
|
+
when {
|
43
|
+
allOf {
|
44
|
+
expression { GERRIT_BRANCH == 'master' }
|
45
|
+
environment name: 'GERRIT_EVENT_TYPE', value: 'change-merged'
|
46
|
+
}
|
47
|
+
}
|
8
48
|
steps {
|
9
|
-
|
49
|
+
withCredentials([string(credentialsId: 'rubygems-rw', variable: 'GEM_HOST_API_KEY')]) {
|
50
|
+
sh 'docker compose run -e GEM_HOST_API_KEY --rm api_client_builder /bin/bash -lc "./bin/publish.sh"'
|
51
|
+
}
|
10
52
|
}
|
11
53
|
}
|
12
54
|
}
|
55
|
+
|
56
|
+
post {
|
57
|
+
cleanup {
|
58
|
+
sh 'docker compose down --rmi=all --volumes --remove-orphans'
|
59
|
+
}
|
60
|
+
}
|
13
61
|
}
|
data/README.md
CHANGED
@@ -396,6 +396,31 @@ end
|
|
396
396
|
|
397
397
|
response_body = single_request.response
|
398
398
|
```
|
399
|
+
## Development
|
400
|
+
First copy the compose override example file:
|
401
|
+
```
|
402
|
+
cp docker-compose.override.yml.example docker-compose.override.yml
|
403
|
+
```
|
404
|
+
|
405
|
+
This project uses [Compose watch](https://docs.docker.com/compose/file-watch/) to sync files between host and container.
|
406
|
+
|
407
|
+
Compose watch will also rebuild the container (and install gems)
|
408
|
+
if new dependencies are added to the gemspec.
|
409
|
+
|
410
|
+
To build the container and start file watching, run the following
|
411
|
+
```
|
412
|
+
docker compose watch
|
413
|
+
```
|
414
|
+
|
415
|
+
To execute tests run
|
416
|
+
```
|
417
|
+
docker compose exec api_client_builder rspec
|
418
|
+
```
|
419
|
+
|
420
|
+
Start a shell in the container with
|
421
|
+
```
|
422
|
+
docker compose exec api_client_builder bash
|
423
|
+
```
|
399
424
|
|
400
425
|
---
|
401
426
|
|
data/api_client_builder.gemspec
CHANGED
data/bin/publish.sh
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
current_version=$(ruby -e "require '$(pwd)/lib/api_client_builder/version.rb'; puts APIClientBuilder::VERSION;")
|
6
|
+
|
7
|
+
if gem list --exact api_client_builder --remote --all | grep -o '\((.*)\)$' | tr '() ,' '\n' | grep -xF "$current_version"; then
|
8
|
+
echo "Gem has already been published ... skipping ..."
|
9
|
+
else
|
10
|
+
gem build ./api_client_builder.gemspec
|
11
|
+
find api_client_builder-*.gem | xargs gem push
|
12
|
+
fi
|
data/docker-compose.yml
ADDED
@@ -21,17 +21,26 @@ module APIClientBuilder
|
|
21
21
|
#
|
22
22
|
# @return [URI] the fully built route
|
23
23
|
def build_route(route, **params)
|
24
|
-
string_params = route.split(%r{[
|
24
|
+
string_params = route.split(%r{[\/=&]}).select { |param| param.start_with?(':') }
|
25
25
|
symboled_params = string_params.map { |param| param.tr(':', '').to_sym }
|
26
26
|
|
27
27
|
new_route = route.clone
|
28
28
|
symboled_params.each do |param|
|
29
29
|
value = params[param]
|
30
30
|
raise ArgumentError, "Param :#{param} is required" unless value
|
31
|
-
new_route.gsub!(":#{param}",
|
31
|
+
new_route.gsub!(":#{param}", encode_ascii(value.to_s))
|
32
32
|
end
|
33
33
|
|
34
34
|
@base_uri.merge(new_route)
|
35
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def encode_ascii(str)
|
40
|
+
str.each_char.map do |c|
|
41
|
+
next c if c.force_encoding('ascii').valid_encoding?
|
42
|
+
CGI.escape c
|
43
|
+
end.join
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
@@ -31,11 +31,34 @@ module APIClientBuilder
|
|
31
31
|
url_generator = URLGenerator.new('https://www.domain.com/api/endpoints/')
|
32
32
|
|
33
33
|
route = url_generator.build_route(
|
34
|
-
'route_to_object/:object_id/object',
|
35
|
-
object_id: "\u1F4a9"
|
34
|
+
'route_to_object/:object_id/object/:query_string',
|
35
|
+
object_id: "\u1F4a9",
|
36
|
+
query_string: "?sample[]=\u1F648\u1F649\u1F64A&success=party\u1F64C"
|
36
37
|
)
|
37
|
-
expect(route).to eq(URI.parse('https://www.domain.com/api/endpoints/route_to_object/%E1%BD%8A9/object'
|
38
|
+
expect(route).to eq(URI.parse('https://www.domain.com/api/endpoints/route_to_object/%E1%BD%8A9/object/' \
|
39
|
+
'?sample[]=%E1%BD%A48%E1%BD%A49%E1%BD%A4A&success=party%E1%BD%A4C'))
|
38
40
|
end
|
41
|
+
|
42
|
+
context "and the route has multiple colon params in they query string" do
|
43
|
+
let(:url) { 'object_one/:object_one_id/:object_one_id/object&as_user_id=:user_object_id¶m_2=:param_2&per_page=100' }
|
44
|
+
let(:url_generator) { URLGenerator.new('https://www.domain.com/api/endpoints/') }
|
45
|
+
|
46
|
+
subject do
|
47
|
+
route = url_generator.build_route(
|
48
|
+
url,
|
49
|
+
object_one_id: '4',
|
50
|
+
user_object_id: '1',
|
51
|
+
param_2: 'anotherqueryparam'
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
it do
|
56
|
+
is_expected.to eq URI.parse(
|
57
|
+
'https://www.domain.com/api/endpoints/object_one/4/4/object&as_user_id=1¶m_2=anotherqueryparam&per_page=100'
|
58
|
+
)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
39
62
|
end
|
40
63
|
|
41
64
|
context 'route with colon params and non matching keys' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayce Higgins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -71,19 +71,23 @@ description: API Client Builder provides an easy to use interface for creating H
|
|
71
71
|
email:
|
72
72
|
- jhiggins@instructure.com
|
73
73
|
- eng@instructure.com
|
74
|
-
executables:
|
74
|
+
executables:
|
75
|
+
- publish.sh
|
75
76
|
extensions: []
|
76
77
|
extra_rdoc_files: []
|
77
78
|
files:
|
78
79
|
- ".gitignore"
|
79
80
|
- ".rubocop.yml"
|
80
81
|
- ".travis.yml"
|
82
|
+
- Dockerfile
|
81
83
|
- Gemfile
|
82
84
|
- Jenkinsfile
|
83
85
|
- LICENSE.txt
|
84
86
|
- README.md
|
85
87
|
- api_client_builder.gemspec
|
86
|
-
-
|
88
|
+
- bin/publish.sh
|
89
|
+
- docker-compose.override.yml.example
|
90
|
+
- docker-compose.yml
|
87
91
|
- lib/api_client_builder.rb
|
88
92
|
- lib/api_client_builder/api_client.rb
|
89
93
|
- lib/api_client_builder/delete_request.rb
|
@@ -120,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
124
|
requirements:
|
121
125
|
- - ">="
|
122
126
|
- !ruby/object:Gem::Version
|
123
|
-
version: '2.
|
127
|
+
version: '2.7'
|
124
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
129
|
requirements:
|
126
130
|
- - ">="
|
127
131
|
- !ruby/object:Gem::Version
|
128
132
|
version: '0'
|
129
133
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
134
|
+
rubygems_version: 3.2.6
|
131
135
|
signing_key:
|
132
136
|
specification_version: 4
|
133
137
|
summary: API Client Builder provides an easy to use interface for creating HTTP api
|
data/build.sh
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
set -e
|
4
|
-
|
5
|
-
docker pull ruby:2.5
|
6
|
-
docker pull ruby:2.6
|
7
|
-
|
8
|
-
docker run --rm -v "`pwd`:/app" -w /app --user `id -u`:`id -g` -e HOME="/tmp" "ruby:2.3" \
|
9
|
-
/bin/sh -c "echo \"gem: --no-document\" >> ~/.gemrc && bundle install --jobs 5 --quiet && bundle exec rubocop --cache false --fail-level autocorrect"
|
10
|
-
|
11
|
-
for version in '2.5' '2.6'; do
|
12
|
-
echo "Testing Ruby $version..."
|
13
|
-
docker run --rm -v "`pwd`:/app" -w /app --user `id -u`:`id -g` \
|
14
|
-
-e HOME="/tmp" "ruby:$version" /bin/sh -c \
|
15
|
-
"echo \"gem: --no-document\" >> ~/.gemrc && bundle install --jobs 5 --quiet && bundle exec rspec"
|
16
|
-
done
|