semaphore_client 2.3.1 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8667d0574937ebe6d65ba924beefa38e3137c057
4
- data.tar.gz: 3deb2629af0dbe542818a7f86a1c5408d8467f0a
3
+ metadata.gz: 6d4ea7977e94aa5c80b02123679165c5cc3f6720
4
+ data.tar.gz: 147e7c0565697549c42bf2b4193e98e8045a525c
5
5
  SHA512:
6
- metadata.gz: 011b080f1ba2433a40b8245b108ad89c8043c114d9bd2c473eb8215274735db2d5c66d857daec4c8a27aaaec0418a140cd8b2bca7d6d726851e44692cd94638d
7
- data.tar.gz: f9d4ba58651191611e064e1eff99d55f5359c71e5610b71258e3e53393c999c5e523c6b79bc7bc5c831a869b7375693e83bc54a525fd3bcb8635e1c3af13c46a
6
+ metadata.gz: e7c4bf97917f9d10322bf30dddee91be955aff962ce42baa3214c821b80a8b62b94a9a9ce1d95852884822ce225b237b842f1bcdf284ddd4ca480cb2440402d8
7
+ data.tar.gz: 9b654def04a757c7b531dbbbe85ae4faebb547ff9c545bfbb026d47285178e508e92e3513dfea2ea681dc6b8066c3cd329c8e0cb5e19d17f0231d871404be78b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- semaphore_client (2.3.1)
4
+ semaphore_client (2.4.0)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -1,6 +1,7 @@
1
1
  require "json"
2
2
  require "securerandom"
3
3
  require "faraday"
4
+ require "faraday_middleware"
4
5
  require "logger"
5
6
 
6
7
  require "semaphore_client/version"
@@ -28,10 +29,11 @@ class SemaphoreClient
28
29
  def initialize(auth_token, options = {})
29
30
  @auth_token = auth_token
30
31
 
31
- @api_url = options.fetch(:api_url, API_URL)
32
- @api_version = options.fetch(:api_version, API_VERSION)
33
- @verbose = options.fetch(:verbose, false)
34
- @logger = options.fetch(:logger, Logger.new(STDOUT))
32
+ @api_url = options.fetch(:api_url, API_URL)
33
+ @api_version = options.fetch(:api_version, API_VERSION)
34
+ @verbose = options.fetch(:verbose, false)
35
+ @logger = options.fetch(:logger, Logger.new(STDOUT))
36
+ @auto_paginate = options.fetch(:auto_paginate, false)
35
37
  end
36
38
 
37
39
  def users
@@ -65,6 +67,6 @@ class SemaphoreClient
65
67
  private
66
68
 
67
69
  def http_client
68
- @http_client ||= SemaphoreClient::HttpClient.new(@auth_token, @api_url, @api_version, @verbose, @logger)
70
+ @http_client ||= SemaphoreClient::HttpClient.new(@auth_token, @api_url, @api_version, @verbose, @logger, @auto_paginate)
69
71
  end
70
72
  end
@@ -5,135 +5,113 @@ class SemaphoreClient
5
5
  @http_client = http_client
6
6
  end
7
7
 
8
- def list_for_project(project_id, query = nil)
9
- list_for_project!(project_id, query)
10
- rescue SemaphoreClient::Exceptions::RequestFailed
11
- end
12
8
 
13
- def attach_to_project(config_file_id, project_id)
14
- attach_to_project!(config_file_id, project_id)
15
- rescue SemaphoreClient::Exceptions::RequestFailed
9
+ def list_for_project(project_id, params = nil, options = {})
10
+ list_for_project!(project_id, params, options)
11
+ rescue SemaphoreClient::Exceptions::ResponseError
16
12
  end
17
13
 
18
- def detach_from_project(config_file_id, project_id)
19
- detach_from_project!(config_file_id, project_id)
20
- rescue SemaphoreClient::Exceptions::RequestFailed
21
- end
14
+ def list_for_project!(project_id, params = nil, options = {})
15
+ path = "/projects/#{project_id}/config_files"
22
16
 
23
- def list_for_shared_config(shared_config_id, query = nil)
24
- list_for_shared_config!(shared_config_id, query)
25
- rescue SemaphoreClient::Exceptions::RequestFailed
17
+ @http_client.get(path, params, options = {}).body.map { |e| SemaphoreClient::Model::ConfigFile.load(e) }
26
18
  end
