faraday-panoptes 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/run_tests_CI.yml +17 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +9 -0
- data/Dockerfile +20 -0
- data/README.md +15 -1
- data/Rakefile +0 -9
- data/docker-compose.yml +11 -0
- data/faraday-panoptes.gemspec +9 -5
- data/lib/faraday/panoptes/access_token_authentication.rb +30 -0
- data/lib/faraday/panoptes/client_credentials_authentication.rb +7 -0
- data/lib/faraday/panoptes/version.rb +1 -1
- data/lib/faraday/panoptes.rb +2 -0
- metadata +80 -21
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 077ad6c0c7d63af21648067c7e831ca6466883168bf8436b68cf83e9aa49a56c
|
4
|
+
data.tar.gz: ed0af98fc264667e80d0312719ef9c5add62179226437caa21e9f68d8f4dcb89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d37c4d84ff2d20861c080e252c4abede36aeb1bf3282e111bd34266f196a0491e092a90d094e14c1c54e976e4ed6b7de5d801f9a7e533de3262f69f60516af2f
|
7
|
+
data.tar.gz: 671fe25d112f6a5dc73b92150238f522a6727ea492808ac27858cef0e3c4ce6e256ef9260a6be77d0cff269673727f8c409d51dbc7fc188a517615db88d644bf
|
@@ -0,0 +1,17 @@
|
|
1
|
+
name: Zooni CI
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
push: { branches: master }
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Run Tests
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- name: Setup Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.7
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Run tests
|
17
|
+
run: bundle exec rspec
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# 0.2.0
|
2
|
+
|
3
|
+
* Provides Faraday middleware which just sets the OAuth access token in the correct header
|
4
|
+
|
5
|
+
# 0.1.0
|
6
|
+
|
7
|
+
* Initial release.
|
8
|
+
* Provides Faraday middleware which will request access tokens using application key/secret and refresh them when needed.
|
9
|
+
* Provides Faraday middleware which will set correct headers for version 1 of the API.
|
data/Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
FROM ruby:2.7-slim
|
2
|
+
|
3
|
+
WORKDIR /app
|
4
|
+
|
5
|
+
RUN apt-get update && apt-get -y upgrade && \
|
6
|
+
apt-get install --no-install-recommends -y \
|
7
|
+
build-essential \
|
8
|
+
# git is required for installing gems
|
9
|
+
git && \
|
10
|
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
11
|
+
|
12
|
+
ADD ./Gemfile /app/
|
13
|
+
ADD ./faraday-panoptes.gemspec /app/
|
14
|
+
ADD ./ /app
|
15
|
+
|
16
|
+
# ensure we use a newer version of rubygems / bundler
|
17
|
+
RUN gem update --system
|
18
|
+
|
19
|
+
RUN bundle config --global jobs `cat /proc/cpuinfo | grep processor | wc -l | xargs -I % expr % - 1`
|
20
|
+
RUN bundle install
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@ api_client = Faraday.new(url: "https://panoptes.zooniverse.org") do |faraday|
|
|
7
7
|
faraday.request :panoptes_client_credentials, url: 'https://panoptes.zooniverse.org', client_id: 'APPLICATION_ID', client_secret: 'APPLICATION_SECRET'
|
8
8
|
faraday.request :panoptes_api_v1
|
9
9
|
faraday.response :json
|
10
|
+
|
11
|
+
faraday.adapter Faraday.default_adapter # WITHOUT THIS LINE NOTHING WILL HAPPEN
|
10
12
|
end
|
11
13
|
|
12
14
|
response = api_client.get("/api/projects/1")
|
@@ -33,10 +35,22 @@ Or install it yourself as:
|
|
33
35
|
|
34
36
|
## Development
|
35
37
|
|
36
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
39
|
|
38
40
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
41
|
|
42
|
+
Use docker & compose to setup the dev env
|
43
|
+
|
44
|
+
```shell
|
45
|
+
$ docker-compose build
|
46
|
+
```
|
47
|
+
|
48
|
+
Run a bash shell inside the new container
|
49
|
+
|
50
|
+
```shell
|
51
|
+
$ docker-compose run --service-ports --rm faraday-panoptes bash
|
52
|
+
```
|
53
|
+
|
40
54
|
## Contributing
|
41
55
|
|
42
56
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/faraday-panoptes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
data/Rakefile
CHANGED
data/docker-compose.yml
ADDED
data/faraday-panoptes.gemspec
CHANGED
@@ -19,11 +19,15 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency 'faraday', '~> 0
|
23
|
-
spec.add_dependency 'faraday_middleware', '~> 0
|
22
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
23
|
+
spec.add_dependency 'faraday_middleware', '~> 1.0'
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
26
|
+
spec.add_development_dependency "openssl"
|
28
27
|
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "vcr"
|
31
|
+
spec.add_development_dependency "webmock"
|
32
|
+
spec.add_development_dependency "jwt"
|
29
33
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
module Panoptes
|
6
|
+
class AccessTokenAuthentication < Faraday::Middleware
|
7
|
+
dependency do
|
8
|
+
require 'json' unless defined?(::JSON)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(app, url:, access_token:)
|
12
|
+
super(app)
|
13
|
+
@access_token = access_token
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
env[:request_headers]["Authorization"] = authorization_header
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def authorization_header
|
22
|
+
"Bearer #{access_token}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def access_token
|
26
|
+
@access_token
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,6 +3,10 @@ require 'faraday_middleware'
|
|
3
3
|
|
4
4
|
module Faraday
|
5
5
|
module Panoptes
|
6
|
+
|
7
|
+
class CredentialsOAuthError < StandardError
|
8
|
+
end
|
9
|
+
|
6
10
|
class ClientCredentialsAuthentication < Faraday::Middleware
|
7
11
|
dependency do
|
8
12
|
require 'json' unless defined?(::JSON)
|
@@ -13,6 +17,7 @@ module Faraday
|
|
13
17
|
@client_id = client_id
|
14
18
|
@client_secret = client_secret
|
15
19
|
@conn = Faraday.new(url: url)
|
20
|
+
@current_token = nil
|
16
21
|
end
|
17
22
|
|
18
23
|
def call(env)
|
@@ -45,6 +50,8 @@ module Faraday
|
|
45
50
|
grant_type: 'client_credentials',
|
46
51
|
client_id: @client_id,
|
47
52
|
client_secret: @client_secret)
|
53
|
+
|
54
|
+
raise CredentialsOAuthError.new "Failed to obtain access token" if result.status == 401 or result.status == 422 or result.body.empty?
|
48
55
|
JSON.parse(result.body)
|
49
56
|
end
|
50
57
|
end
|
data/lib/faraday/panoptes.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "faraday/panoptes/version"
|
2
2
|
require 'faraday/panoptes/api_v1'
|
3
|
+
require 'faraday/panoptes/access_token_authentication'
|
3
4
|
require 'faraday/panoptes/client_credentials_authentication'
|
4
5
|
|
5
6
|
module Faraday
|
6
7
|
module Panoptes
|
7
8
|
Faraday::Request.register_middleware \
|
9
|
+
panoptes_access_token: lambda { AccessTokenAuthentication },
|
8
10
|
panoptes_client_credentials: lambda { ClientCredentialsAuthentication },
|
9
11
|
panoptes_api_v1: lambda { ApiV1 }
|
10
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-panoptes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marten Veldthuis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,58 +16,100 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday_middleware
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
33
|
+
version: '1.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: openssl
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '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'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: rake
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - "
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
60
95
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
|
-
- - "
|
108
|
+
- - ">="
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: vcr
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
115
|
- - ">="
|
@@ -81,7 +123,21 @@ dependencies:
|
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: jwt
|
85
141
|
requirement: !ruby/object:Gem::Requirement
|
86
142
|
requirements:
|
87
143
|
- - ">="
|
@@ -102,17 +158,22 @@ executables: []
|
|
102
158
|
extensions: []
|
103
159
|
extra_rdoc_files: []
|
104
160
|
files:
|
161
|
+
- ".github/workflows/run_tests_CI.yml"
|
105
162
|
- ".gitignore"
|
106
|
-
- ".
|
163
|
+
- ".rspec"
|
164
|
+
- CHANGELOG.md
|
107
165
|
- CODE_OF_CONDUCT.md
|
166
|
+
- Dockerfile
|
108
167
|
- Gemfile
|
109
168
|
- LICENSE.txt
|
110
169
|
- README.md
|
111
170
|
- Rakefile
|
112
171
|
- bin/console
|
113
172
|
- bin/setup
|
173
|
+
- docker-compose.yml
|
114
174
|
- faraday-panoptes.gemspec
|
115
175
|
- lib/faraday/panoptes.rb
|
176
|
+
- lib/faraday/panoptes/access_token_authentication.rb
|
116
177
|
- lib/faraday/panoptes/api_v1.rb
|
117
178
|
- lib/faraday/panoptes/client_credentials_authentication.rb
|
118
179
|
- lib/faraday/panoptes/version.rb
|
@@ -120,7 +181,7 @@ homepage: https://github.com/zooniverse/faraday-panoptes
|
|
120
181
|
licenses:
|
121
182
|
- MIT
|
122
183
|
metadata: {}
|
123
|
-
post_install_message:
|
184
|
+
post_install_message:
|
124
185
|
rdoc_options: []
|
125
186
|
require_paths:
|
126
187
|
- lib
|
@@ -135,10 +196,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
196
|
- !ruby/object:Gem::Version
|
136
197
|
version: '0'
|
137
198
|
requirements: []
|
138
|
-
|
139
|
-
|
140
|
-
signing_key:
|
199
|
+
rubygems_version: 3.1.4
|
200
|
+
signing_key:
|
141
201
|
specification_version: 4
|
142
202
|
summary: Faraday middleware for talking to the Panoptes API
|
143
203
|
test_files: []
|
144
|
-
has_rdoc:
|
data/.travis.yml
DELETED