spearly-sdk-ruby 0.2.4 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67814c681befa771a269e339b41cd446c68bdc242dd3a61900c3a1f507165167
4
- data.tar.gz: ae7c1f34d649ebc34c0bd8ec4d1e468542c5c7c13bbf351fc0c9e3c294010996
3
+ metadata.gz: ff4e69930eb91c2c598d261ecf89ba3054ae06781adcd1b5a65220df547aed41
4
+ data.tar.gz: 3d7aa5463bb510214093c434ef2360de11af132cdfb2f9fbc092037b23463711
5
5
  SHA512:
6
- metadata.gz: b5e943c498662cd93bcaaa2a5db68e5f16129a337860f8f35637a3d4056bcda54684a5f542201017ac1642ca9dab50549a77324d5d1c7c0354178eaa92b9c88c
7
- data.tar.gz: a7fff0b9890ee300d37a958cfd714057d5684dbd534fb05e7a8cd24b6f7f59c1e45fd084ab64a457da3fcbf5c2a51c437e7d11704174db4fb00b1db30040e855
6
+ metadata.gz: d668c71f640036c5e34a0a7fef4f2420c5ddfa0503e07930c0e9e114cafb342d4923fd499d58e4354895210dc46f10cdaf8950c140efa2cae2a471b64e5b783e
7
+ data.tar.gz: f3d0eba2bd731c73771d0cae35e0ecc0ace751336f28ea023cc001f1a4ff7ce87254c5fabc3497954aa02b5fd7619df67c9f39448a31c12e143b11eea31809d3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.3.2] - 2021-09-13
2
+
3
+ - Use the new `Spearly API v2`
4
+ - Refactors parsing `JSON` data
5
+
6
+ ## [0.2.4] - 2021-07-16
7
+
8
+ - Rescue `Signet::AuthorizationError` on `Spearly::Auth::Authorizer`
9
+
1
10
  ## [0.2.3] - 2021-06-18
2
11
 
3
12
  - Raise `Spearly::Auth::AuthorizationError` and `Spearly::Auth::ServerError` from `Spearly::Auth::User` and `Spearly::Auth::Token`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spearly-sdk-ruby (0.2.3)
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.7.0)
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.4.2)
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.1.0)
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.3)
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.4)
75
- signet (0.15.0)
76
- addressable (~> 2.3)
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
@@ -20,29 +20,42 @@ Or install it manually:
20
20
  gem install spearly-sdk-ruby
21
21
  ```
22
22
 
23
- ## Publish
23
+ ## Contribute
24
24
  ### Increment version
25
25
  ```sh
26
26
  vim lib/spearly/version.rb
27
27
  ```
28
28
 
29
- ### Build
29
+ ### Update CHANGELOG
30
30
  ```sh
31
- rake build
31
+ vim CHANGELOG.md
32
32
  ```
33
33
 
34
- ### Push to RubyGems
34
+ ### Update Gemfile.lock
35
35
  ```sh
36
- new_version=$(ruby -e "require 'spearly/version'; puts Spearly::VERSION")
37
-
38
- gem push pkg/spearly-sdk-ruby-$new_version.gem
36
+ bundle install
39
37
  ```
40
38
 
41
- ## Contribute
42
39
  ### New version commit
43
40
  ```sh
44
- new_version=$(ruby -e "require 'spearly/version'; puts Spearly::VERSION")
41
+ new_version=$(ruby -e "require './lib/spearly/version'; puts Spearly::VERSION")
45
42
 
46
43
  git commit -m "v$new_version"
47
44
  git tag -a v$new_version -m "Release $new_version"