27
19
 
28
- def create_for_shared_config(shared_config_id, params)
29
- create_for_shared_config!(shared_config_id, params)
30
- rescue SemaphoreClient::Exceptions::RequestFailed
31
- end
32
20
 
33
- def get(id)
34
- get!(id)
35
- rescue SemaphoreClient::Exceptions::RequestFailed
36
- end
37
21
 
38
- def delete(id)
39
- delete!(id)
40
- rescue SemaphoreClient::Exceptions::RequestFailed
22
+ def attach_to_project(config_file_id, project_id, params = nil, options = {})
23
+ attach_to_project!(config_file_id, project_id, params, options)
24
+ rescue SemaphoreClient::Exceptions::ResponseError
41
25
  end
42
26
 
43
- def update(id, params)
44
- update!(id, params)
45
- rescue SemaphoreClient::Exceptions::RequestFailed
27
+ def attach_to_project!(config_file_id, project_id, params = nil, options = {})
28
+ path = "/projects/#{project_id}/config_files/#{config_file_id}"
29
+
30
+ @http_client.post(path, params, options)
46
31
  end
47
32
 
48
- def list_for_project!(project_id, query = nil)
49
- query_string =
50
- unless query.nil? || query.empty?
51
- "?" + query.map { |key, value| "#{key}=#{value}" }.join("&")
52
- end
53
33
 
54
- response = @http_client.get([:projects, project_id, :config_files, query_string].compact)
55
34
 
56
- assert_response_status(response, 200)
35
+ def detach_from_project(config_file_id, project_id, params = nil, options = {})
36
+ detach_from_project!(config_file_id, project_id, params, options)
37
+ rescue SemaphoreClient::Exceptions::ResponseError
38
+ end
57
39
 
58
- content = JSON.parse(response.body)
40
+ def detach_from_project!(config_file_id, project_id, params = nil, options = {})
41
+ path = "/projects/#{project_id}/config_files/#{config_file_id}"
59
42
 
60
- content.map do |entity|
61
- SemaphoreClient::Model::ConfigFile.load(entity)
62
- end
43
+ @http_client.delete(path, params, options)
63
44
  end
64
45
 
65
- def attach_to_project!(config_file_id, project_id)
66
- response = @http_client.post([:projects, project_id, :config_files, config_file_id])
67
46
 
68
- assert_response_status(response, 204)
47
+
48
+ def list_for_shared_config(shared_config_id, params = nil, options = {})
49
+ list_for_shared_config!(shared_config_id, params, options)
50
+ rescue SemaphoreClient::Exceptions::ResponseError
69
51
  end
70
52
 
71
- def detach_from_project!(config_file_id, project_id)
72
- response = @http_client.delete([:projects, project_id, :config_files, config_file_id])
53
+ def list_for_shared_config!(shared_config_id, params = nil, options = {})
54
+ path = "/shared_configs/#{shared_config_id}/config_files"
73
55
 
74
- assert_response_status(response, 204)
56
+ @http_client.get(path, params, options = {}).body.map { |e| SemaphoreClient::Model::ConfigFile.load(e) }
75
57
  end
76
58
 
77
- def list_for_shared_config!(shared_config_id, query = nil)
78
- query_string =
79
- unless query.nil? || query.empty?
80
- "?" + query.map { |key, value| "#{key}=#{value}" }.join("&")
81
- end
82
59
 
83
- response = @http_client.get([:shared_configs, shared_config_id, :config_files, query_string].compact)
84
60
 
85
- assert_response_status(response, 200)
61
+ def create_for_shared_config(shared_config_id, params = nil, options = {})
62
+ create_for_shared_config!(shared_config_id, params, options)
63
+ rescue SemaphoreClient::Exceptions::ResponseError
64
+ end
86
65
 
87
- content = JSON.parse(response.body)
66
+ def create_for_shared_config!(shared_config_id, params = nil, options = {})
67
+ path = "/shared_configs/#{shared_config_id}/config_files"
68
+ response = @http_client.post(path, params, options)
88
69
 
89
- content.map do |entity|
90
- SemaphoreClient::Model::ConfigFile.load(entity)
91
- end
70
+ SemaphoreClient::Model::ConfigFile.load(response.body)
92
71
  end
