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,49 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class Org
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list
9
+ list!
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def get(id)
14
+ get!(id)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def list!
19
+ response = @http_client.get([:orgs])
20
+
21
+ assert_response_status(response, 200)
22
+
23
+ content = JSON.parse(response.body)
24
+
25
+ content.map do |entity|
26
+ SemaphoreClient::Model::Org.load(entity)
27
+ end
28
+ end
29
+
30
+ def get!(id)
31
+ response = @http_client.get([:orgs, id])
32
+
33
+ assert_response_status(response, 200)
34
+
35
+ content = JSON.parse(response.body)
36
+
37
+ SemaphoreClient::Model::Org.load(content)
38
+ end
39
+
40
+ private
41
+
42
+ def assert_response_status(response, expected_status)
43
+ return if response.status == expected_status
44
+
45
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,90 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class Project
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_org(org_id)
9
+ list_for_org!(org_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def list_for_team(team_id)
14
+ list_for_team!(team_id)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def attach_to_team(project_id, team_id)
19
+ attach_to_team!(project_id, team_id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def detach_from_team(project_id, team_id)
24
+ detach_from_team!(project_id, team_id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def list_for_shared_config(shared_config_id)
29
+ list_for_shared_config!(shared_config_id)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def list_for_org!(org_id)
34
+ response = @http_client.get([:orgs, org_id, :projects])
35
+
36
+ assert_response_status(response, 200)
37
+
38
+ content = JSON.parse(response.body)
39
+
40
+ content.map do |entity|
41
+ SemaphoreClient::Model::Project.load(entity)
42
+ end
43
+ end
44
+
45
+ def list_for_team!(team_id)
46
+ response = @http_client.get([:teams, team_id, :projects])
47
+
48
+ assert_response_status(response, 200)
49
+
50
+ content = JSON.parse(response.body)
51
+
52
+ content.map do |entity|
53
+ SemaphoreClient::Model::Project.load(entity)
54
+ end
55
+ end
56
+
57
+ def attach_to_team!(project_id, team_id)
58
+ response = @http_client.post([:teams, team_id, :projects, project_id])
59
+
60
+ assert_response_status(response, 204)
61
+ end
62
+
63
+ def detach_from_team!(project_id, team_id)
64
+ response = @http_client.delete([:teams, team_id, :projects, project_id])
65
+
66
+ assert_response_status(response, 204)
67
+ end
68
+
69
+ def list_for_shared_config!(shared_config_id)
70
+ response = @http_client.get([:shared_configs, shared_config_id, :projects])
71
+
72
+ assert_response_status(response, 200)
73
+
74
+ content = JSON.parse(response.body)
75
+
76
+ content.map do |entity|
77
+ SemaphoreClient::Model::Project.load(entity)
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def assert_response_status(response, expected_status)
84
+ return if response.status == expected_status
85
+
86
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,168 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class SharedConfig
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_org(org_id)
9
+ list_for_org!(org_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def create_for_org(org_id, params)
14
+ create_for_org!(org_id, params)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def list_for_team(team_id)
19
+ list_for_team!(team_id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def attach_to_team(shared_config_id, team_id)
24
+ attach_to_team!(shared_config_id, team_id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def detach_from_team(shared_config_id, team_id)
29
+ detach_from_team!(shared_config_id, team_id)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def list_for_project(project_id)
34
+ list_for_project!(project_id)
35
+ rescue SemaphoreClient::Exceptions::RequestFailed
36
+ end
37
+
38
+ def attach_to_project(shared_config_id, project_id)
39
+ attach_to_project!(shared_config_id, project_id)
40
+ rescue SemaphoreClient::Exceptions::RequestFailed
41
+ end
42
+
43
+ def detach_from_project(shared_config_id, project_id)
44
+ detach_from_project!(shared_config_id, project_id)
45
+ rescue SemaphoreClient::Exceptions::RequestFailed
46
+ end
47
+
48
+ def get(id)
49
+ get!(id)
50
+ rescue SemaphoreClient::Exceptions::RequestFailed
51
+ end
52
+
53
+ def delete(id)
54
+ delete!(id)
55
+ rescue SemaphoreClient::Exceptions::RequestFailed
56
+ end
57
+
58
+ def update(id, params)
59
+ update!(id, params)
60
+ rescue SemaphoreClient::Exceptions::RequestFailed
61
+ end
62
+
63
+ def list_for_org!(org_id)
64
+ response = @http_client.get([:orgs, org_id, :shared_configs])
65
+
66
+ assert_response_status(response, 200)
67
+
68
+ content = JSON.parse(response.body)
69
+
70
+ content.map do |entity|
71
+ SemaphoreClient::Model::SharedConfig.load(entity)
72
+ end
73
+ end
74
+
75
+ def create_for_org!(org_id, params)
76
+ response = @http_client.post([:orgs, org_id, :shared_configs], params.to_json)
77
+
78
+ assert_response_status(response, 200)
79
+
80
+ content = JSON.parse(response.body)
81
+
82
+ SemaphoreClient::Model::SharedConfig.load(content)
83
+ end
84
+
85
+ def list_for_team!(team_id)
86
+ response = @http_client.get([:teams, team_id, :shared_configs])
87
+
88
+ assert_response_status(response, 200)
89
+
90
+ content = JSON.parse(response.body)
91
+
92
+ content.map do |entity|
93
+ SemaphoreClient::Model::SharedConfig.load(entity)
94
+ end
95
+ end
96
+
97
+ def attach_to_team!(shared_config_id, team_id)
98
+ response = @http_client.post([:teams, team_id, :shared_configs, shared_config_id])
99
+
100
+ assert_response_status(response, 204)
101
+ end
102
+
103
+ def detach_from_team!(shared_config_id, team_id)
104
+ response = @http_client.delete([:teams, team_id, :shared_configs, shared_config_id])
105
+
106
+ assert_response_status(response, 204)
107
+ end
108
+
109
+ def list_for_project!(project_id)
110
+ response = @http_client.get([:projects, project_id, :shared_configs])
111
+
112
+ assert_response_status(response, 200)
113
+
114
+ content = JSON.parse(response.body)
115
+
116
+ content.map do |entity|
117
+ SemaphoreClient::Model::SharedConfig.load(entity)
118
+ end
119
+ end
120
+
121
+ def attach_to_project!(shared_config_id, project_id)
122
+ response = @http_client.post([:projects, project_id, :shared_configs, shared_config_id])
123
+
124
+ assert_response_status(response, 204)
125
+ end
126
+
127
+ def detach_from_project!(shared_config_id, project_id)
128
+ response = @http_client.delete([:projects, project_id, :shared_configs, shared_config_id])
129
+
130
+ assert_response_status(response, 204)
131
+ end
132
+
133
+ def get!(id)
134
+ response = @http_client.get([:shared_configs, id])
135
+
136
+ assert_response_status(response, 200)
137
+
138
+ content = JSON.parse(response.body)
139
+
140
+ SemaphoreClient::Model::SharedConfig.load(content)
141
+ end
142
+
143
+ def delete!(id)
144
+ response = @http_client.delete([:shared_configs, id])
145
+
146
+ assert_response_status(response, 200)
147
+ end
148
+
149
+ def update!(id, params)
150
+ response = @http_client.patch([:shared_configs, id], params.to_json)
151
+
152
+ assert_response_status(response, 200)
153
+
154
+ content = JSON.parse(response.body)
155
+
156
+ SemaphoreClient::Model::SharedConfig.load(content)
157
+ end
158
+
159
+ private
160
+
161
+ def assert_response_status(response, expected_status)
162
+ return if response.status == expected_status
163
+
164
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
165
+ end
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,124 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class Team
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_org(org_id)
9
+ list_for_org!(org_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def create_for_org(org_id, params)
14
+ create_for_org!(org_id, params)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def get(id)
19
+ get!(id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def delete(id)
24
+ delete!(id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def update(id, params)
29
+ update!(id, params)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def list_for_project(project_id)
34
+ list_for_project!(project_id)
35
+ rescue SemaphoreClient::Exceptions::RequestFailed
36
+ end
37
+
38
+ def list_for_shared_config(shared_config_id)
39
+ list_for_shared_config!(shared_config_id)
40
+ rescue SemaphoreClient::Exceptions::RequestFailed
41
+ end
42
+
43
+ def list_for_org!(org_id)
44
+ response = @http_client.get([:orgs, org_id, :teams])
45
+
46
+ assert_response_status(response, 200)
47
+
48
+ content = JSON.parse(response.body)
49
+
50
+ content.map do |entity|
51
+ SemaphoreClient::Model::Team.load(entity)
52
+ end
53
+ end
54
+
55
+ def create_for_org!(org_id, params)
56
+ response = @http_client.post([:orgs, org_id, :teams], params.to_json)
57
+
58
+ assert_response_status(response, 200)
59
+
60
+ content = JSON.parse(response.body)
61
+
62
+ SemaphoreClient::Model::Team.load(content)
63
+ end
64
+
65
+ def get!(id)
66
+ response = @http_client.get([:teams, id])
67
+
68
+ assert_response_status(response, 200)
69
+
70
+ content = JSON.parse(response.body)
71
+
72
+ SemaphoreClient::Model::Team.load(content)
73
+ end
74
+
75
+ def delete!(id)
76
+ response = @http_client.delete([:teams, id])
77
+
78
+ assert_response_status(response, 200)
79
+ end
80
+
81
+ def update!(id, params)
82
+ response = @http_client.patch([:teams, id], params.to_json)
83
+
84
+ assert_response_status(response, 200)
85
+
86
+ content = JSON.parse(response.body)
87
+
88
+ SemaphoreClient::Model::Team.load(content)
89
+ end
90
+
91
+ def list_for_project!(project_id)
92
+ response = @http_client.get([:projects, project_id, :teams])
93
+
94
+ assert_response_status(response, 200)
95
+
96
+ content = JSON.parse(response.body)
97
+
98
+ content.map do |entity|
99
+ SemaphoreClient::Model::Team.load(entity)
100
+ end
101
+ end
102
+
103
+ def list_for_shared_config!(shared_config_id)
104
+ response = @http_client.get([:shared_configs, shared_config_id, :teams])
105
+
106
+ assert_response_status(response, 200)
107
+
108
+ content = JSON.parse(response.body)
109
+
110
+ content.map do |entity|
111
+ SemaphoreClient::Model::Team.load(entity)
112
+ end
113
+ end
114
+
115
+ private
116
+
117
+ def assert_response_status(response, expected_status)
118
+ return if response.status == expected_status
119
+
120
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,90 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class User
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_org(org_id)
9
+ list_for_org!(org_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def list_for_team(team_id)
14
+ list_for_team!(team_id)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def attach_to_team(user_id, team_id)
19
+ attach_to_team!(user_id, team_id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def detach_from_team(user_id, team_id)
24
+ detach_from_team!(user_id, team_id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def list_for_project(project_id)
29
+ list_for_project!(project_id)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def list_for_org!(org_id)
34
+ response = @http_client.get([:orgs, org_id, :users])
35
+
36
+ assert_response_status(response, 200)
37
+
38
+ content = JSON.parse(response.body)
39
+
40
+ content.map do |entity|
41
+ SemaphoreClient::Model::User.load(entity)
42
+ end
43
+ end
44
+
45
+ def list_for_team!(team_id)
46
+ response = @http_client.get([:teams, team_id, :users])
47
+
48
+ assert_response_status(response, 200)
49
+
50
+ content = JSON.parse(response.body)
51
+
52
+ content.map do |entity|
53
+ SemaphoreClient::Model::User.load(entity)
54
+ end
55
+ end
56
+
57
+ def attach_to_team!(user_id, team_id)
58
+ response = @http_client.post([:teams, team_id, :users, user_id])
59
+
60
+ assert_response_status(response, 204)
61
+ end
62
+
63
+ def detach_from_team!(user_id, team_id)
64
+ response = @http_client.delete([:teams, team_id, :users, user_id])
65
+
66
+ assert_response_status(response, 204)
67
+ end
68
+
69
+ def list_for_project!(project_id)
70
+ response = @http_client.get([:projects, project_id, :users])
71
+
72
+ assert_response_status(response, 200)
73
+
74
+ content = JSON.parse(response.body)
75
+
76
+ content.map do |entity|
77
+ SemaphoreClient::Model::User.load(entity)
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def assert_response_status(response, expected_status)
84
+ return if response.status == expected_status
85
+
86
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
87
+ end
88
+ end
89
+ end
90
+ end