semaphore_client 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ class SemaphoreClient
2
+ class Exceptions
3
+ class AttributeNotAvailable < StandardError; end
4
+ class RequestFailed < StandardError; end
5
+ end
6
+ end
@@ -0,0 +1,58 @@
1
+ require "faraday"
2
+
3
+ class SemaphoreClient
4
+ class HttpClient
5
+ class RouteNotSupported < StandardError; end
6
+
7
+ def initialize(auth_token, api_url, api_version)
8
+ @auth_token = auth_token
9
+ @api_url = api_url
10
+ @api_version = api_version
11
+ end
12
+
13
+ def get(route_elements)
14
+ route = route(route_elements)
15
+
16
+ connection.get(route)
17
+ end
18
+
19
+ def post(route_elements, content = nil)
20
+ route = route(route_elements)
21
+
22
+ if content
23
+ connection.post(route, content)
24
+ else
25
+ connection.post(route)
26
+ end
27
+ end
28
+
29
+ def patch(route_elements, content = nil)
30
+ route = route(route_elements)
31
+
32
+ if content
33
+ connection.patch(route, content)
34
+ else
35
+ connection.patch(route)
36
+ end
37
+ end
38
+
39
+ def delete(route_elements)
40
+ route = route(route_elements)
41
+
42
+ connection.delete(route)
43
+ end
44
+
45
+ private
46
+
47
+ def route(route_elements)
48
+ ["", @api_version, *route_elements].compact.join("/")
49
+ end
50
+
51
+ def connection
52
+ @connection ||= Faraday.new(
53
+ :url => @api_url,
54
+ :headers => { "Authorization" => "Token #{@auth_token}" }
55
+ )
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,61 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class ConfigFile
4
+ attr_reader :id, :url, :shared, :encrypted, :created_at, :updated_at
5
+ attr_accessor :path, :content
6
+
7
+ def self.load(attributes)
8
+ new.load(attributes)
9
+ end
10
+
11
+ def self.create(attributes)
12
+ new.update(attributes)
13
+ end
14
+
15
+ def load(attributes)
16
+ attributes = symbolize_keys(attributes)
17
+
18
+ @id = attributes[:id] if attributes.key?(:id)
19
+ @path = attributes[:path] if attributes.key?(:path)
20
+ @url = attributes[:url] if attributes.key?(:url)
21
+ @content = attributes[:content] if attributes.key?(:content)
22
+ @shared = attributes[:shared] if attributes.key?(:shared)
23
+ @encrypted = attributes[:encrypted] if attributes.key?(:encrypted)
24
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
25
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
26
+
27
+ self
28
+ end
29
+
30
+ def update(attributes)
31
+ attributes = symbolize_keys(attributes)
32
+
33
+ updatable_keys = [:path, :content]
34
+
35
+ if (attributes.keys - updatable_keys).any?
36
+ raise SemaphoreClient::Exceptions::AttributeNotAvailable
37
+ end
38
+
39
+ @path = attributes[:path] if attributes.key?(:path)
40
+ @content = attributes[:content] if attributes.key?(:content)
41
+
42
+ self
43
+ end
44
+
45
+ def serialize
46
+ object_hash = {
47
+ "path" => @path,
48
+ "content" => @content,
49
+ }
50
+
51
+ object_hash.delete_if { |_, value| value.nil? }
52
+ end
53
+
54
+ private
55
+
56
+ def symbolize_keys(hash)
57
+ hash.map { |key, value| [key.to_sym, value] }.to_h
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,61 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class EnvVar
4
+ attr_reader :id, :url, :shared, :encrypted, :created_at, :updated_at
5
+ attr_accessor :name, :content
6
+
7
+ def self.load(attributes)
8
+ new.load(attributes)
9
+ end
10
+
11
+ def self.create(attributes)
12
+ new.update(attributes)
13
+ end
14
+
15
+ def load(attributes)
16
+ attributes = symbolize_keys(attributes)
17
+
18
+ @id = attributes[:id] if attributes.key?(:id)
19
+ @name = attributes[:name] if attributes.key?(:name)
20
+ @url = attributes[:url] if attributes.key?(:url)
21
+ @content = attributes[:content] if attributes.key?(:content)
22
+ @shared = attributes[:shared] if attributes.key?(:shared)
23
+ @encrypted = attributes[:encrypted] if attributes.key?(:encrypted)
24
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
25
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
26
+
27
+ self
28
+ end
29
+
30
+ def update(attributes)
31
+ attributes = symbolize_keys(attributes)
32
+
33
+ updatable_keys = [:name, :content]
34
+
35
+ if (attributes.keys - updatable_keys).any?
36
+ raise SemaphoreClient::Exceptions::AttributeNotAvailable
37
+ end
38
+
39
+ @name = attributes[:name] if attributes.key?(:name)
40
+ @content = attributes[:content] if attributes.key?(:content)
41
+
42
+ self
43
+ end
44
+
45
+ def serialize
46
+ object_hash = {
47
+ "name" => @name,
48
+ "content" => @content,
49
+ }
50
+
51
+ object_hash.delete_if { |_, value| value.nil? }
52
+ end
53
+
54
+ private
55
+
56
+ def symbolize_keys(hash)
57
+ hash.map { |key, value| [key.to_sym, value] }.to_h
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,46 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class Org
4
+ attr_reader :projects_url, :teams_url, :name, :username, :updated_at, :id, :url, :shared_configs_url, :users_url, :created_at
5
+
6
+ def self.load(attributes)
7
+ new.load(attributes)
8
+ end
9
+
10
+ def self.create(attributes)
11
+ new.update(attributes)
12
+ end
13
+
14
+ def load(attributes)
15
+ attributes = symbolize_keys(attributes)
16
+
17
+ @projects_url = attributes[:projects_url] if attributes.key?(:projects_url)
18
+ @teams_url = attributes[:teams_url] if attributes.key?(:teams_url)
19
+ @name = attributes[:name] if attributes.key?(:name)
20
+ @username = attributes[:username] if attributes.key?(:username)
21
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
22
+ @id = attributes[:id] if attributes.key?(:id)
23
+ @url = attributes[:url] if attributes.key?(:url)
24
+ @shared_configs_url = attributes[:shared_configs_url] if attributes.key?(:shared_configs_url)
25
+ @users_url = attributes[:users_url] if attributes.key?(:users_url)
26
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
27
+
28
+ self
29
+ end
30
+
31
+ def update(attributes)
32
+ self
33
+ end
34
+
35
+ def serialize
36
+ {}
37
+ end
38
+
39
+ private
40
+
41
+ def symbolize_keys(hash)
42
+ hash.map { |key, value| [key.to_sym, value] }.to_h
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class Project
4
+ attr_reader :id, :name, :users_url, :shared_configs_url, :env_vars_url, :config_files_url, :updated_at, :created_at
5
+
6
+ def self.load(attributes)
7
+ new.load(attributes)
8
+ end
9
+
10
+ def self.create(attributes)
11
+ new.update(attributes)
12
+ end
13
+
14
+ def load(attributes)
15
+ attributes = symbolize_keys(attributes)
16
+
17
+ @id = attributes[:id] if attributes.key?(:id)
18
+ @name = attributes[:name] if attributes.key?(:name)
19
+ @users_url = attributes[:users_url] if attributes.key?(:users_url)
20
+ @shared_configs_url = attributes[:shared_configs_url] if attributes.key?(:shared_configs_url)
21
+ @env_vars_url = attributes[:env_vars_url] if attributes.key?(:env_vars_url)
22
+ @config_files_url = attributes[:config_files_url] if attributes.key?(:config_files_url)
23
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
24
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
25
+
26
+ self
27
+ end
28
+
29
+ def update(attributes)
30
+ self
31
+ end
32
+
33
+ def serialize
34
+ {}
35
+ end
36
+
37
+ private
38
+
39
+ def symbolize_keys(hash)
40
+ hash.map { |key, value| [key.to_sym, value] }.to_h
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,63 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class SharedConfig
4
+ attr_reader :projects_url, :teams_url, :config_files_url, :updated_at, :env_vars_url, :id, :url, :created_at
5
+ attr_accessor :name, :description
6
+
7
+ def self.load(attributes)
8
+ new.load(attributes)
9
+ end
10
+
11
+ def self.create(attributes)
12
+ new.update(attributes)
13
+ end
14
+
15
+ def load(attributes)
16
+ attributes = symbolize_keys(attributes)
17
+
18
+ @description = attributes[:description] if attributes.key?(:description)
19
+ @projects_url = attributes[:projects_url] if attributes.key?(:projects_url)
20
+ @teams_url = attributes[:teams_url] if attributes.key?(:teams_url)
21
+ @name = attributes[:name] if attributes.key?(:name)
22
+ @config_files_url = attributes[:config_files_url] if attributes.key?(:config_files_url)
23
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
24
+ @env_vars_url = attributes[:env_vars_url] if attributes.key?(:env_vars_url)
25
+ @id = attributes[:id] if attributes.key?(:id)
26
+ @url = attributes[:url] if attributes.key?(:url)
27
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
28
+
29
+ self
30
+ end
31
+
32
+ def update(attributes)
33
+ attributes = symbolize_keys(attributes)
34
+
35
+ updatable_keys = [:name, :description]
36
+
37
+ if (attributes.keys - updatable_keys).any?
38
+ raise SemaphoreClient::Exceptions::AttributeNotAvailable
39
+ end
40
+
41
+ @name = attributes[:name] if attributes.key?(:name)
42
+ @description = attributes[:description] if attributes.key?(:description)
43
+
44
+ self
45
+ end
46
+
47
+ def serialize
48
+ object_hash = {
49
+ "name" => @name,
50
+ "description" => @description,
51
+ }
52
+
53
+ object_hash.delete_if { |_, value| value.nil? }
54
+ end
55
+
56
+ private
57
+
58
+ def symbolize_keys(hash)
59
+ hash.map { |key, value| [key.to_sym, value] }.to_h
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,65 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class Team
4
+ attr_reader :projects_url, :updated_at, :id, :url, :shared_configs_url, :users_url, :created_at
5
+ attr_accessor :name, :permission, :description
6
+
7
+ def self.load(attributes)
8
+ new.load(attributes)
9
+ end
10
+
11
+ def self.create(attributes)
12
+ new.update(attributes)
13
+ end
14
+
15
+ def load(attributes)
16
+ attributes = symbolize_keys(attributes)
17
+
18
+ @description = attributes[:description] if attributes.key?(:description)
19
+ @projects_url = attributes[:projects_url] if attributes.key?(:projects_url)
20
+ @permission = attributes[:permission] if attributes.key?(:permission)
21
+ @name = attributes[:name] if attributes.key?(:name)
22
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
23
+ @id = attributes[:id] if attributes.key?(:id)
24
+ @url = attributes[:url] if attributes.key?(:url)
25
+ @shared_configs_url = attributes[:shared_configs_url] if attributes.key?(:shared_configs_url)
26
+ @users_url = attributes[:users_url] if attributes.key?(:users_url)
27
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
28
+
29
+ self
30
+ end
31
+
32
+ def update(attributes)
33
+ attributes = symbolize_keys(attributes)
34
+
35
+ updatable_keys = [:name, :permission, :description]
36
+
37
+ if (attributes.keys - updatable_keys).any?
38
+ raise SemaphoreClient::Exceptions::AttributeNotAvailable
39
+ end
40
+
41
+ @name = attributes[:name] if attributes.key?(:name)
42
+ @permission = attributes[:permission] if attributes.key?(:permission)
43
+ @description = attributes[:description] if attributes.key?(:description)
44
+
45
+ self
46
+ end
47
+
48
+ def serialize
49
+ object_hash = {
50
+ "name" => @name,
51
+ "permission" => @permission,
52
+ "description" => @description,
53
+ }
54
+
55
+ object_hash.delete_if { |_, value| value.nil? }
56
+ end
57
+
58
+ private
59
+
60
+ def symbolize_keys(hash)
61
+ hash.map { |key, value| [key.to_sym, value] }.to_h
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,41 @@
1
+ class SemaphoreClient
2
+ module Model
3
+ class User
4
+ attr_reader :uid, :username, :name, :created_at, :updated_at
5
+
6
+ def self.load(attributes)
7
+ new.load(attributes)
8
+ end
9
+
10
+ def self.create(attributes)
11
+ new.update(attributes)
12
+ end
13
+
14
+ def load(attributes)
15
+ attributes = symbolize_keys(attributes)
16
+
17
+ @uid = attributes[:uid] if attributes.key?(:uid)
18
+ @username = attributes[:username] if attributes.key?(:username)
19
+ @name = attributes[:name] if attributes.key?(:name)
20
+ @created_at = attributes[:created_at] if attributes.key?(:created_at)
21
+ @updated_at = attributes[:updated_at] if attributes.key?(:updated_at)
22
+
23
+ self
24
+ end
25
+
26
+ def update(attributes)
27
+ self
28
+ end
29
+
30
+ def serialize
31
+ {}
32
+ end
33
+
34
+ private
35
+
36
+ def symbolize_keys(hash)
37
+ hash.map { |key, value| [key.to_sym, value] }.to_h
38
+ end
39
+ end
40
+ end
41
+ end