spearly-sdk-ruby 0.3.2 → 0.7.0

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: ff4e69930eb91c2c598d261ecf89ba3054ae06781adcd1b5a65220df547aed41
4
- data.tar.gz: 3d7aa5463bb510214093c434ef2360de11af132cdfb2f9fbc092037b23463711
3
+ metadata.gz: b191a5c6747aa61591ac0814ab291186952f531e4c57cacea840a20c3cc35765
4
+ data.tar.gz: 15761f6518078b18ca44e6291d13decee06b9e25f2fe929e83ab047519a75288
5
5
  SHA512:
6
- metadata.gz: d668c71f640036c5e34a0a7fef4f2420c5ddfa0503e07930c0e9e114cafb342d4923fd499d58e4354895210dc46f10cdaf8950c140efa2cae2a471b64e5b783e
7
- data.tar.gz: f3d0eba2bd731c73771d0cae35e0ecc0ace751336f28ea023cc001f1a4ff7ce87254c5fabc3497954aa02b5fd7619df67c9f39448a31c12e143b11eea31809d3
6
+ metadata.gz: 1d1b10c84917d54971d20ae6484160855f782876a3286fb8b2c63136e61565e096b0e65bf8f11d09d7a6a417bd4a0a565398acfcabfb1eafe325caccce73a23e
7
+ data.tar.gz: 71566f9e3973b6e42872ab7078ec70a8baeeb8732e2b4ecb65209f22e438ed811f45cd4064f2256e2031d24496e438a000b6ce30502a9c9d01ac3e002eda9986
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
1
+ .bundle
11
2
  .rspec_status
3
+ .ruby-version
4
+ .yardoc
5
+ _yardoc/
6
+ coverage/
7
+ doc/
8
+ Gemfile.local
9
+ Gemfile.lock
10
+ pkg/
11
+ spec/reports/
12
+ tmp/
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## [0.7.0] - 2022-01-31
2
+
3
+ - `Spearly::Cloud::Client#get_site`
4
+ - `Spearly::Cloud::Client#get_sites`
5
+
6
+ ## [0.6.0] - 2022-01-20
7
+
8
+ - `Spearly::Auth::Client#get_team_features`
9
+
10
+ ## [0.5.0] - 2021-12-13
11
+
12
+ - `Spearly::Auth::Client`
13
+
14
+ ## [0.4.0] - 2021-09-13
15
+
16
+ - Error handling improvements
17
+
1
18
  ## [0.3.2] - 2021-09-13
2
19
 
3
20
  - Use the new `Spearly API v2`