93
72
 
94
- def create_for_shared_config!(shared_config_id, params)
95
- response = @http_client.post([:shared_configs, shared_config_id, :config_files], params.to_json)
96
73
 
97
- assert_response_status(response, 200)
98
74
 
99
- content = JSON.parse(response.body)
100
-
101
- SemaphoreClient::Model::ConfigFile.load(content)
75
+ def get(id, params = nil, options = {})
76
+ get!(id, params, options)
77
+ rescue SemaphoreClient::Exceptions::ResponseError
102
78
  end
103
79
 
104
- def get!(id)
105
- response = @http_client.get([:config_files, id])
80
+ def get!(id, params = nil, options = {})
81
+ path = "/config_files/#{id}"
82
+ response = @http_client.get(path, params = {})
83
+
84
+ SemaphoreClient::Model::ConfigFile.load(response.body)
85
+ end
106
86
 
107
- assert_response_status(response, 200)
108
87
 
109
- content = JSON.parse(response.body)
110
88
 
111
- SemaphoreClient::Model::ConfigFile.load(content)
89
+ def delete(id, params = nil, options = {})
90
+ delete!(id, params, options)
91
+ rescue SemaphoreClient::Exceptions::ResponseError
112
92
  end
113
93
 
114
- def delete!(id)
115
- response = @http_client.delete([:config_files, id])
94
+ def delete!(id, params = nil, options = {})
95
+ path = "/config_files/#{id}"
116
96
 
117
- assert_response_status(response, 200)
97
+ @http_client.delete(path, params)
118
98
  end
119
99
 
120
- def update!(id, params)
121
- response = @http_client.patch([:config_files, id], params.to_json)
122
-
123
- assert_response_status(response, 200)
124
100
 
125
- content = JSON.parse(response.body)
126
101
 
127
- SemaphoreClient::Model::ConfigFile.load(content)
102
+ def update(id, params = nil, options = {})
103
+ update!(id, params, options)
104
+ rescue SemaphoreClient::Exceptions::ResponseError
128
105
  end
129
106
 
130
- private
107
+ def update!(id, params = nil, options = {})
108
+ path = "/config_files/#{id}"
109
+ response = @http_client.patch(path, params)
131
110
 
132
- def assert_response_status(response, expected_status)
133
- return if response.status == expected_status
134
-
135
- raise SemaphoreClient::Exceptions::RequestFailed, response.status
111
+ SemaphoreClient::Model::ConfigFile.load(response.body)
136
112
  end
113
+
114
+
137
115
  end
138
116
  end
139
117
  end
@@ -5,135 +5,113 @@ class SemaphoreClient
5
5
  @http_client = http_client
6
6
  end
7
7
 
8
- def list_for_project(project_id, query = nil)
9
- list_for_project!(project_id, query)
10
- rescue SemaphoreClient::Exceptions::RequestFailed
11
- end
12
8
 
13
- def attach_to_project(env_var_id, project_id)
14
- attach_to_project!(env_var_id, project_id)
15
- rescue SemaphoreClient::Exceptions::RequestFailed
9
+ def list_for_project(project_id, params = nil, options = {})
10
+ list_for_project!(project_id, params, options)
11
+ rescue SemaphoreClient::Exceptions::ResponseError
16
12
  end
17
13
 
18
- def detach_from_project(env_var_id, project_id)
19
- detach_from_project!(env_var_id, project_id)
20
- rescue SemaphoreClient::Exceptions::RequestFailed
21
- end
14
+ def list_for_project!(project_id, params = nil, options = {})
15
+ path = "/projects/#{project_id}/env_vars"
22
16
 
23
- def list_for_shared_config(shared_config_id, query = nil)
24
- list_for_shared_config!(shared_config_id, query)
25
- rescue SemaphoreClient::Exceptions::RequestFailed
17
+ @http_client.get(path, params, options = {}).body.map { |e| SemaphoreClient::Model::EnvVar.load(e) }
26
18
  end
27
19
 
28
- def create_for_shared_config(shared_config_id, params)
29
- create_for_shared_config!(shared_config_id, params)
30
- rescue SemaphoreClient::Exceptions::RequestFailed
31
- end
32
20
 
