replicatedvendor 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66ce44f072def3a8306532b2a6ce2e982710b675
4
+ data.tar.gz: 1882812683286bb9eea5ecadfa8cc6efbb68fd8a
5
+ SHA512:
6
+ metadata.gz: 7435f080201126ee900d894600055f8ac1f2a48ded1ff91c86c7f100405c94fab16ca3af4012720fee16ad9513901ad5e74492846ad110f1e18c1cb29107266c
7
+ data.tar.gz: dbc107b18684764a9162e3351fa78530988730bca2853f99694e384424a40434f3830e9a60996fb8cc7cc837401547503301ab6e3a624b25edd9452e2965428a
data/lib/api.rb ADDED
@@ -0,0 +1,55 @@
1
+ require_relative "./client/client.rb"
2
+
3
+ require_relative "./api/apimodule.rb"
4
+
5
+ class VendorApi
6
+ def initialize(api_token = nil)
7
+ @api_token = api_token
8
+ @client = ApiClient.new()
9
+ @client.set_token(@api_token)
10
+ end
11
+
12
+ def app
13
+ return App.new(@client)
14
+ end
15
+
16
+ def apps
17
+
18
+ end
19
+
20
+ def auditlog
21
+
22
+ end
23
+
24
+ def auditlog
25
+
26
+ end
27
+
28
+ def auth
29
+
30
+ end
31
+
32
+ def channel
33
+
34
+ end
35
+
36
+ def license
37
+
38
+ end
39
+
40
+ def licenes
41
+
42
+ end
43
+
44
+ def release
45
+
46
+ end
47
+
48
+ def releases
49
+
50
+ end
51
+
52
+ def team
53
+
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ class ApiModule
2
+ def initialize(client = nil)
3
+ @client = client
4
+ end
5
+ end
6
+
7
+ Dir[File.dirname(__FILE__) + '/**/*.rb'].each {|file| require file }
@@ -0,0 +1,52 @@
1
+ class App < ApiModule
2
+ def initialize(client)
3
+ super(client)
4
+ @ENDPOINT = client.ENDPOINT + "/" + "app"
5
+ end
6
+
7
+ def list_branding(appid)
8
+ endpoint = self.ENDPOINT + "/" + appid + "/branding"
9
+ return self.client.request("GET", endpoint)
10
+ end
11
+
12
+ def create_branding(appid:)
13
+ endpoint = self.ENDPOINT + "/" + appid + "/branding"
14
+ return self.client.request("POST", endpoint)
15
+ end
16
+
17
+ def list_license_fields(appid:)
18
+ endpoint = self.ENDPOINT + "/" + appid + "/licensefield"
19
+ return self.client.request("GET", endpoint)
20
+ end
21
+
22
+ def create_license_field(appid:, default:, hidden:, name:, required:, title:, type:)
23
+ endpoint = self.ENDPOINT + "/" + appid + "/licensefield"
24
+ return self.client.request("POST", endpoint, {
25
+ "default": default,
26
+ "hidden": hidden,
27
+ "name": name,
28
+ "required": required,
29
+ "title": title,
30
+ "type": type,
31
+ })
32
+ end
33
+
34
+ def edit_license_field(appid, license_field_name, default, hidden, title)
35
+ endpoint = self.ENDPOINT + "/" + appid + "/licensefield/" + license_field_name
36
+ return self.client.request("PUT", endpoint, {
37
+ "default": default,
38
+ "hidden": hidden,
39
+ "title": title,
40
+ })
41
+ end
42
+
43
+ def delete_license_field(appid, license_field_name)
44
+ endpoint = self.ENDPOINT + "/" + appid + "/licensefield/" + license_field_name
45
+ return self.client.request("DELETE", endpoint)
46
+ end
47
+
48
+ def list_license(appid)
49
+ endpoint = self.ENDPOINT + "/" + appid + "/licenses"
50
+ return self.client.request("GET", endpoint)
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ class Apps < ApiModule
2
+ def initialize(client)
3
+ super(client)
4
+ @ENDPOINT = client.ENDPOINT + "/" + "app"
5
+ end
6
+
7
+ def list()
8
+ method = "GET"
9
+ return self.client.request(method, self.ENDPOINT)
10
+ end
11
+
12
+ def delete(appid)
13
+ method = "DELETE"
14
+ unless appid.is_a? Integer
15
+ raise "Non integer appid"
16
+ end
17
+ endpoint = self.ENDPOINT + "/" + appid
18
+ return self.client.request(method, endpoint)
19
+ end
20
+
21
+ def delete_branding(appid)
22
+ method = "DELETE"
23
+ unless appid.is_a? Integer
24
+ raise "Non integer appid"
25
+ end
26
+ endpoint = self.ENDPOINT + "/" + appid + "/branding"
27
+ return self.client.request(method, endpoint)
28
+ end
29
+
30
+ def create(name)
31
+ method = "POST"
32
+ unless appid.is_a? String
33
+ raise "Non string app name"
34
+ end
35
+ return self.client.request(method, self.ENDPOINT, {"name" => name})
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ class AuditLog < ApiModule
2
+ def initialize(client)
3
+ super(client)
4
+ end
5
+
6
+ def get_token(targetid)
7
+ endpoint = "auditlogtoken"
8
+ params = {"target_id" => targetid}
9
+ return self.client.request("GET", endpoint, params)
10
+ end
11
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/apiuri.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'uri'
2
+
3
+ class ApiUri
4
+ VENDOR_HOST = "api.replicated.com"
5
+ VENDOR_BASE_PATH = "/vendor/v1"
6
+
7
+ def self.build_uri(module_name, endpoint = nil, params = nil)
8
+ uri_base = "https://" << VENDOR_HOST
9
+ uri = URI(uri_base)
10
+
11
+ path = VENDOR_BASE_PATH << "/" << module_name
12
+ if endpoint
13
+ path = path << "/" << endpoint
14
+ end
15
+ uri.path = path
16
+
17
+ if params
18
+ uri.query = URI.encode_www_form(params)
19
+ end
20
+
21
+ return uri
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "ostruct"
4
+ require "json"
5
+
6
+ class ApiClient
7
+ ENDPOINT = "https://api.replicated.com/vendor/v1"
8
+ VERB_MAP = {
9
+ :get => Net::HTTP::Get,
10
+ :post => Net::HTTP::Post,
11
+ :put => Net::HTTP::Put,
12
+ :delete => Net::HTTP::Delete
13
+ }
14
+
15
+ def initialize(endpoint = ENDPOINT)
16
+ uri = URI.parse(endpoint)
17
+ @http = Net::HTTP.new(uri.host, uri.port)
18
+ end
19
+
20
+ def set_token(api_token)
21
+ @api_token = api_token
22
+ end
23
+
24
+ def request_json(method, path, params)
25
+ response = request(method, path, params)
26
+ body = JSON.parse(response.body)
27
+
28
+ OpenStruct.new(:code => response.code, :body => body)
29
+ rescue JSON::ParserError
30
+ response
31
+ end
32
+
33
+ def request(method, path, params)
34
+ method_sym = method.downcase.to_sym
35
+ case method_sym
36
+ when :get
37
+ full_path = encode_path_params(path, params)
38
+ request = VERB_MAP[method_sym].new(full_path)
39
+ else
40
+ request = VERB_MAP[method_sym].new(path)
41
+ request.set_form_data(params)
42
+ end
43
+
44
+ if @api_token
45
+ request['Authorization'] = @api_token
46
+ end
47
+
48
+ @http.request(request)
49
+ end
50
+
51
+ def encode_path_params(path, params)
52
+ encoded = URI.encode_www_form(params)
53
+ [path, encoded].join("?")
54
+ end
55
+ end
@@ -0,0 +1,13 @@
1
+ class Assert
2
+ def self.int(var)
3
+ unless appid.is_a? Integer
4
+ raise "Expected integer"
5
+ end
6
+ end
7
+
8
+ def self.bool(var)
9
+ unless appid.is_a? Boolean
10
+ raise "Expected boolean"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'replicatedvendor'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['MIT']
5
+ s.summary = "A ruby wrapper for the replicated vendor api"
6
+ s.description = "A ruby wrapper for the replicated vendor api: https://replicated-vendor-api.readme.io/v1.0/reference"
7
+ s.authors = ["Guy Moore", "Daryl Metzler"]
8
+ s.email = 'guy.moore.normal@mgmail.com'
9
+ s.files = %w(replicatedvendor.gemspec)
10
+ s.files += Dir.glob("lib/**/*.rb")
11
+ s.files += Dir.glob("lib/**/**/*.rb")
12
+ s.homepage = 'https://rubygems.org/gems/replicatedvendor'
13
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: replicatedvendor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Guy Moore
8
+ - Daryl Metzler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-10-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: 'A ruby wrapper for the replicated vendor api: https://replicated-vendor-api.readme.io/v1.0/reference'
15
+ email: guy.moore.normal@mgmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/api.rb
21
+ - lib/api/apimodule.rb
22
+ - lib/api/app/app.rb
23
+ - lib/api/apps/apps.rb
24
+ - lib/api/auditlog/auditlog.rb
25
+ - lib/api/auth/auth.rb
26
+ - lib/api/channel/channel.rb
27
+ - lib/api/license/license.rb
28
+ - lib/api/licenses/licenses.rb
29
+ - lib/api/release/release.rb
30
+ - lib/api/releases/releases.rb
31
+ - lib/api/team/team.rb
32
+ - lib/apiuri.rb
33
+ - lib/client/client.rb
34
+ - lib/util/assert.rb
35
+ - replicatedvendor.gemspec
36
+ homepage: https://rubygems.org/gems/replicatedvendor
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.5.2.1
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: A ruby wrapper for the replicated vendor api
60
+ test_files: []