@@ -0,0 +1,145 @@
1
+ module Spearly
2
+ module Auth
3
+ class Client
4
+ def initialize(token)
5
+ @token = token
6
+ end
7
+
8
+ def create_team(params)
9
+ uri = "#{ENV['SPEARLY_API_URL']}/teams"
10
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
11
+ client = Faraday.default_connection
12
+
13
+ res = client.post(uri_parsed,
14
+ params.as_json,
15
+ 'Accept' => 'application/vnd.spearly.v2+json',
16
+ 'Authorization' => @token)
17
+
18
+ if res.status == 201
19
+ JSON.parse(res.body)['data']
20
+ else
21
+ {}
22
+ end
23
+ end
24
+
25
+ def get_team(team_id)
26
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}"
27
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
28
+ client = Faraday.default_connection
29
+
30
+ res = client.get(uri_parsed,
31
+ nil,
32
+ 'Accept' => 'application/vnd.spearly.v2+json',
33
+ 'Authorization' => @token)
34
+
35
+ if res.status == 200
36
+ JSON.parse(res.body)['data']
37
+ else
38
+ {}
39
+ end
40
+ end
41
+
42
+ def get_teams(params = {})
43
+ uri = "#{ENV['SPEARLY_API_URL']}/teams"
44
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
45
+ client = Faraday.default_connection
46
+
47
+ res = client.get(uri_parsed,
48
+ params.as_json,
49
+ 'Accept' => 'application/vnd.spearly.v2+json',
50
+ 'Authorization' => @token)
51
+
52
+ if res.status == 200
53
+ JSON.parse(res.body)['data']
54
+ else
55
+ []
56
+ end
57
+ end
58
+
59
+ def update_team(team_id, params)
60
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}"
61
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
62
+ client = Faraday.default_connection
63
+
64
+ res = client.put(uri_parsed,
65
+ params.as_json,
66
+ 'Accept' => 'application/vnd.spearly.v2+json',
67
+ 'Authorization' => @token)
68
+
69
+ if res.status == 200
70
+ JSON.parse(res.body)['data']
71
+ else
72
+ nil
73
+ end
74
+ end
75
+
76
+ def regenerate_team_api_access_token(team_id)
77
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/regenerate_api_access_token"
78
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
79
+ client = Faraday.default_connection
80
+
81
+ res = client.post(uri_parsed,
82
+ nil,
83
+ 'Accept' => 'application/vnd.spearly.v2+json',
84
+ 'Authorization' => @token)
85
+
86
+ if res.status == 200
87
+ JSON.parse(res.body)['data']
88
+ else
89
+ nil
90
+ end
91
+ end
92
+
93
+ def invite_user_to_team(team_id, params)
94
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/invite"
95
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
96
+ client = Faraday.default_connection
97
+
98
+ res = client.post(uri_parsed,
99
+ params.as_json,
100
+ 'Accept' => 'application/vnd.spearly.v2+json',
101
+ 'Authorization' => @token)
102
+
103
+ if res.status == 201
104
+ JSON.parse(res.body)['data']
105
+ else
106
+ nil
107
+ end
108
+ end
109
+
110
+ def get_team_members(team_id)
111
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/members"
112
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
113
+ client = Faraday.default_connection
114
+
115
+ res = client.get(uri_parsed,
116
+ nil,
117
+ 'Accept' => 'application/vnd.spearly.v2+json',
118
+ 'Authorization' => @token)
119
+
120
+ if res.status == 200
121
+ JSON.parse(res.body)['data']
122
+ else
123
+ []
124
+ end
125
+ end
126
+
127
+ def get_team_features(team_id)
128
+ uri = "#{ENV['SPEARLY_API_URL']}/teams/#{team_id}/features"
129
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
130
+ client = Faraday.default_connection
131
+
132
+ res = client.get(uri_parsed,
133
+ nil,
134
+ 'Accept' => 'application/vnd.spearly.v2+json',
135
+ 'Authorization' => @token)
136
+
137
+ if res.status == 200
138
+ JSON.parse(res.body)['data']
139
+ else
140
+ {}
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -5,7 +5,7 @@ module Spearly
5
5
  module Rails
6
6
  module Helpers
7
7
  def spearly_authorize!
8
- spearly_token
8
+ raise Spearly::Auth::AuthorizationError unless spearly_token
9
9
  end
10
10
 
11
11
  private
@@ -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
@@ -1,8 +1,5 @@
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
5
  class Team
@@ -26,12 +26,7 @@ module Spearly
26
26
  'Accept' => 'application/vnd.spearly.v2+json',
27
27
  'Authorization' => @token)
28
28
 
29
- case res.status
30
- when 401
31
- raise Spearly::Auth::AuthorizationError
32
- when 500
33
- raise Spearly::Auth::ServerError
34
- end
29
+ return unless res.status == 200
35
30
 
36
31
  @data = JSON.parse(res.body)
37
32
  end
@@ -26,12 +26,7 @@ module Spearly
26
26
  'Accept' => 'application/vnd.spearly.v2+json',
27
27
  'Authorization' => @token)
28
28
 
29
- case res.status
30
- when 401
31
- raise Spearly::Auth::AuthorizationError
32
- when 500
33
- raise Spearly::Auth::ServerError
34
- end
29
+ return unless res.status == 200
35
30
 
36
31
  @data = JSON.parse(res.body)['data']
37
32
  end
@@ -46,12 +41,7 @@ module Spearly
46
41
  'Accept' => 'application/vnd.spearly.v2+json',
47
42
  'Authorization' => @token)
48
43
 
