semaphore_client 2.3.1 → 2.4.0

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