45
+
46
+ git push origin main
47
+ git push origin --tags
48
+ ```
49
+
50
+ ## Publish
51
+ ### Build
52
+ ```sh
53
+ rake build
54
+ ```
55
+
56
+ ### Push to RubyGems
57
+ ```sh
58
+ new_version=$(ruby -e "require './lib/spearly/version'; puts Spearly::VERSION")
59
+
60
+ gem push pkg/spearly-sdk-ruby-$new_version.gem
48
61
  ```
@@ -19,13 +19,19 @@ module Spearly
19
19
  private
20
20
 
21
21
  def initialize_client
22
+ Faraday.default_connection_options = {
23
+ headers: {
24
+ 'Accept' => 'application/vnd.spearly.v2+json'
25
+ }
26
+ }
27
+
22
28
  client = ::Signet::OAuth2::Client.new
23
29
  client.client_id = @params[:client_id] || @params['client_id']
24
30
  client.client_secret = @params[:client_secret] || @params['client_secret']
25
31
  client.code = @params[:code] || @params['code']
26
32
  client.grant_type = @params[:grant_type] || @params['grant_type']
27
- client.authorization_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth/authorize"
28
- client.token_credential_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth/token"
33
+ client.authorization_uri = "#{ENV['SPEARLY_API_URL']}/oauth/authorize"
34
+ client.token_credential_uri = "#{ENV['SPEARLY_API_URL']}/oauth/token"
29
35
  client.redirect_uri = @params[:redirect_uri] || @params['redirect_uri']
30
36
 
31
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 :attributes
9
+ attr_reader :data
10
10
 
11
- def initialize(attributes)
12
- @attributes = attributes
11
+ def initialize(data)
12
+ @data = data
13
13
  end
14
14
 
15
15
  def method_missing(name, *_args)
16
- @attributes[name.to_s]
16
+ @data[name.to_s]
17
17
  end
18
18
 
19
19
  def to_json(*_args)
20
- @attributes.to_json
20
+ @data.to_json
21
21
  end
22
22
 
23
23
  def as_json
24
- @attributes.as_json
24
+ @data.as_json
25
25
  end
26
26
  end
27
27
  end
@@ -5,7 +5,7 @@ module Spearly
5
5
  module Rails
6
6
  module Helpers
7
7
  def spearly_authorize!
8
- raise Spearly::Auth::AuthorizationError unless spearly_token
8
+ spearly_token
9
9
  end
10
10
 
11
11
  private
@@ -13,16 +13,18 @@ module Spearly
13
13
  def spearly_token
14
14
  @spearly_token ||= begin
15
15
  token = Spearly::Auth::Token.new(request.authorization)
16
+ token.info
16
17
 
17
- token.info ? token : nil
18
+ token
18
19
  end
19
20
  end
20
21
 
21
22
  def spearly_user
22
23
  @spearly_user ||= begin
23
24
  user = Spearly::Auth::User.new(request.authorization)
25
+ user.find
24
26
 
25
- user.find ? user : nil
27
+ user
26
28
  end
27
29
  end
28
30
  end
@@ -6,22 +6,22 @@ require 'faraday'
6
6
  module Spearly
7
7
  module Auth
8
8
  class Team
9
- attr_reader :attributes
9
+ attr_reader :data
10
10
 
11
- def initialize(attributes)
12
- @attributes = attributes
11
+ def initialize(data)
12
+ @data = data
13
13
  end
14
14
 
15
15
  def method_missing(name, *_args)
16
- @attributes[name.to_s]
16
+ @data[name.to_s]
17
17
  end
18
18
 
19
19
  def to_json(*_args)
20
- @attributes.to_json
20
+ @data.to_json
21
21
  end
22
22
 
23
23
  def as_json
24
- @attributes.as_json
24
+ @data.as_json
25
25
  end
26
26
  end
27
27
  end
@@ -6,32 +6,38 @@ require 'faraday'
6
6
  module Spearly
7
7
  module Auth
8
8
  class Token
9
- attr_reader :attributes, :token
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
- @attributes[name.to_s]
16
+ @data[name.to_s]
17
17
  end
18
18
 
19
19
  def info
20
- token_info_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth/token/info"
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
- return unless res.status == 200
29
+ case res.status
30
+ when 401
31
+ raise Spearly::Auth::AuthorizationError
32
+ when 500
33
+ raise Spearly::Auth::ServerError
34
+ end
29
35
 
30
- @attributes = JSON.parse(res.body)
36
+ @data = JSON.parse(res.body)
31
37
  end
32
38
 
33
39
  def revoke(params)
34
- token_revoke_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth/revoke"
40
+ token_revoke_uri = "#{ENV['SPEARLY_API_URL']}/oauth/revoke"
35
41
  url = Addressable::URI.parse(token_revoke_uri).normalize.to_s
36
42
  client = Faraday.default_connection
37
43
 
@@ -46,11 +52,11 @@ module Spearly
46
52
  end
47
53
 
48
54
  def to_json(*_args)
49
- @attributes.to_json
55
+ @data.to_json
50
56
  end
51
57
 
52
58
  def as_json
53
- @attributes.as_json
59
+ @data.as_json
54
60
  end
55
61
  end
56
62
  end
@@ -6,72 +6,66 @@ require 'faraday'
6
6
  module Spearly
7
7
  module Auth
8
8
  class User
9
- attr_reader :attributes
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
- @attributes[name.to_s]
16
+ @data[name.to_s]
17
17
  end
18
18
 
19
19
  def find
20
- user_profile_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/oauth/profile"
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
- return unless res.status == 200
29
+ case res.status
30
+ when 401
31
+ raise Spearly::Auth::AuthorizationError
32
+ when 500
33
+ raise Spearly::Auth::ServerError
34
+ end
29
35
 
30
- @attributes = JSON.parse(res.body)['user']
36
+ @data = JSON.parse(res.body)['data']
31
37
  end
32
38
 
33
39
  def teams
34
- teams_uri = "#{ENV['SPEARLY_AUTH_API_URL']}/api/v1/teams"
40
+ teams_uri = "#{ENV['SPEARLY_API_URL']}/teams"
35
41
  url = Addressable::URI.parse(teams_uri).normalize.to_s
36
42
  client = Faraday.default_connection
37
43
 
38
44
  res = client.get(url,
39
45
  nil,
46
+ 'Accept' => 'application/vnd.spearly.v2+json',
40
47
  'Authorization' => @token)
41
48
 
42
- return [] unless res.status == 200
49
+ case res.status
50
+ when 401
51
+ raise Spearly::Auth::AuthorizationError
52
+ when 500
53
+ raise Spearly::Auth::ServerError
54
+ end
43
55
 
44
- team_hashes = JSON.parse(res.body)['teams']
56
+ team_hashes = JSON.parse(res.body)['data']
45
57
 
46
58
  team_hashes.map do |team_hash|
47
59
  Spearly::Auth::Team.new(team_hash)
48
60
  end
49
61
  end
50
62
 
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
63
  def to_json(*_args)
70
- @attributes.to_json
64
+ @data.to_json
71
65
  end
72
66
 
73
67
  def as_json
74
- @attributes.as_json
68
+ @data.as_json
75
69
  end
76
70
  end
77
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spearly
4
- VERSION = '0.2.4'
4
+ VERSION = '0.3.2'
5
5
  end
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'] = "https://github.com/unimal-jp/spearly-sdk-ruby/blob/#{Spearly::VERSION}/CHANGELOG.md"
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.2.4
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spearly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
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/blob/0.2.4/CHANGELOG.md
169
+ changelog_uri: https://github.com/unimal-jp/spearly-sdk-ruby/blob/v0.3.2/CHANGELOG.md
170
170
  post_install_message:
171
171
  rdoc_options: []
172
172
  require_paths: