Class: SemaphoreClient::Api::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/semaphore_client/api/config_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_client) ⇒ ConfigFile

Returns a new instance of ConfigFile.



4
5
6
# File 'lib/semaphore_client/api/config_file.rb', line 4

def initialize(http_client)
  @http_client = http_client
end

Instance Method Details

#attach_to_project(config_file_id, project_id) ⇒ Object



13
14
15
16
# File 'lib/semaphore_client/api/config_file.rb', line 13

def attach_to_project(config_file_id, project_id)
  attach_to_project!(config_file_id, project_id)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#attach_to_project!(config_file_id, project_id) ⇒ Object



62
63
64
65
66
# File 'lib/semaphore_client/api/config_file.rb', line 62

def attach_to_project!(config_file_id, project_id)
  response = @http_client.post([:projects, project_id, :config_files, config_file_id])

  assert_response_status(response, 204)
end

#create_for_shared_config(shared_config_id, params) ⇒ Object



28
29
30
31
# File 'lib/semaphore_client/api/config_file.rb', line 28

def create_for_shared_config(shared_config_id, params)
  create_for_shared_config!(shared_config_id, params)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#create_for_shared_config!(shared_config_id, params) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/semaphore_client/api/config_file.rb', line 88

def create_for_shared_config!(shared_config_id, params)
  response = @http_client.post([:shared_configs, shared_config_id, :config_files], params.to_json)

  assert_response_status(response, 200)

  content = JSON.parse(response.body)

  SemaphoreClient::Model::ConfigFile.load(content)
end

#delete(id) ⇒ Object



38
39
40
41
# File 'lib/semaphore_client/api/config_file.rb', line 38

def delete(id)
  delete!(id)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#delete!(id) ⇒ Object



108
109
110
111
112
# File 'lib/semaphore_client/api/config_file.rb', line 108

def delete!(id)
  response = @http_client.delete([:config_files, id])

  assert_response_status(response, 200)
end

#detach_from_project(config_file_id, project_id) ⇒ Object



18
19
20
21
# File 'lib/semaphore_client/api/config_file.rb', line 18

def detach_from_project(config_file_id, project_id)
  detach_from_project!(config_file_id, project_id)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#detach_from_project!(config_file_id, project_id) ⇒ Object



68
69
70
71
72
# File 'lib/semaphore_client/api/config_file.rb', line 68

def detach_from_project!(config_file_id, project_id)
  response = @http_client.delete([:projects, project_id, :config_files, config_file_id])

  assert_response_status(response, 204)
end

#get(id) ⇒ Object



33
34
35
36
# File 'lib/semaphore_client/api/config_file.rb', line 33

def get(id)
  get!(id)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#get!(id) ⇒ Object



98
99
100
101
102
103
104
105
106
# File 'lib/semaphore_client/api/config_file.rb', line 98

def get!(id)
  response = @http_client.get([:config_files, id])

  assert_response_status(response, 200)

  content = JSON.parse(response.body)

  SemaphoreClient::Model::ConfigFile.load(content)
end

#list_for_project(project_id, query = nil) ⇒ Object



8
9
10
11
# File 'lib/semaphore_client/api/config_file.rb', line 8

def list_for_project(project_id, query = nil)
  list_for_project!(project_id, query)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#list_for_project!(project_id, query = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/semaphore_client/api/config_file.rb', line 48

def list_for_project!(project_id, query = nil)
  query_string = query.nil? ? nil : "?#{query}"

  response = @http_client.get([:projects, project_id, :config_files, query_string].compact)

  assert_response_status(response, 200)

  content = JSON.parse(response.body)

  content.map do |entity|
    SemaphoreClient::Model::ConfigFile.load(entity)
  end
end

#list_for_shared_config(shared_config_id, query = nil) ⇒ Object



23
24
25
26
# File 'lib/semaphore_client/api/config_file.rb', line 23

def list_for_shared_config(shared_config_id, query = nil)
  list_for_shared_config!(shared_config_id, query)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#list_for_shared_config!(shared_config_id, query = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/semaphore_client/api/config_file.rb', line 74

def list_for_shared_config!(shared_config_id, query = nil)
  query_string = query.nil? ? nil : "?#{query}"

  response = @http_client.get([:shared_configs, shared_config_id, :config_files, query_string].compact)

  assert_response_status(response, 200)

  content = JSON.parse(response.body)

  content.map do |entity|
    SemaphoreClient::Model::ConfigFile.load(entity)
  end
end

#update(id, params) ⇒ Object



43
44
45
46
# File 'lib/semaphore_client/api/config_file.rb', line 43

def update(id, params)
  update!(id, params)
rescue SemaphoreClient::Exceptions::RequestFailed
end

#update!(id, params) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/semaphore_client/api/config_file.rb', line 114

def update!(id, params)
  response = @http_client.patch([:config_files, id], params.to_json)

  assert_response_status(response, 200)

  content = JSON.parse(response.body)

  SemaphoreClient::Model::ConfigFile.load(content)
end