spearly-sdk-ruby 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -2
- data/Gemfile.lock +15 -8
- data/README.md +35 -6
- data/lib/spearly/auth/authorizer.rb +10 -2
- data/lib/spearly/auth/oauth_user.rb +6 -6
- data/lib/spearly/auth/rails/helpers.rb +2 -4
- data/lib/spearly/auth/team.rb +6 -6
- data/lib/spearly/auth/token.rb +8 -7
- data/lib/spearly/auth/user.rb +11 -27
- data/lib/spearly/auth.rb +1 -0
- data/lib/spearly/version.rb +1 -1
- data/spearly.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ca2e7efcf2a6ef0c4c933c9edd49115fc2c82c5d601c34a84c76ca87bd1602
|
4
|
+
data.tar.gz: 2e924b9bf892c8504034bf654acdda7f28d6bdc36cc01b1bc915f6333b4c5648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c73bf97ee424325e8032d2719e25dc38cdfd369fac1f3775af89324f152c513c1a147a3082fefe83dab2b39d03e7f303a75c4a38a54a4e7fbdc5d1fd1c564fb9
|
7
|
+
data.tar.gz: aa26cc8cb81db6f9587439fc297915deaf88c5bc61e83266390f25a9e6f37da2571de3eb17f040c12dfb8ad10d5800f8d7385ee4fb48fa813d9dc2b9527fb9fd
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,27 @@
|
|
1
|
+
## [0.4.0] - 2021-09-13
|
2
|
+
|
3
|
+
- Error handling improvements
|
4
|
+
|
5
|
+
## [0.3.2] - 2021-09-13
|
6
|
+
|
7
|
+
- Use the new `Spearly API v2`
|
8
|
+
- Refactors parsing `JSON` data
|
9
|
+
|
10
|
+
## [0.2.4] - 2021-07-16
|
11
|
+
|
12
|
+
- Rescue `Signet::AuthorizationError` on `Spearly::Auth::Authorizer`
|
13
|
+
|
14
|
+
## [0.2.3] - 2021-06-18
|
15
|
+
|
16
|
+
- Raise `Spearly::Auth::AuthorizationError` and `Spearly::Auth::ServerError` from `Spearly::Auth::User` and `Spearly::Auth::Token`
|
17
|
+
|
1
18
|
## [0.2.2] - 2021-06-11
|
2
19
|
|
3
|
-
- Updates README and gem specs
|
20
|
+
- Updates `README` and gem specs
|
4
21
|
|
5
22
|
## [0.2.1] - 2021-05-31
|
6
23
|
|
7
|
-
- Initialize Spearly::Auth::User with bearer token
|
24
|
+
- Initialize `Spearly::Auth::User` with bearer token
|
8
25
|
|
9
26
|
## [0.2.0] - 2021-05-31
|
10
27
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spearly-sdk-ruby (0.
|
4
|
+
spearly-sdk-ruby (0.3.1)
|
5
5
|
addressable (~> 2.3)
|
6
6
|
faraday (>= 0.17.4, < 2.0)
|
7
7
|
rake (~> 13.0)
|
@@ -10,24 +10,30 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
addressable (2.
|
13
|
+
addressable (2.8.0)
|
14
14
|
public_suffix (>= 2.0.2, < 5.0)
|
15
15
|
ast (2.4.2)
|
16
16
|
coderay (1.1.3)
|
17
17
|
diff-lcs (1.4.4)
|
18
|
-
faraday (1.
|
18
|
+
faraday (1.7.1)
|
19
19
|
faraday-em_http (~> 1.0)
|
20
20
|
faraday-em_synchrony (~> 1.0)
|
21
21
|
faraday-excon (~> 1.1)
|
22
|
+
faraday-httpclient (~> 1.0.1)
|
22
23
|
faraday-net_http (~> 1.0)
|
23
24
|
faraday-net_http_persistent (~> 1.1)
|
25
|
+
faraday-patron (~> 1.0)
|
26
|
+
faraday-rack (~> 1.0)
|
24
27
|
multipart-post (>= 1.2, < 3)
|
25
28
|
ruby2_keywords (>= 0.0.4)
|
26
29
|
faraday-em_http (1.0.0)
|
27
30
|
faraday-em_synchrony (1.0.0)
|
28
31
|
faraday-excon (1.1.0)
|
32
|
+
faraday-httpclient (1.0.1)
|
29
33
|
faraday-net_http (1.0.1)
|
30
|
-
faraday-net_http_persistent (1.
|
34
|
+
faraday-net_http_persistent (1.2.0)
|
35
|
+
faraday-patron (1.0.0)
|
36
|
+
faraday-rack (1.0.0)
|
31
37
|
jwt (2.2.3)
|
32
38
|
method_source (1.0.0)
|
33
39
|
multi_json (1.15.0)
|
@@ -40,7 +46,7 @@ GEM
|
|
40
46
|
method_source (~> 1.0)
|
41
47
|
public_suffix (4.0.6)
|
42
48
|
rainbow (3.0.0)
|
43
|
-
rake (13.0.
|
49
|
+
rake (13.0.6)
|
44
50
|
regexp_parser (2.1.1)
|
45
51
|
rexml (3.2.5)
|
46
52
|
rspec (3.10.0)
|
@@ -71,9 +77,9 @@ GEM
|
|
71
77
|
rubocop (~> 1.0)
|
72
78
|
rubocop-ast (>= 1.1.0)
|
73
79
|
ruby-progressbar (1.11.0)
|
74
|
-
ruby2_keywords (0.0.
|
75
|
-
signet (0.
|
76
|
-
addressable (~> 2.
|
80
|
+
ruby2_keywords (0.0.5)
|
81
|
+
signet (0.16.0)
|
82
|
+
addressable (~> 2.8)
|
77
83
|
faraday (>= 0.17.3, < 2.0)
|
78
84
|
jwt (>= 1.5, < 3.0)
|
79
85
|
multi_json (~> 1.10)
|
@@ -81,6 +87,7 @@ GEM
|
|
81
87
|
|
82
88
|
PLATFORMS
|
83
89
|
x86_64-darwin-20
|
90
|
+
x86_64-linux
|
84
91
|
|
85
92
|
DEPENDENCIES
|
86
93
|
pry (~> 0.13.1)
|
data/README.md
CHANGED
@@ -7,26 +7,55 @@ Spearly SDK for Ruby.
|
|
7
7
|
Add this line to your application's `Gemfile`:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'spearly-sdk-ruby', '~>
|
10
|
+
gem 'spearly-sdk-ruby', '~> x.y.z', require: 'spearly'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
```sh
|
15
|
-
|
15
|
+
bundle install
|
16
16
|
```
|
17
17
|
|
18
|
-
Or install it
|
18
|
+
Or install it manually:
|
19
19
|
```sh
|
20
|
-
|
20
|
+
gem install spearly-sdk-ruby
|
21
|
+
```
|
22
|
+
|
23
|
+
## Contribute
|
24
|
+
### Increment version
|
25
|
+
```sh
|
26
|
+
vim lib/spearly/version.rb
|
27
|
+
```
|
28
|
+
|
29
|
+
### Update CHANGELOG
|
30
|
+
```sh
|
31
|
+
vim CHANGELOG.md
|
32
|
+
```
|
33
|
+
|
34
|
+
### Update Gemfile.lock
|
35
|
+
```sh
|
36
|
+
bundle install
|
37
|
+
```
|
38
|
+
|
39
|
+
### New version commit
|
40
|
+
```sh
|
41
|
+
new_version=$(ruby -e "require './lib/spearly/version'; puts Spearly::VERSION")
|
42
|
+
|
43
|
+
git commit -m "v$new_version"
|
44
|
+
git tag -a v$new_version -m "Release $new_version"
|
45
|
+
|
46
|
+
git push origin main
|
47
|
+
git push origin --tags
|
21
48
|
```
|
22
49
|
|
23
50
|
## Publish
|
24
51
|
### Build
|
25
52
|
```sh
|
26
|
-
|
53
|
+
rake build
|
27
54
|
```
|
28
55
|
|
29
56
|
### Push to RubyGems
|
30
57
|
```sh
|
31
|
-
|
58
|
+
new_version=$(ruby -e "require './lib/spearly/version'; puts Spearly::VERSION")
|
59
|
+
|
60
|
+
gem push pkg/spearly-sdk-ruby-$new_version.gem
|
32
61
|
```
|
@@ -12,18 +12,26 @@ module Spearly
|
|
12
12
|
|
13
13
|
def method_missing(name, *args)
|
14
14
|
@client.send(name, *args)
|
15
|
+
rescue Signet::AuthorizationError
|
16
|
+
raise Spearly::Auth::AuthorizationError
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
21
|
def initialize_client
|
22
|
+
Faraday.default_connection_options = {
|
23
|
+
headers: {
|
24
|
+
'Accept' => 'application/vnd.spearly.v2+json'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
20
28
|
client = ::Signet::OAuth2::Client.new
|
21
29
|
client.client_id = @params[:client_id] || @params['client_id']
|
22
30
|
client.client_secret = @params[:client_secret] || @params['client_secret']
|
23
31
|
client.code = @params[:code] || @params['code']
|
24
32
|
client.grant_type = @params[:grant_type] || @params['grant_type']
|
25
|
-
client.authorization_uri = "#{ENV['
|
26
|
-
client.token_credential_uri = "#{ENV['
|
33
|
+
client.authorization_uri = "#{ENV['SPEARLY_API_URL']}/oauth/authorize"
|
34
|
+
client.token_credential_uri = "#{ENV['SPEARLY_API_URL']}/oauth/token"
|
27
35
|
client.redirect_uri = @params[:redirect_uri] || @params['redirect_uri']
|
28
36
|
|
29
37
|
client.access_token = @params[:access_token] || @params['access_token']
|
@@ -6,22 +6,22 @@ require 'faraday'
|
|
6
6
|
module Spearly
|
7
7
|
module Auth
|
8
8
|
class OauthUser
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :data
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(name, *_args)
|
16
|
-
@
|
16
|
+
@data[name.to_s]
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_json(*_args)
|
20
|
-
@
|
20
|
+
@data.to_json
|
21
21
|
end
|
22
22
|
|
23
23
|
def as_json
|
24
|
-
@
|
24
|
+
@data.as_json
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -13,18 +13,16 @@ module Spearly
|
|
13
13
|
def spearly_token
|
14
14
|
@spearly_token ||= begin
|
15
15
|
token = Spearly::Auth::Token.new(request.authorization)
|
16
|
-
token.info
|
17
16
|
|
18
|
-
token
|
17
|
+
token.info ? token : nil
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
def spearly_user
|
23
22
|
@spearly_user ||= begin
|
24
23
|
user = Spearly::Auth::User.new(request.authorization)
|
25
|
-
user.find
|
26
24
|
|
27
|
-
user
|
25
|
+
user.find ? user : nil
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
data/lib/spearly/auth/team.rb
CHANGED
@@ -6,22 +6,22 @@ require 'faraday'
|
|
6
6
|
module Spearly
|
7
7
|
module Auth
|
8
8
|
class Team
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :data
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(name, *_args)
|
16
|
-
@
|
16
|
+
@data[name.to_s]
|
17
17
|
end
|
18
18
|
|
19
19
|
def to_json(*_args)
|
20
|
-
@
|
20
|
+
@data.to_json
|
21
21
|
end
|
22
22
|
|
23
23
|
def as_json
|
24
|
-
@
|
24
|
+
@data.as_json
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/spearly/auth/token.rb
CHANGED
@@ -6,32 +6,33 @@ require 'faraday'
|
|
6
6
|
module Spearly
|
7
7
|
module Auth
|
8
8
|
class Token
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :data, :token
|
10
10
|
|
11
11
|
def initialize(token)
|
12
12
|
@token = token
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(name, *_args)
|
16
|
-
@
|
16
|
+
@data[name.to_s]
|
17
17
|
end
|
18
18
|
|
19
19
|
def info
|
20
|
-
token_info_uri = "#{ENV['
|
20
|
+
token_info_uri = "#{ENV['SPEARLY_API_URL']}/oauth/token/info"
|
21
21
|
url = Addressable::URI.parse(token_info_uri).normalize.to_s
|
22
22
|
client = Faraday.default_connection
|
23
23
|
|
24
24
|
res = client.get(url,
|
25
25
|
nil,
|
26
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
26
27
|
'Authorization' => @token)
|
27
28
|
|
28
29
|
return unless res.status == 200
|
29
30
|
|
30
|
-
@
|
31
|
+
@data = JSON.parse(res.body)
|
31
32
|
end
|
32
33
|
|
33
34
|
def revoke(params)
|
34
|
-
token_revoke_uri = "#{ENV['
|
35
|
+
token_revoke_uri = "#{ENV['SPEARLY_API_URL']}/oauth/revoke"
|
35
36
|
url = Addressable::URI.parse(token_revoke_uri).normalize.to_s
|
36
37
|
client = Faraday.default_connection
|
37
38
|
|
@@ -46,11 +47,11 @@ module Spearly
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def to_json(*_args)
|
49
|
-
@
|
50
|
+
@data.to_json
|
50
51
|
end
|
51
52
|
|
52
53
|
def as_json
|
53
|
-
@
|
54
|
+
@data.as_json
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
data/lib/spearly/auth/user.rb
CHANGED
@@ -6,72 +6,56 @@ require 'faraday'
|
|
6
6
|
module Spearly
|
7
7
|
module Auth
|
8
8
|
class User
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :data
|
10
10
|
|
11
11
|
def initialize(token)
|
12
12
|
@token = token
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(name, *_args)
|
16
|
-
@
|
16
|
+
@data[name.to_s]
|
17
17
|
end
|
18
18
|
|
19
19
|
def find
|
20
|
-
user_profile_uri = "#{ENV['
|
20
|
+
user_profile_uri = "#{ENV['SPEARLY_API_URL']}/profile"
|
21
21
|
url = Addressable::URI.parse(user_profile_uri).normalize.to_s
|
22
22
|
client = Faraday.default_connection
|
23
23
|
|
24
24
|
res = client.get(url,
|
25
25
|
nil,
|
26
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
26
27
|
'Authorization' => @token)
|
27
28
|
|
28
29
|
return unless res.status == 200
|
29
30
|
|
30
|
-
@
|
31
|
+
@data = JSON.parse(res.body)['data']
|
31
32
|
end
|
32
33
|
|
33
34
|
def teams
|
34
|
-
teams_uri = "#{ENV['
|
35
|
+
teams_uri = "#{ENV['SPEARLY_API_URL']}/teams"
|
35
36
|
url = Addressable::URI.parse(teams_uri).normalize.to_s
|
36
37
|
client = Faraday.default_connection
|
37
38
|
|
38
39
|
res = client.get(url,
|
39
40
|
nil,
|
41
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
40
42
|
'Authorization' => @token)
|
41
43
|
|
42
|
-
return unless res.status == 200
|
44
|
+
return [] unless res.status == 200
|
43
45
|
|
44
|
-
team_hashes = JSON.parse(res.body)['
|
46
|
+
team_hashes = JSON.parse(res.body)['data']
|
45
47
|
|
46
48
|
team_hashes.map do |team_hash|
|
47
49
|
Spearly::Auth::Team.new(team_hash)
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
|
-
def oauth_users
|
52
|
-
oauth_users_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth_users"
|
53
|
-
url = Addressable::URI.parse(oauth_users_uri).normalize.to_s
|
54
|
-
client = Faraday.default_connection
|
55
|
-
|
56
|
-
res = client.get(url,
|
57
|
-
nil,
|
58
|
-
'Authorization' => @token)
|
59
|
-
|
60
|
-
return unless res.status == 200
|
61
|
-
|
62
|
-
oauth_user_hashes = JSON.parse(res.body)['oauth_users']
|
63
|
-
|
64
|
-
oauth_user_hashes.map do |oauth_user_hash|
|
65
|
-
Spearly::Auth::OauthUser.new(oauth_user_hash)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
53
|
def to_json(*_args)
|
70
|
-
@
|
54
|
+
@data.to_json
|
71
55
|
end
|
72
56
|
|
73
57
|
def as_json
|
74
|
-
@
|
58
|
+
@data.as_json
|
75
59
|
end
|
76
60
|
end
|
77
61
|
end
|
data/lib/spearly/auth.rb
CHANGED
data/lib/spearly/version.rb
CHANGED
data/spearly.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.required_ruby_version = Gem::Requirement.new('>= 2.7.2')
|
14
14
|
gem.metadata['homepage_uri'] = gem.homepage
|
15
15
|
gem.metadata['source_code_uri'] = 'https://github.com/unimal-jp/spearly-sdk-ruby'
|
16
|
-
gem.metadata['changelog_uri'] =
|
16
|
+
gem.metadata['changelog_uri'] = "https://github.com/unimal-jp/spearly-sdk-ruby/blob/v#{Spearly::VERSION}/CHANGELOG.md"
|
17
17
|
|
18
18
|
gem.files = `git ls-files`.split("\n")
|
19
19
|
gem.executables = 'spearly'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spearly-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spearly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -166,7 +166,7 @@ licenses: []
|
|
166
166
|
metadata:
|
167
167
|
homepage_uri: https://github.com/unimal-jp/spearly-sdk-ruby
|
168
168
|
source_code_uri: https://github.com/unimal-jp/spearly-sdk-ruby
|
169
|
-
changelog_uri: https://github.com/unimal-jp/spearly-sdk-ruby/CHANGELOG.md
|
169
|
+
changelog_uri: https://github.com/unimal-jp/spearly-sdk-ruby/blob/v0.4.0/CHANGELOG.md
|
170
170
|
post_install_message:
|
171
171
|
rdoc_options: []
|
172
172
|
require_paths:
|