33
- def get(id)
34
- get!(id)
35
- rescue SemaphoreClient::Exceptions::RequestFailed
36
- end
37
21
 
38
- def delete(id)
39
- delete!(id)
40
- rescue SemaphoreClient::Exceptions::RequestFailed
22
+ def attach_to_project(env_var_id, project_id, params = nil, options = {})
23
+ attach_to_project!(env_var_id, project_id, params, options)
24
+ rescue SemaphoreClient::Exceptions::ResponseError
41
25
  end
42
26
 
43
- def update(id, params)
44
- update!(id, params)
45
- rescue SemaphoreClient::Exceptions::RequestFailed
27
+ def attach_to_project!(env_var_id, project_id, params = nil, options = {})
28
+ path = "/projects/#{project_id}/env_vars/#{env_var_id}"
29
+
30
+ @http_client.post(path, params, options)
46
31
  end
47
32
 
48
- def list_for_project!(project_id, query = nil)
49
- query_string =
50
- unless query.nil? || query.empty?
51
- "?" + query.map { |key, value| "#{key}=#{value}" }.join("&")
52
- end
53
33
 
54
- response = @http_client.get([:projects, project_id, :env_vars, query_string].compact)
55
34
 
56
- assert_response_status(response, 200)
35
+ def detach_from_project(env_var_id, project_id, params = nil, options = {})
36
+ detach_from_project!(env_var_id, project_id, params, options)
37
+ rescue SemaphoreClient::Exceptions::ResponseError
38
+ end
57
39
 
58
- content = JSON.parse(response.body)
40
+ def detach_from_project!(env_var_id, project_id, params = nil, options = {})
41
+ path = "/projects/#{project_id}/env_vars/#{env_var_id}"
59
42
 
60
- content.map do |entity|
61
- SemaphoreClient::Model::EnvVar.load(entity)
62
- end
43
+ @http_client.delete(path, params, options)
63
44
  end
64
45
 
65
- def attach_to_project!(env_var_id, project_id)
66
- response = @http_client.post([:projects, project_id, :env_vars, env_var_id])
67
46
 
68
- assert_response_status(response, 204)
47
+
48
+ def list_for_shared_config(shared_config_id, params = nil, options = {})
49
+ list_for_shared_config!(shared_config_id, params, options)
50
+ rescue SemaphoreClient::Exceptions::ResponseError
69
51
  end
70
52
 
71
- def detach_from_project!(env_var_id, project_id)
72
- response = @http_client.delete([:projects, project_id, :env_vars, env_var_id])
53
+ def list_for_shared_config!(shared_config_id, params = nil, options = {})
54
+ path = "/shared_configs/#{shared_config_id}/env_vars"
73
55
 
74
- assert_response_status(response, 204)
56
+ @http_client.get(path, params, options = {}).body.map { |e| SemaphoreClient::Model::EnvVar.load(e) }
75
57
  end
76
58
 
77
- def list_for_shared_config!(shared_config_id, query = nil)
78
- query_string =
79
- unless query.nil? || query.empty?
80
- "?" + query.map { |key, value| "#{key}=#{value}" }.join("&")
81
- end
82
59
 
83
- response = @http_client.get([:shared_configs, shared_config_id, :env_vars, query_string].compact)
84
60
 
85
- assert_response_status(response, 200)
61
+ def create_for_shared_config(shared_config_id, params = nil, options = {})
62
+ create_for_shared_config!(shared_config_id, params, options)
63
+ rescue SemaphoreClient::Exceptions::ResponseError
64
+ end
86
65
 
87
- content = JSON.parse(response.body)
66
+ def create_for_shared_config!(shared_config_id, params = nil, options = {})
67
+ path = "/shared_configs/#{shared_config_id}/env_vars"
68
+ response = @http_client.post(path, params, options)
88
69
 
89
- content.map do |entity|
90
- SemaphoreClient::Model::EnvVar.load(entity)
91
- end
70
+ SemaphoreClient::Model::EnvVar.load(response.body)
92
71
  end
93
72
 
94
- def create_for_shared_config!(shared_config_id, params)
95
- response = @http_client.post([:shared_configs, shared_config_id, :env_vars], params.to_json)
96
73
 
97
- assert_response_status(response, 200)
98
74
 
