-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathbundles.rb
154 lines (136 loc) · 6.87 KB
/
bundles.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# frozen_string_literal: true
module Crowdin
module ApiResources
module Bundles
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.getMany API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.getMany Enterprise API Documentation}
def list_bundles(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles",
{ params: query }
)
Web::SendRequest.new(request).perform
end
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.post API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.post Enterprise API Documentation}
def add_bundle(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error
%i[name format sourcePatterns exportPattern].each do |param|
query[param] || raise_parameter_is_required_error(param)
end
request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/bundles",
{ params: query }
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.post API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.post Enterprise API Documentation}
def export_bundle(bundle_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports"
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# @param export_id [String] Export ID
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.get API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.get Enterprise API Documentation}
def check_bundle_export_status(bundle_id, export_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
export_id || raise_parameter_is_required_error(:export_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}"
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# @param export_id [String] Export ID
# @param destination [String] Destination of File
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.exports.download.get API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.exports.download.get Enterprise API Documentation}
def download_bundle(bundle_id, export_id, destination = nil, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
export_id || raise_parameter_is_required_error(:export_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/exports/#{export_id}/download"
)
Web::SendRequest.new(request, destination).perform
end
# @param bundle_id [Integer] Bundle ID
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.get API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.get Enterprise API Documentation}
def get_bundle(bundle_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}"
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.delete API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.delete Enterprise API Documentation}
def delete_bundle(bundle_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:delete,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}"
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.patch API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.patch Enterprise API Documentation}
def edit_bundle(bundle_id, query = {}, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:patch,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}",
{ params: query }
)
Web::SendRequest.new(request).perform
end
# @param bundle_id [Integer] Bundle ID
# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.bundles.files.getMany API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.bundles.files.getMany Enterprise API Documentation}
def bundle_list_files(bundle_id, query = {}, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error
request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/files",
{ params: query }
)
Web::SendRequest.new(request).perform
end
end
end
end