spearly-sdk-ruby 0.10.0 → 0.11.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 +4 -4
- data/.github/workflows/main.yml +11 -6
- data/.rubocop.yml +3 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +8 -1
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/lib/spearly/auth/authorizer.rb +0 -1
- data/lib/spearly/auth/client.rb +36 -159
- data/lib/spearly/auth/team.rb +43 -12
- data/lib/spearly/auth/team_member.rb +28 -0
- data/lib/spearly/auth/team_subscription.rb +18 -0
- data/lib/spearly/auth/token.rb +18 -50
- data/lib/spearly/auth/user.rb +17 -55
- data/lib/spearly/auth.rb +2 -9
- data/lib/spearly/cloud/client.rb +2 -2
- data/lib/spearly/version.rb +1 -1
- data/spearly.gemspec +1 -8
- data/spec/spearly/auth/client_spec.rb +8 -72
- data/spec/spearly/auth/team_member_spec.rb +159 -0
- data/spec/spearly/auth/team_spec.rb +371 -0
- data/spec/spearly/auth/team_subscription_spec.rb +82 -0
- data/spec/spearly/auth/token_spec.rb +150 -0
- data/spec/spearly/auth/user_spec.rb +168 -0
- data/spec/spec_helper.rb +0 -1
- metadata +12 -92
- data/lib/spearly/auth/engine.rb +0 -13
- data/lib/spearly/auth/oauth_user.rb +0 -32
- data/lib/spearly/auth/rails/helpers.rb +0 -31
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffd3333dfa37f250288b37eb593db42db89846aa436397371c403a20ec9fe5e9
|
|
4
|
+
data.tar.gz: d1b0eeab87ff53e34bbd1b7c00b8b691e679823c2b09ad5df713003691349d7a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e1a2419d6013bac9e3adbb347afd731fc04a9b1a85c87c41e11c7fbec6ade89db3ca2b3d54adfe5c9a1720a680e22968a1df5960901e2cf76cc29d2e1bf9b85
|
|
7
|
+
data.tar.gz: 3c19e93be4e91f9cc17333a5d4a7d7233f678a4a5b9db393bb5122c26ea1a5d2d4df3d2a3848b177097e606938270519a3e2a3ede0b232af40219bda848e39aa
|
data/.github/workflows/main.yml
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
name: Ruby
|
|
2
|
-
on:
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- '**'
|
|
3
6
|
jobs:
|
|
4
7
|
build:
|
|
5
|
-
runs-on: ubuntu-
|
|
8
|
+
runs-on: ubuntu-22.04
|
|
6
9
|
steps:
|
|
7
|
-
-
|
|
8
|
-
|
|
10
|
+
- name: Checkout code
|
|
11
|
+
uses: actions/checkout@v3
|
|
12
|
+
|
|
13
|
+
- name: Setup Ruby
|
|
9
14
|
uses: ruby/setup-ruby@v1
|
|
10
15
|
with:
|
|
11
|
-
ruby-version:
|
|
16
|
+
ruby-version: 3.1.4
|
|
17
|
+
|
|
12
18
|
- name: Run the default task
|
|
13
19
|
run: |
|
|
14
|
-
gem install bundler -v 2.3.26
|
|
15
20
|
bundle install
|
|
16
21
|
bundle exec rake
|
data/.rubocop.yml
CHANGED
|
@@ -2,7 +2,7 @@ require:
|
|
|
2
2
|
- rubocop-rspec
|
|
3
3
|
AllCops:
|
|
4
4
|
NewCops: enable
|
|
5
|
-
TargetRubyVersion:
|
|
5
|
+
TargetRubyVersion: 3.1
|
|
6
6
|
Exclude:
|
|
7
7
|
- 'bin/**/*'
|
|
8
8
|
Layout/EmptyLineBetweenDefs:
|
|
@@ -16,6 +16,8 @@ Metrics/ClassLength:
|
|
|
16
16
|
Enabled: false
|
|
17
17
|
Metrics/MethodLength:
|
|
18
18
|
Enabled: false
|
|
19
|
+
Naming/AccessorMethodName:
|
|
20
|
+
Enabled: false
|
|
19
21
|
RSpec/BeNil:
|
|
20
22
|
EnforcedStyle: 'be'
|
|
21
23
|
RSpec/ExampleLength:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## [0.11.1] - 2023-09-27
|
|
2
|
+
|
|
3
|
+
- Implement a reader for `Spearly::Auth::Client#token` [#18](https://github.com/unimal-jp/spearly-sdk-ruby/pull/18)
|
|
4
|
+
|
|
5
|
+
## [0.11.0] - 2023-09-23
|
|
6
|
+
|
|
7
|
+
- Throw errors `from Spearly::Auth` methods [#15](https://github.com/unimal-jp/spearly-sdk-ruby/pull/15)
|
|
8
|
+
- `Spearly::Auth::Client` refactors [#14](https://github.com/unimal-jp/spearly-sdk-ruby/pull/14)
|
|
9
|
+
- Upgrade Ruby to 3.1.4 [#13](https://github.com/unimal-jp/spearly-sdk-ruby/pull/13)
|
|
10
|
+
- Remove deprecated classes and helpers [#12](https://github.com/unimal-jp/spearly-sdk-ruby/pull/12)
|
|
11
|
+
|
|
1
12
|
## [0.10.0] - 2022-12-05
|
|
2
13
|
|
|
3
14
|
- `Spearly::Auth::Client#get_team_subscriptions()`
|
data/Gemfile
CHANGED
|
@@ -3,4 +3,11 @@
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
group :development do
|
|
7
|
+
gem 'bundler-audit', '~> 0.9'
|
|
8
|
+
gem 'fuubar', '~> 2.5'
|
|
9
|
+
gem 'pry', '~> 0.13'
|
|
10
|
+
gem 'rspec', '~> 3.10'
|
|
11
|
+
gem 'rubocop', '~> 1.15'
|
|
12
|
+
gem 'rubocop-rspec', '~> 2.3'
|
|
13
|
+
end
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/spearly/auth/client.rb
CHANGED
|
@@ -1,176 +1,53 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'team_member'
|
|
4
|
+
require_relative 'team_subscription'
|
|
5
|
+
require_relative 'team'
|
|
6
|
+
require_relative 'token'
|
|
7
|
+
require_relative 'user'
|
|
8
|
+
|
|
3
9
|
module Spearly
|
|
4
10
|
module Auth
|
|
5
11
|
class Client
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/users/#{user_id}"
|
|
12
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
13
|
-
client = Faraday.default_connection
|
|
14
|
-
|
|
15
|
-
res = client.get(uri_parsed,
|
|
16
|
-
nil,
|
|
17
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
18
|
-
'Authorization' => @token)
|
|
19
|
-
|
|
20
|
-
if res.status == 200
|
|
21
|
-
JSON.parse(res.body)['data']
|
|
22
|
-
else
|
|
23
|
-
{}
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def create_team(params)
|
|
28
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams"
|
|
29
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
30
|
-
client = Faraday.default_connection
|
|
31
|
-
|
|
32
|
-
res = client.post(uri_parsed,
|
|
33
|
-
params.as_json,
|
|
34
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
35
|
-
'Authorization' => @token)
|
|
36
|
-
|
|
37
|
-
case res.status
|
|
38
|
-
when 201
|
|
39
|
-
JSON.parse(res.body)['data']
|
|
40
|
-
when 422
|
|
41
|
-
JSON.parse(res.body)
|
|
42
|
-
else
|
|
43
|
-
{}
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def get_team(team_id)
|
|
48
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams/#{team_id}"
|
|
49
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
50
|
-
client = Faraday.default_connection
|
|
51
|
-
|
|
52
|
-
res = client.get(uri_parsed,
|
|
53
|
-
nil,
|
|
54
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
55
|
-
'Authorization' => @token)
|
|
56
|
-
|
|
57
|
-
if res.status == 200
|
|
58
|
-
JSON.parse(res.body)['data']
|
|
59
|
-
else
|
|
60
|
-
{}
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def get_teams(params = {})
|
|
65
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams"
|
|
66
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
67
|
-
client = Faraday.default_connection
|
|
68
|
-
|
|
69
|
-
res = client.get(uri_parsed,
|
|
70
|
-
params.as_json,
|
|
71
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
72
|
-
'Authorization' => @token)
|
|
73
|
-
|
|
74
|
-
if res.status == 200
|
|
75
|
-
JSON.parse(res.body)['data']
|
|
76
|
-
else
|
|
77
|
-
[]
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def update_team(team_id, params)
|
|
82
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams/#{team_id}"
|
|
83
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
84
|
-
client = Faraday.default_connection
|
|
85
|
-
|
|
86
|
-
res = client.put(uri_parsed,
|
|
87
|
-
params.as_json,
|
|
88
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
89
|
-
'Authorization' => @token)
|
|
90
|
-
|
|
91
|
-
return unless res.status == 200
|
|
92
|
-
|
|
93
|
-
JSON.parse(res.body)['data']
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def regenerate_team_api_access_token(team_id)
|
|
97
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams/#{team_id}/regenerate_api_access_token"
|
|
98
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
99
|
-
client = Faraday.default_connection
|
|
100
|
-
|
|
101
|
-
res = client.post(uri_parsed,
|
|
102
|
-
nil,
|
|
103
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
104
|
-
'Authorization' => @token)
|
|
105
|
-
|
|
106
|
-
return unless res.status == 200
|
|
107
|
-
|
|
108
|
-
JSON.parse(res.body)['data']
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def invite_user_to_team(team_id, params)
|
|
112
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams/#{team_id}/invite"
|
|
113
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
114
|
-
client = Faraday.default_connection
|
|
12
|
+
include Team
|
|
13
|
+
include TeamMember
|
|
14
|
+
include TeamSubscription
|
|
15
|
+
include Token
|
|
16
|
+
include User
|
|
115
17
|
|
|
116
|
-
|
|
117
|
-
params.as_json,
|
|
118
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
119
|
-
'Authorization' => @token)
|
|
18
|
+
attr_reader :token
|
|
120
19
|
|
|
121
|
-
|
|
20
|
+
def initialize(token)
|
|
21
|
+
@token = token
|
|
122
22
|
|
|
123
|
-
|
|
23
|
+
base_url = ENV.fetch('SPEARLY_API_URL', nil)
|
|
24
|
+
@client = Faraday.new(base_url)
|
|
124
25
|
end
|
|
125
26
|
|
|
126
|
-
def
|
|
127
|
-
|
|
128
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
129
|
-
client = Faraday.default_connection
|
|
27
|
+
def run_request(method:, path:, params: nil)
|
|
28
|
+
path_parsed = Addressable::URI.parse(path).normalize.to_s
|
|
130
29
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
else
|
|
139
|
-
[]
|
|
140
|
-
end
|
|
30
|
+
@client.run_request(method.to_sym,
|
|
31
|
+
path_parsed,
|
|
32
|
+
params,
|
|
33
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
|
34
|
+
'Authorization' => @token)
|
|
35
|
+
rescue Faraday::ConnectionFailed => e
|
|
36
|
+
raise ServerError, e.message
|
|
141
37
|
end
|
|
142
38
|
|
|
143
|
-
def
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if res.status == 200
|
|
154
|
-
JSON.parse(res.body)['data']
|
|
155
|
-
else
|
|
156
|
-
{}
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def get_team_subscriptions(team_id, params)
|
|
161
|
-
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/teams/#{team_id}/subscriptions"
|
|
162
|
-
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
163
|
-
client = Faraday.default_connection
|
|
164
|
-
|
|
165
|
-
res = client.get(uri_parsed,
|
|
166
|
-
params.as_json,
|
|
167
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
168
|
-
'Authorization' => @token)
|
|
169
|
-
|
|
170
|
-
if res.status == 200
|
|
171
|
-
JSON.parse(res.body)
|
|
39
|
+
def process_response(response)
|
|
40
|
+
case response.status
|
|
41
|
+
when 200, 201, 422
|
|
42
|
+
JSON.parse(response.body)
|
|
43
|
+
when 401
|
|
44
|
+
raise AuthorizationError, 'Unauthorized'
|
|
45
|
+
when 404
|
|
46
|
+
raise NotFoundError, 'Not Found'
|
|
47
|
+
when 503
|
|
48
|
+
raise ServiceUnavailableError, 'Service Unavailable'
|
|
172
49
|
else
|
|
173
|
-
|
|
50
|
+
raise ServerError, 'Server Error'
|
|
174
51
|
end
|
|
175
52
|
end
|
|
176
53
|
end
|
data/lib/spearly/auth/team.rb
CHANGED
|
@@ -2,27 +2,58 @@
|
|
|
2
2
|
|
|
3
3
|
module Spearly
|
|
4
4
|
module Auth
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
module Team
|
|
6
|
+
# POST /teams
|
|
7
|
+
def create_team(params)
|
|
8
|
+
response = run_request(
|
|
9
|
+
:method => :post,
|
|
10
|
+
path: '/teams',
|
|
11
|
+
params: params
|
|
12
|
+
)
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
@data = data
|
|
14
|
+
process_response(response)
|
|
10
15
|
end
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
# GET /teams/:team_id
|
|
18
|
+
def get_team(team_id)
|
|
19
|
+
response = run_request(
|
|
20
|
+
:method => :get,
|
|
21
|
+
path: "/teams/#{team_id}"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
process_response(response)
|
|
14
25
|
end
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
# GET /teams
|
|
28
|
+
def get_teams(params)
|
|
29
|
+
response = run_request(
|
|
30
|
+
:method => :get,
|
|
31
|
+
path: '/teams',
|
|
32
|
+
params: params
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
process_response(response)
|
|
18
36
|
end
|
|
19
37
|
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
# PUT /teams/:team_id
|
|
39
|
+
def update_team(team_id, params)
|
|
40
|
+
response = run_request(
|
|
41
|
+
:method => :put,
|
|
42
|
+
path: "/teams/#{team_id}",
|
|
43
|
+
params: params
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
process_response(response)
|
|
22
47
|
end
|
|
23
48
|
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
# GET /teams/:team_id/regenerate_api_access_token
|
|
50
|
+
def regenerate_team_api_access_token(team_id)
|
|
51
|
+
response = run_request(
|
|
52
|
+
:method => :get,
|
|
53
|
+
path: "/teams/#{team_id}/regenerate_api_access_token"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
process_response(response)
|
|
26
57
|
end
|
|
27
58
|
end
|
|
28
59
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spearly
|
|
4
|
+
module Auth
|
|
5
|
+
module TeamMember
|
|
6
|
+
# POST /teams/:team_id/invite
|
|
7
|
+
def invite_user_to_team(team_id, params)
|
|
8
|
+
response = run_request(
|
|
9
|
+
:method => :post,
|
|
10
|
+
path: "/teams/#{team_id}/invite",
|
|
11
|
+
params: params
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
process_response(response)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# GET /teams/:team_id/members
|
|
18
|
+
def get_team_members(team_id)
|
|
19
|
+
response = run_request(
|
|
20
|
+
:method => :get,
|
|
21
|
+
path: "/teams/#{team_id}/members"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
process_response(response)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Spearly
|
|
4
|
+
module Auth
|
|
5
|
+
module TeamSubscription
|
|
6
|
+
# GET /teams/:team_id/subscriptions
|
|
7
|
+
def get_team_subscriptions(team_id, params)
|
|
8
|
+
response = run_request(
|
|
9
|
+
:method => :get,
|
|
10
|
+
path: "/teams/#{team_id}/subscriptions",
|
|
11
|
+
params: params
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
process_response(response)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/spearly/auth/token.rb
CHANGED
|
@@ -1,61 +1,29 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'addressable/uri'
|
|
4
|
-
require 'faraday'
|
|
5
|
-
|
|
6
3
|
module Spearly
|
|
7
4
|
module Auth
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
module Token
|
|
6
|
+
# GET /oauth/token/info
|
|
7
|
+
def get_token_info
|
|
8
|
+
response = run_request(
|
|
9
|
+
:method => :get,
|
|
10
|
+
path: '/oauth/token/info'
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
process_response(response)
|
|
17
14
|
end
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def info
|
|
24
|
-
token_info_uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/oauth/token/info"
|
|
25
|
-
url = Addressable::URI.parse(token_info_uri).normalize.to_s
|
|
26
|
-
client = Faraday.default_connection
|
|
27
|
-
|
|
28
|
-
res = client.get(url,
|
|
29
|
-
nil,
|
|
30
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
31
|
-
'Authorization' => @token)
|
|
32
|
-
|
|
33
|
-
return unless res.status == 200
|
|
16
|
+
# POST /oauth/revoke
|
|
17
|
+
def revoke_token(params)
|
|
18
|
+
params[:token] = @token.gsub(/^Bearer /i, '')
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
url = Addressable::URI.parse(token_revoke_uri).normalize.to_s
|
|
41
|
-
client = Faraday.default_connection
|
|
42
|
-
|
|
43
|
-
bearer_token = @token.gsub(/^Bearer /i, '')
|
|
44
|
-
|
|
45
|
-
client.post(url,
|
|
46
|
-
{
|
|
47
|
-
client_id: params[:client_id],
|
|
48
|
-
client_secret: params[:client_secret],
|
|
49
|
-
token: bearer_token
|
|
50
|
-
})
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def to_json(*_args)
|
|
54
|
-
@data.to_json
|
|
55
|
-
end
|
|
20
|
+
response = run_request(
|
|
21
|
+
:method => :post,
|
|
22
|
+
path: '/oauth/revoke',
|
|
23
|
+
params: params
|
|
24
|
+
)
|
|
56
25
|
|
|
57
|
-
|
|
58
|
-
@data.as_json
|
|
26
|
+
process_response(response)
|
|
59
27
|
end
|
|
60
28
|
end
|
|
61
29
|
end
|
data/lib/spearly/auth/user.rb
CHANGED
|
@@ -1,65 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'addressable/uri'
|
|
4
|
-
require 'faraday'
|
|
5
|
-
|
|
6
3
|
module Spearly
|
|
7
4
|
module Auth
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def respond_to_missing?(_name, *_args)
|
|
20
|
-
true
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def find
|
|
24
|
-
user_profile_uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/profile"
|
|
25
|
-
url = Addressable::URI.parse(user_profile_uri).normalize.to_s
|
|
26
|
-
client = Faraday.default_connection
|
|
27
|
-
|
|
28
|
-
res = client.get(url,
|
|
29
|
-
nil,
|
|
30
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
31
|
-
'Authorization' => @token)
|
|
32
|
-
|
|
33
|
-
return unless res.status == 200
|
|
34
|
-
|
|
35
|
-
@data = JSON.parse(res.body)['data']
|
|
5
|
+
module User
|
|
6
|
+
# GET /users/:user_id
|
|
7
|
+
# requires SPEARLY_API_ACCESS_TOKEN as token
|
|
8
|
+
def get_user(user_id)
|
|
9
|
+
response = run_request(
|
|
10
|
+
:method => :get,
|
|
11
|
+
path: "/users/#{user_id}"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
process_response(response)
|
|
36
15
|
end
|
|
37
16
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
nil,
|
|
45
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
|
46
|
-
'Authorization' => @token)
|
|
47
|
-
|
|
48
|
-
return [] unless res.status == 200
|
|
49
|
-
|
|
50
|
-
team_hashes = JSON.parse(res.body)['data']
|
|
51
|
-
|
|
52
|
-
team_hashes.map do |team_hash|
|
|
53
|
-
Spearly::Auth::Team.new(team_hash)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def to_json(*_args)
|
|
58
|
-
@data.to_json
|
|
59
|
-
end
|
|
17
|
+
# GET /profile
|
|
18
|
+
def get_profile
|
|
19
|
+
response = run_request(
|
|
20
|
+
:method => :get,
|
|
21
|
+
path: '/profile'
|
|
22
|
+
)
|
|
60
23
|
|
|
61
|
-
|
|
62
|
-
@data.as_json
|
|
24
|
+
process_response(response)
|
|
63
25
|
end
|
|
64
26
|
end
|
|
65
27
|
end
|
data/lib/spearly/auth.rb
CHANGED
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'auth/authorizer'
|
|
4
4
|
require_relative 'auth/client'
|
|
5
|
-
require_relative 'auth/engine'
|
|
6
|
-
require_relative 'auth/oauth_user'
|
|
7
|
-
require_relative 'auth/team'
|
|
8
|
-
require_relative 'auth/token'
|
|
9
|
-
require_relative 'auth/user'
|
|
10
5
|
|
|
11
6
|
module Spearly
|
|
12
7
|
module Auth
|
|
13
8
|
class Error < StandardError; end
|
|
14
9
|
class AuthorizationError < Error; end
|
|
10
|
+
class NotFoundError < Error; end
|
|
15
11
|
class ServerError < Error; end
|
|
16
|
-
|
|
17
|
-
module Rails
|
|
18
|
-
autoload :Helpers, 'spearly/auth/rails/helpers'
|
|
19
|
-
end
|
|
12
|
+
class ServiceUnavailableError < Error; end
|
|
20
13
|
end
|
|
21
14
|
end
|
data/lib/spearly/cloud/client.rb
CHANGED
|
@@ -7,13 +7,13 @@ module Spearly
|
|
|
7
7
|
@token = token
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def get_sites(params
|
|
10
|
+
def get_sites(params)
|
|
11
11
|
uri = "#{ENV.fetch('SPEARLY_API_URL', nil)}/sites"
|
|
12
12
|
uri_parsed = Addressable::URI.parse(uri).normalize.to_s
|
|
13
13
|
client = Faraday.default_connection
|
|
14
14
|
|
|
15
15
|
res = client.get(uri_parsed,
|
|
16
|
-
params
|
|
16
|
+
params,
|
|
17
17
|
'Accept' => 'application/vnd.spearly.v2+json',
|
|
18
18
|
'Authorization' => @token)
|
|
19
19
|
|
data/lib/spearly/version.rb
CHANGED