99
- content = JSON.parse(response.body)
100
-
101
- SemaphoreClient::Model::EnvVar.load(content)
75
+ def get(id, params = nil, options = {})
76
+ get!(id, params, options)
77
+ rescue SemaphoreClient::Exceptions::ResponseError
102
78
  end
103
79
 
104
- def get!(id)
105
- response = @http_client.get([:env_vars, id])
80
+ def get!(id, params = nil, options = {})
81
+ path = "/env_vars/#{id}"
82
+ response = @http_client.get(path, params = {})
83
+
84
+ SemaphoreClient::Model::EnvVar.load(response.body)
85
+ end
106
86
 
107
- assert_response_status(response, 200)
108
87
 
109
- content = JSON.parse(response.body)
110
88
 
111
- SemaphoreClient::Model::EnvVar.load(content)
89
+ def delete(id, params = nil, options = {})
90
+ delete!(id, params, options)
91
+ rescue SemaphoreClient::Exceptions::ResponseError
112
92
  end
113
93
 
114
- def delete!(id)
115
- response = @http_client.delete([:env_vars, id])
94
+ def delete!(id, params = nil, options = {})
95
+ path = "/env_vars/#{id}"
116
96
 
117
- assert_response_status(response, 200)
97
+ @http_client.delete(path, params)
118
98
  end
119
99
 
120
- def update!(id, params)
121
- response = @http_client.patch([:env_vars, id], params.to_json)
122
-
123
- assert_response_status(response, 200)
124
100
 
125
- content = JSON.parse(response.body)
126
101
 
127
- SemaphoreClient::Model::EnvVar.load(content)
102
+ def update(id, params = nil, options = {})
103
+ update!(id, params, options)
104
+ rescue SemaphoreClient::Exceptions::ResponseError
128
105
  end
129
106
 
130
- private
107
+ def update!(id, params = nil, options = {})
108
+ path = "/env_vars/#{id}"
109
+ response = @http_client.patch(path, params)
131
110
 
132
- def assert_response_status(response, expected_status)
133
- return if response.status == expected_status
134
-
135
- raise SemaphoreClient::Exceptions::RequestFailed, response.status
111
+ SemaphoreClient::Model::EnvVar.load(response.body)
136
112
  end
113
+
114
+
137
115
  end
138
116
  end
139
117
  end
@@ -5,45 +5,33 @@ class SemaphoreClient
5
5
  @http_client = http_client
6
6
  end
7
7
 
8
- def list
9
- list!
10
- rescue SemaphoreClient::Exceptions::RequestFailed
11
- end
12
8
 
13
- def get(id)
14
- get!(id)
15
- rescue SemaphoreClient::Exceptions::RequestFailed
9
+ def list(params = nil, options = {})
10
+ list!(params, options)
11
+ rescue SemaphoreClient::Exceptions::ResponseError
16
12
  end
17
13
 
18
- def list!
19
- response = @http_client.get([:orgs])
20
-
21
- assert_response_status(response, 200)
14
+ def list!(params = nil, options = {})
15
+ path = "/orgs"
22
16
 
23
- content = JSON.parse(response.body)
24
-
25
- content.map do |entity|
26
- SemaphoreClient::Model::Org.load(entity)
27
- end
17
+ @http_client.get(path, params, options).body.map { |e| SemaphoreClient::Model::Org.load(e) }
28
18
  end
29
19
 
30
- def get!(id)
31
- response = @http_client.get([:orgs, id])
32
-
33
- assert_response_status(response, 200)
34
20
 
35
- content = JSON.parse(response.body)
36
21
 
37
- SemaphoreClient::Model::Org.load(content)
22
+ def get(id, params = nil, options = {})
23
+ get!(id, params, options)
24
+ rescue SemaphoreClient::Exceptions::ResponseError
38
25
  end
39
26
 
40
- private
27
+ def get!(id, params = nil, options = {})
28
+ path = "/orgs/#{id}"
29
+ response = @http_client.get(path, params = {})
41
30
 
42
- def assert_response_status(response, expected_status)
43
- return if response.status == expected_status
44
-
45
- raise SemaphoreClient::Exceptions::RequestFailed, response.status
31
+ SemaphoreClient::Model::Org.load(response.body)
46
32
  end
33
+
34
+
47
35
  end
48
36
  end
49
37
  end