49
- case res.status
50
- when 401
51
- raise Spearly::Auth::AuthorizationError
52
- when 500
53
- raise Spearly::Auth::ServerError
54
- end
44
+ return [] unless res.status == 200
55
45
 
56
46
  team_hashes = JSON.parse(res.body)['data']
57
47
 
data/lib/spearly/auth.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'auth/authorizer'
4
+ require_relative 'auth/client'
4
5
  require_relative 'auth/engine'
5
6
  require_relative 'auth/oauth_user'
6
7
  require_relative 'auth/team'
@@ -0,0 +1,43 @@
1
+ module Spearly
2
+ module Cloud
3
+ class Client
4
+ def initialize(token)
5
+ @token = token
6
+ end
7
+
8
+ def get_sites(params = {})
9
+ uri = "#{ENV['SPEARLY_API_URL']}/sites"
10
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
11
+ client = Faraday.default_connection
12
+
13
+ res = client.get(uri_parsed,
14
+ params.as_json,
15
+ 'Accept' => 'application/vnd.spearly.v2+json',
16
+ 'Authorization' => @token)
17
+
18
+ if res.status == 200
19
+ JSON.parse(res.body)['data']
20
+ else
21
+ []
22
+ end
23
+ end
24
+
25
+ def get_site(site_id)
26
+ uri = "#{ENV['SPEARLY_API_URL']}/sites/#{site_id}"
27
+ uri_parsed = Addressable::URI.parse(uri).normalize.to_s
28
+ client = Faraday.default_connection
29
+
30
+ res = client.get(uri_parsed,
31
+ nil,
32
+ 'Accept' => 'application/vnd.spearly.v2+json',
33
+ 'Authorization' => @token)
34
+
35
+ if res.status == 200
36
+ JSON.parse(res.body)['data']
37
+ else
38
+ {}
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cloud/client'
4
+
5
+ module Spearly
6
+ module Cloud
7
+ class Error < StandardError; end
8
+ class AuthorizationError < Error; end
9
+ class ServerError < Error; end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spearly
4
- VERSION = '0.3.2'
4
+ VERSION = '0.7.0'
5
5
  end
data/lib/spearly.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'spearly/auth'
4
+ require_relative 'spearly/cloud'
4
5
  require_relative 'spearly/version'
5
6
 
6
7
  module 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.3.2
4
+ version: 0.7.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-09-13 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -142,7 +142,6 @@ files:
142
142
  - ".rubocop.yml"
143
143
  - CHANGELOG.md
144
144
  - Gemfile
145
- - Gemfile.lock
146
145
  - README.md
147
146
  - Rakefile
148
147
  - bin/console
@@ -151,12 +150,15 @@ files:
151
150
  - lib/spearly.rb
152
151
  - lib/spearly/auth.rb
153
152
  - lib/spearly/auth/authorizer.rb
153
+ - lib/spearly/auth/client.rb
154
154
  - lib/spearly/auth/engine.rb
155
155
  - lib/spearly/auth/oauth_user.rb
156
156
  - lib/spearly/auth/rails/helpers.rb
157
157
  - lib/spearly/auth/team.rb
158
158
  - lib/spearly/auth/token.rb
159
159
  - lib/spearly/auth/user.rb
160
+ - lib/spearly/cloud.rb
161
+ - lib/spearly/cloud/client.rb
160
162
  - lib/spearly/version.rb
161
163
  - spearly.gemspec
162
164
  - spec/spearly_spec.rb
@@ -166,7 +168,7 @@ licenses: []
166
168
  metadata:
167
169
  homepage_uri: https://github.com/unimal-jp/spearly-sdk-ruby
168
170
  source_code_uri: https://github.com/unimal-jp/spearly-sdk-ruby
169
- changelog_uri: https://github.com/unimal-jp/spearly-sdk-ruby/blob/v0.3.2/CHANGELOG.md
171
+ changelog_uri: https://github.com/unimal-jp/spearly-sdk-ruby/blob/v0.7.0/CHANGELOG.md
170
172
  post_install_message:
171
173
  rdoc_options: []
