addons-api 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/README.md +7 -0
- data/addons-api.gemspec +33 -0
- data/lib/addons-api/client.rb +267 -0
- data/lib/addons-api/version.rb +3 -0
- data/lib/addons-api.rb +6 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a4081270b247ebcecee38930b50eb35c55b6e9232d7af621662500dfd88f172
|
4
|
+
data.tar.gz: cb5b079d9661d102ed5806556554fc8e8907bff70682cabed733343d31dd1088
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46a81fb7b5b76c567c72ecaf9b849c250fa7699cb3e4d4086d0cc14737fc75f1389e8222e20c5e5bb62541f135027750d5697073699b08b641afd5a296561dc3
|
7
|
+
data.tar.gz: a467fc67ee16b66d97ddf5746e48bdbded81f61e68bcf492ab096584c2daa47fe40117227bec72c48f9993dbc294a212d3786e4811cc833f05ac8a87191e3796
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/README.md
ADDED
data/addons-api.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'addons-api/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'addons-api'
|
10
|
+
spec.version = AddonsApi::VERSION
|
11
|
+
spec.authors = ['motymichaely']
|
12
|
+
spec.email = ['moty@crazyantlabs.com']
|
13
|
+
spec.description = 'Ruby HTTP client for the Addons.io API.'
|
14
|
+
spec.summary = 'Ruby HTTP client for the Addons.io API. Learn more on https://addons.io'
|
15
|
+
spec.homepage = 'https://github.com/addonsio/sdk/ruby'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', "~> 2.3"
|
24
|
+
spec.add_development_dependency 'rake', "~> 13.0"
|
25
|
+
spec.add_development_dependency 'yard', "~> 0.9"
|
26
|
+
spec.add_development_dependency 'pry', "~> 0.13"
|
27
|
+
spec.add_development_dependency 'netrc', "~> 0.11"
|
28
|
+
spec.add_development_dependency 'rspec', "~> 3.10"
|
29
|
+
|
30
|
+
spec.add_dependency "oj", "~> 3.14"
|
31
|
+
spec.add_dependency "rest-client", "~> 2.1"
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,267 @@
|
|
1
|
+
require 'addons-api/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'oj'
|
4
|
+
require 'open-uri'
|
5
|
+
|
6
|
+
module AddonsApi
|
7
|
+
class Client
|
8
|
+
|
9
|
+
# Get a Client configured to use Token authentication.
|
10
|
+
def self.connect(options=nil)
|
11
|
+
options = sanitize_options(options)
|
12
|
+
Wrapper.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get a Client configured to use Token authentication.
|
16
|
+
def self.connect_with_token(token, options=nil)
|
17
|
+
options = sanitize_options(options)
|
18
|
+
options[:token] = token
|
19
|
+
Wrapper.new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.sanitize_options(options)
|
23
|
+
return {} if options.nil?
|
24
|
+
|
25
|
+
final_options = {}
|
26
|
+
final_options[:auto_paginate] = options[:auto_paginate] if options[:auto_paginate]
|
27
|
+
final_options[:headers] = options[:headers] if options[:headers]
|
28
|
+
final_options[:timeout] = options[:timeout] if options[:timeout]
|
29
|
+
final_options[:token] = options[:token] if options[:token]
|
30
|
+
final_options[:base_url] = options[:base_url] if options[:base_url]
|
31
|
+
final_options
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Addons.io API wrapper
|
36
|
+
#
|
37
|
+
class Wrapper
|
38
|
+
BASE_URL = %(https://api.addons.io/).freeze
|
39
|
+
API_VERSION = %(2022-12-01).freeze
|
40
|
+
|
41
|
+
HEADERS = {
|
42
|
+
'X-Addons-Api-Version' => API_VERSION,
|
43
|
+
'Accept' => 'application/json',
|
44
|
+
'Content-Type' => 'application/json',
|
45
|
+
'User-Agent' => "addons-api/#{AddonsApi::VERSION}"
|
46
|
+
}.freeze
|
47
|
+
|
48
|
+
OPTIONS = {
|
49
|
+
:auto_paginate => true,
|
50
|
+
:headers => {},
|
51
|
+
:logger => Logger.new(STDERR),
|
52
|
+
:timeout => 10 # seconds
|
53
|
+
}.freeze
|
54
|
+
|
55
|
+
def initialize(options={})
|
56
|
+
@options = OPTIONS.merge(options)
|
57
|
+
|
58
|
+
@token = @options.delete(:token)
|
59
|
+
@base_url = @options.delete(:base_url) || BASE_URL
|
60
|
+
|
61
|
+
@options[:headers] = HEADERS
|
62
|
+
if @token
|
63
|
+
@options[:headers] = @options[:headers].merge({
|
64
|
+
'Authorization' => "Bearer #{@token}",
|
65
|
+
}).merge(@options[:headers])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def request(method, path, body: {}, query: {}, base_url: nil)
|
70
|
+
|
71
|
+
base_url = base_url || @base_url
|
72
|
+
url = "#{base_url.chomp('/')}/#{path}"
|
73
|
+
query_string = URI.encode_www_form(query)
|
74
|
+
|
75
|
+
unless query_string.empty?
|
76
|
+
if url.include?('?')
|
77
|
+
url = url + '&' + query_string
|
78
|
+
else
|
79
|
+
url = url + '?' + query_string
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO: How do we paginate these requests??
|
84
|
+
result = RestClient::Request.execute(
|
85
|
+
method: method,
|
86
|
+
url: url,
|
87
|
+
params: query,
|
88
|
+
payload: Oj.dump(body, mode: :compat),
|
89
|
+
headers: @options[:headers],
|
90
|
+
timeout: @options[:timeout],
|
91
|
+
log: @options[:logger]
|
92
|
+
)
|
93
|
+
Oj.load(result.body, symbol_keys: true)
|
94
|
+
rescue RestClient::BadRequest => e
|
95
|
+
raise
|
96
|
+
end
|
97
|
+
|
98
|
+
# OAuth resource
|
99
|
+
def oauth
|
100
|
+
@oauth_resource ||= OAuth.new(self)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Team resource
|
104
|
+
def team
|
105
|
+
@team_resource ||= Team.new(self)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Add-on services represent add-ons that may be provisioned for apps.
|
110
|
+
class OAuth
|
111
|
+
BASE_PATH = "oauth"
|
112
|
+
|
113
|
+
def initialize(client)
|
114
|
+
@client = client
|
115
|
+
end
|
116
|
+
|
117
|
+
def token
|
118
|
+
@token_resource ||= Token.new(@client)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Token
|
122
|
+
class Token
|
123
|
+
def initialize(client)
|
124
|
+
@client = client
|
125
|
+
end
|
126
|
+
|
127
|
+
def create(client, code)
|
128
|
+
path = "#{BASE_PATH}/token"
|
129
|
+
token = @client.request(:post, path, body: {
|
130
|
+
code: code,
|
131
|
+
grant_type: "authorization_code",
|
132
|
+
client_id: client[:id],
|
133
|
+
client_secret: client[:secret],
|
134
|
+
})
|
135
|
+
token
|
136
|
+
end
|
137
|
+
|
138
|
+
def refresh(client, refresh_token)
|
139
|
+
path = "#{BASE_PATH}/token"
|
140
|
+
token = @client.request(:post, path, body: {
|
141
|
+
refresh_token: refresh_token,
|
142
|
+
grant_type: "refresh_token",
|
143
|
+
client_id: client[:id],
|
144
|
+
client_secret: client[:secret],
|
145
|
+
})
|
146
|
+
token
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class Team
|
152
|
+
BASE_PATH = "teams"
|
153
|
+
|
154
|
+
def initialize(client)
|
155
|
+
@client = client
|
156
|
+
end
|
157
|
+
|
158
|
+
def list()
|
159
|
+
@client.request(:get, "#{BASE_PATH}")
|
160
|
+
end
|
161
|
+
|
162
|
+
def info(team_id)
|
163
|
+
@client.request(:get, "#{BASE_PATH}/#{team_id}")
|
164
|
+
end
|
165
|
+
|
166
|
+
def member
|
167
|
+
@member_resource ||= Member.new(@client)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Add-on resource
|
171
|
+
def addon
|
172
|
+
@addon_resource ||= Addon.new(@client)
|
173
|
+
end
|
174
|
+
|
175
|
+
# A member is a user with access to a team.
|
176
|
+
class Member
|
177
|
+
def initialize(client)
|
178
|
+
@client = client
|
179
|
+
end
|
180
|
+
|
181
|
+
# List members of the team
|
182
|
+
def list(team_id)
|
183
|
+
@client.request(:get, "#{BASE_PATH}/#{team_id}/members")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Add-on
|
188
|
+
class Addon
|
189
|
+
def initialize(client)
|
190
|
+
@client = client
|
191
|
+
end
|
192
|
+
|
193
|
+
def action
|
194
|
+
@action_resource ||= Action.new(@client)
|
195
|
+
end
|
196
|
+
|
197
|
+
def config
|
198
|
+
@config_resource ||= Config.new(@client)
|
199
|
+
end
|
200
|
+
|
201
|
+
def info(team_id, addon_id)
|
202
|
+
@client.request(:get, "#{BASE_PATH}/#{team_id}/addons/#{addon_id}")
|
203
|
+
end
|
204
|
+
|
205
|
+
def info_by_callback_url(callback_url)
|
206
|
+
@client.request(:get, "", base_url: callback_url)
|
207
|
+
end
|
208
|
+
|
209
|
+
# Configuration of an Add-on
|
210
|
+
class Config
|
211
|
+
def initialize(client)
|
212
|
+
@client = client
|
213
|
+
end
|
214
|
+
|
215
|
+
# Get the configuration of an add-on.
|
216
|
+
def list(team_id, addon_id)
|
217
|
+
@client.request(:get, "#{BASE_PATH}/#{team_id}/addons/#{addon_id}/config")
|
218
|
+
end
|
219
|
+
|
220
|
+
# Get the configuration of an add-on with callback URL.
|
221
|
+
def list_with_callback_url(callback_url)
|
222
|
+
@client.request(:get, "config", base_url: callback_url)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Update the configuration of an add-on.
|
226
|
+
def update(team_id, addon_id, body = {})
|
227
|
+
@client.request(:patch, "#{BASE_PATH}/#{team_id}/addons/#{addon_id}/config", body: body)
|
228
|
+
end
|
229
|
+
|
230
|
+
# Update the configuration of an add-on with callback URL.
|
231
|
+
def update_with_callback_url(callback_url, body = {})
|
232
|
+
@client.request(:patch, "config", base_url: callback_url, body: body)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
# Add-on Actions are lifecycle operations for add-on provisioning and deprovisioning.
|
237
|
+
# They allow add-on providers to (de)provision add-ons in the background and then report back when (de)provisioning is complete.
|
238
|
+
class Action
|
239
|
+
def initialize(client)
|
240
|
+
@client = client
|
241
|
+
end
|
242
|
+
|
243
|
+
# Mark an add-on as provisioned.
|
244
|
+
def provision(team_id, addon_id)
|
245
|
+
@client.request(:post, "#{BASE_PATH}/#{team_id}/addons/#{addon_id}/actions/provision")
|
246
|
+
end
|
247
|
+
|
248
|
+
# Mark an add-on as provisioned with callback URL.
|
249
|
+
def provision_with_callback_url(callback_url)
|
250
|
+
@client.request(:post, "actions/provision", base_url: callback_url)
|
251
|
+
end
|
252
|
+
|
253
|
+
# Mark an add-on as deprovisioned.
|
254
|
+
def deprovision(team_id, addon_id)
|
255
|
+
@client.request(:post, "#{BASE_PATH}/#{team_id}/addons/#{addon_id}/actions/deprovision")
|
256
|
+
end
|
257
|
+
|
258
|
+
# Mark an add-on as deprovisioned with callback URL.
|
259
|
+
def deprovision_with_callback_url(callback_url)
|
260
|
+
@client.request(:post, "actions/deprovision", base_url: callback_url)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
data/lib/addons-api.rb
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: addons-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- motymichaely
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: netrc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.11'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: oj
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.14'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.14'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rest-client
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.1'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.1'
|
125
|
+
description: Ruby HTTP client for the Addons.io API.
|
126
|
+
email:
|
127
|
+
- moty@crazyantlabs.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- Gemfile
|
134
|
+
- README.md
|
135
|
+
- addons-api.gemspec
|
136
|
+
- lib/addons-api.rb
|
137
|
+
- lib/addons-api/client.rb
|
138
|
+
- lib/addons-api/version.rb
|
139
|
+
homepage: https://github.com/addonsio/sdk/ruby
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.3.26
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Ruby HTTP client for the Addons.io API. Learn more on https://addons.io
|
162
|
+
test_files: []
|