172
174
  require_paths:
data/Gemfile.lock DELETED
@@ -1,100 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- spearly-sdk-ruby (0.3.1)
5
- addressable (~> 2.3)
6
- faraday (>= 0.17.4, < 2.0)
7
- rake (~> 13.0)
8
- signet (~> 0.15)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- addressable (2.8.0)
14
- public_suffix (>= 2.0.2, < 5.0)
15
- ast (2.4.2)
16
- coderay (1.1.3)
17
- diff-lcs (1.4.4)
18
- faraday (1.7.1)
19
- faraday-em_http (~> 1.0)
20
- faraday-em_synchrony (~> 1.0)
21
- faraday-excon (~> 1.1)
22
- faraday-httpclient (~> 1.0.1)
23
- faraday-net_http (~> 1.0)
24
- faraday-net_http_persistent (~> 1.1)
25
- faraday-patron (~> 1.0)
26
- faraday-rack (~> 1.0)
27
- multipart-post (>= 1.2, < 3)
28
- ruby2_keywords (>= 0.0.4)
29
- faraday-em_http (1.0.0)
30
- faraday-em_synchrony (1.0.0)
31
- faraday-excon (1.1.0)
32
- faraday-httpclient (1.0.1)
33
- faraday-net_http (1.0.1)
34
- faraday-net_http_persistent (1.2.0)
35
- faraday-patron (1.0.0)
36
- faraday-rack (1.0.0)
37
- jwt (2.2.3)
38
- method_source (1.0.0)
39
- multi_json (1.15.0)
40
- multipart-post (2.1.1)
41
- parallel (1.20.1)
42
- parser (3.0.1.1)
43
- ast (~> 2.4.1)
44
- pry (0.13.1)
45
- coderay (~> 1.1)
46
- method_source (~> 1.0)
47
- public_suffix (4.0.6)
48
- rainbow (3.0.0)
49
- rake (13.0.6)
50
- regexp_parser (2.1.1)
51
- rexml (3.2.5)
52
- rspec (3.10.0)
53
- rspec-core (~> 3.10.0)
54
- rspec-expectations (~> 3.10.0)
55
- rspec-mocks (~> 3.10.0)
56
- rspec-core (3.10.1)
57
- rspec-support (~> 3.10.0)
58
- rspec-expectations (3.10.1)
59
- diff-lcs (>= 1.2.0, < 2.0)
60
- rspec-support (~> 3.10.0)
61
- rspec-mocks (3.10.2)
62
- diff-lcs (>= 1.2.0, < 2.0)
63
- rspec-support (~> 3.10.0)
64
- rspec-support (3.10.2)
65
- rubocop (1.15.0)
66
- parallel (~> 1.10)
67
- parser (>= 3.0.0.0)
68
- rainbow (>= 2.2.2, < 4.0)
69
- regexp_parser (>= 1.8, < 3.0)
70
- rexml
71
- rubocop-ast (>= 1.5.0, < 2.0)
72
- ruby-progressbar (~> 1.7)
73
- unicode-display_width (>= 1.4.0, < 3.0)
74
- rubocop-ast (1.5.0)
75
- parser (>= 3.0.1.1)
76
- rubocop-rspec (2.3.0)
77
- rubocop (~> 1.0)
78
- rubocop-ast (>= 1.1.0)
79
- ruby-progressbar (1.11.0)
80
- ruby2_keywords (0.0.5)
81
- signet (0.16.0)
82
- addressable (~> 2.8)
83
- faraday (>= 0.17.3, < 2.0)
84
- jwt (>= 1.5, < 3.0)
85
- multi_json (~> 1.10)
86
- unicode-display_width (2.0.0)
87
-
88
- PLATFORMS
89
- x86_64-darwin-20
90
- x86_64-linux
91
-
92
- DEPENDENCIES
93
- pry (~> 0.13.1)
94
- rspec (~> 3.0)
95
- rubocop (~> 1.15)
96
- rubocop-rspec (~> 2.3)
97
- spearly-sdk-ruby!
98
-
99
- BUNDLED WITH
100
- 2.2.15