crowdin-api 0.6.0 → 1.2.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.
- checksums.yaml +4 -4
- data/.github/workflows/build-and-publish.yml +30 -0
- data/.github/workflows/test-and-lint.yml +31 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +146 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +71 -0
- data/Gemfile +5 -0
- data/LICENSE +1 -1
- data/README.md +120 -280
- data/Rakefile +19 -0
- data/bin/crowdin-console +54 -0
- data/bin/setup +6 -0
- data/crowdin-api.gemspec +33 -0
- data/lib/crowdin-api/api-resources/dictionaries.rb +34 -0
- data/lib/crowdin-api/api-resources/distributions.rb +99 -0
- data/lib/crowdin-api/api-resources/glossaries.rb +217 -0
- data/lib/crowdin-api/api-resources/labels.rb +117 -0
- data/lib/crowdin-api/api-resources/languages.rb +82 -0
- data/lib/crowdin-api/api-resources/machine_translation_engines.rb +74 -0
- data/lib/crowdin-api/api-resources/projects.rb +148 -0
- data/lib/crowdin-api/api-resources/reports.rb +138 -0
- data/lib/crowdin-api/api-resources/screenshots.rb +186 -0
- data/lib/crowdin-api/api-resources/source_files.rb +304 -0
- data/lib/crowdin-api/api-resources/source_strings.rb +74 -0
- data/lib/crowdin-api/api-resources/storages.rb +106 -0
- data/lib/crowdin-api/api-resources/string_comments.rb +73 -0
- data/lib/crowdin-api/api-resources/string_translations.rb +220 -0
- data/lib/crowdin-api/api-resources/tasks.rb +113 -0
- data/lib/crowdin-api/api-resources/teams.rb +144 -0
- data/lib/crowdin-api/api-resources/translation_memory.rb +145 -0
- data/lib/crowdin-api/api-resources/translation_status.rb +89 -0
- data/lib/crowdin-api/api-resources/translations.rb +161 -0
- data/lib/crowdin-api/api-resources/users.rb +129 -0
- data/lib/crowdin-api/api-resources/vendors.rb +21 -0
- data/lib/crowdin-api/api-resources/webhooks.rb +73 -0
- data/lib/crowdin-api/api-resources/workflows.rb +62 -0
- data/lib/crowdin-api/client/client.rb +95 -0
- data/lib/crowdin-api/client/configuration.rb +48 -0
- data/lib/crowdin-api/client/version.rb +7 -0
- data/lib/crowdin-api/core/errors.rb +8 -0
- data/lib/crowdin-api/core/errors_raisers.rb +39 -0
- data/lib/crowdin-api/core/request.rb +118 -0
- data/lib/crowdin-api/core/utils.rb +10 -0
- data/lib/crowdin-api.rb +39 -126
- data/spec/client/client-instance_spec.rb +14 -0
- data/spec/client/configuration-instance_spec.rb +72 -0
- data/spec/spec_helper.rb +9 -0
- metadata +130 -47
- data/lib/crowdin-api/errors.rb +0 -23
- data/lib/crowdin-api/methods.rb +0 -452
- data/lib/crowdin-api/version.rb +0 -5
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
module Translations
|
6
|
+
def pre_translation_status(pre_translation_id = nil, project_id = config.project_id)
|
7
|
+
pre_translation_id || raise_parameter_is_required_error(:pre_translation_id)
|
8
|
+
project_id || raise_project_id_is_required_error
|
9
|
+
|
10
|
+
request = Web::Request.new(
|
11
|
+
self,
|
12
|
+
:get,
|
13
|
+
"/projects/#{project_id}/pre-translations/#{pre_translation_id}"
|
14
|
+
)
|
15
|
+
|
16
|
+
request.perform
|
17
|
+
end
|
18
|
+
|
19
|
+
def apply_pre_translation(query = {}, project_id = config.project_id)
|
20
|
+
project_id || raise_project_id_is_required_error
|
21
|
+
|
22
|
+
request = Web::Request.new(
|
23
|
+
self,
|
24
|
+
:post,
|
25
|
+
"/projects/#{project_id}/pre-translations",
|
26
|
+
query
|
27
|
+
)
|
28
|
+
|
29
|
+
request.perform
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_project_directory_translation(directory_id = nil, query = {}, project_id = config.project_id)
|
33
|
+
directory_id || raise_parameter_is_required_error(:directory_id)
|
34
|
+
project_id || raise_project_id_is_required_error
|
35
|
+
|
36
|
+
request = Web::Request.new(
|
37
|
+
self,
|
38
|
+
:post,
|
39
|
+
"/projects/#{project_id}/translations/builds/directories/#{directory_id}",
|
40
|
+
query
|
41
|
+
)
|
42
|
+
|
43
|
+
request.perform
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_project_file_translation(file_id = nil, query = {}, project_id = config.project_id)
|
47
|
+
file_id || raise_parameter_is_required_error(:file_id)
|
48
|
+
project_id || raise_project_id_is_required_error
|
49
|
+
|
50
|
+
headers = query[:eTag] ? { 'If-None-Match' => query[:eTag] } : {}
|
51
|
+
|
52
|
+
request = Web::Request.new(
|
53
|
+
self,
|
54
|
+
:post,
|
55
|
+
"/projects/#{project_id}/translations/builds/files/#{file_id}",
|
56
|
+
query,
|
57
|
+
headers
|
58
|
+
)
|
59
|
+
|
60
|
+
request.perform
|
61
|
+
end
|
62
|
+
|
63
|
+
def list_project_builds(query = {}, project_id = config.project_id)
|
64
|
+
project_id || raise_project_id_is_required_error
|
65
|
+
|
66
|
+
request = Web::Request.new(
|
67
|
+
self,
|
68
|
+
:get,
|
69
|
+
"/projects/#{project_id}/translations/builds",
|
70
|
+
query
|
71
|
+
)
|
72
|
+
|
73
|
+
request.perform
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_project_translation(query = {}, project_id = config.project_id)
|
77
|
+
project_id || raise_project_id_is_required_error
|
78
|
+
|
79
|
+
request = Web::Request.new(
|
80
|
+
self,
|
81
|
+
:post,
|
82
|
+
"/projects/#{project_id}/translations/builds",
|
83
|
+
query
|
84
|
+
)
|
85
|
+
|
86
|
+
request.perform
|
87
|
+
end
|
88
|
+
|
89
|
+
def upload_translations(language_id = nil, query = {}, project_id = config.project_id)
|
90
|
+
language_id || raise_parameter_is_required_error(:language_id)
|
91
|
+
project_id || raise_project_id_is_required_error
|
92
|
+
|
93
|
+
request = Web::Request.new(
|
94
|
+
self,
|
95
|
+
:post,
|
96
|
+
"/projects/#{project_id}/translations/#{language_id}",
|
97
|
+
query
|
98
|
+
)
|
99
|
+
|
100
|
+
request.perform
|
101
|
+
end
|
102
|
+
|
103
|
+
def download_project_translations(build_id = nil, destination = nil, project_id = config.project_id)
|
104
|
+
build_id || raise_parameter_is_required_error(:build_id)
|
105
|
+
project_id || raise_project_id_is_required_error
|
106
|
+
|
107
|
+
request = Web::Request.new(
|
108
|
+
self,
|
109
|
+
:get,
|
110
|
+
"/projects/#{project_id}/translations/builds/#{build_id}/download",
|
111
|
+
{},
|
112
|
+
{},
|
113
|
+
destination
|
114
|
+
)
|
115
|
+
|
116
|
+
request.perform
|
117
|
+
end
|
118
|
+
|
119
|
+
def check_project_build_status(build_id = nil, project_id = config.project_id)
|
120
|
+
build_id || raise_parameter_is_required_error(:build_id)
|
121
|
+
project_id || raise_project_id_is_required_error
|
122
|
+
|
123
|
+
request = Web::Request.new(
|
124
|
+
self,
|
125
|
+
:get,
|
126
|
+
"/projects/#{project_id}/translations/builds/#{build_id}"
|
127
|
+
)
|
128
|
+
|
129
|
+
request.perform
|
130
|
+
end
|
131
|
+
|
132
|
+
def cancel_build(build_id = nil, project_id = config.project_id)
|
133
|
+
build_id || raise_parameter_is_required_error(:build_id)
|
134
|
+
project_id || raise_project_id_is_required_error
|
135
|
+
|
136
|
+
request = Web::Request.new(
|
137
|
+
self,
|
138
|
+
:delete,
|
139
|
+
"/projects/#{project_id}/translations/builds/#{build_id}"
|
140
|
+
)
|
141
|
+
|
142
|
+
request.perform
|
143
|
+
end
|
144
|
+
|
145
|
+
def export_project_translation(query = {}, destination = nil, project_id = config.project_id)
|
146
|
+
project_id || raise_project_id_is_required_error
|
147
|
+
|
148
|
+
request = Web::Request.new(
|
149
|
+
self,
|
150
|
+
:post,
|
151
|
+
"/projects/#{project_id}/translations/exports",
|
152
|
+
query,
|
153
|
+
{},
|
154
|
+
destination
|
155
|
+
)
|
156
|
+
|
157
|
+
request.perform
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
module Users
|
6
|
+
def get_authenticated_user
|
7
|
+
request = Web::Request.new(
|
8
|
+
self,
|
9
|
+
:get,
|
10
|
+
'/user'
|
11
|
+
)
|
12
|
+
|
13
|
+
request.perform
|
14
|
+
end
|
15
|
+
|
16
|
+
def list_project_members(query = {}, project_id = config.project_id)
|
17
|
+
project_id || raise_project_id_is_required_error
|
18
|
+
|
19
|
+
request = Web::Request.new(
|
20
|
+
self,
|
21
|
+
:get,
|
22
|
+
"/projects/#{project_id}/members",
|
23
|
+
query
|
24
|
+
)
|
25
|
+
|
26
|
+
request.perform
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_member_info(member_id = nil, project_id = config.project_id)
|
30
|
+
member_id || raise_parameter_is_required_error(:member_id)
|
31
|
+
project_id || raise_project_id_is_required_error
|
32
|
+
|
33
|
+
request = Web::Request.new(
|
34
|
+
self,
|
35
|
+
:get,
|
36
|
+
"/projects/#{project_id}/members/#{member_id}"
|
37
|
+
)
|
38
|
+
|
39
|
+
request.perform
|
40
|
+
end
|
41
|
+
|
42
|
+
# -- For Enterprise mode only --
|
43
|
+
|
44
|
+
def add_project_member(query = {}, project_id = config.project_id)
|
45
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
46
|
+
project_id || raise_project_id_is_required_error
|
47
|
+
|
48
|
+
request = Web::Request.new(
|
49
|
+
self,
|
50
|
+
:post,
|
51
|
+
"/projects/#{project_id}/members",
|
52
|
+
query
|
53
|
+
)
|
54
|
+
|
55
|
+
request.perform
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_project_member_permissions(member_id = nil, project_id = config.project_id)
|
59
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
60
|
+
member_id || raise_parameter_is_required_error(:member_id)
|
61
|
+
project_id || raise_project_id_is_required_error
|
62
|
+
|
63
|
+
request = Web::Request.new(
|
64
|
+
self,
|
65
|
+
:get,
|
66
|
+
"/projects/#{project_id}/members/#{member_id}"
|
67
|
+
)
|
68
|
+
|
69
|
+
request.perform
|
70
|
+
end
|
71
|
+
|
72
|
+
def replace_project_permissions(member_id = nil, query = {}, project_id = config.project_id)
|
73
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
74
|
+
member_id || raise_parameter_is_required_error(:member_id)
|
75
|
+
project_id || raise_project_id_is_required_error
|
76
|
+
|
77
|
+
request = Web::Request.new(
|
78
|
+
self,
|
79
|
+
:put,
|
80
|
+
"/projects/#{project_id}/members/#{member_id}",
|
81
|
+
query
|
82
|
+
)
|
83
|
+
|
84
|
+
request.perform
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete_member_from_project(member_id = nil, query = {}, project_id = config.project_id)
|
88
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
89
|
+
member_id || raise_parameter_is_required_error(:member_id)
|
90
|
+
project_id || raise_project_id_is_required_error
|
91
|
+
|
92
|
+
request = Web::Request.new(
|
93
|
+
self,
|
94
|
+
:delete,
|
95
|
+
"/projects/#{project_id}/members/#{member_id}",
|
96
|
+
query
|
97
|
+
)
|
98
|
+
|
99
|
+
request.perform
|
100
|
+
end
|
101
|
+
|
102
|
+
def list_users(query = {})
|
103
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
104
|
+
|
105
|
+
request = Web::Request.new(
|
106
|
+
self,
|
107
|
+
:get,
|
108
|
+
'/users',
|
109
|
+
query
|
110
|
+
)
|
111
|
+
|
112
|
+
request.perform
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_user(user_id = nil)
|
116
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
117
|
+
user_id || raise_parameter_is_required_error(:user_id)
|
118
|
+
|
119
|
+
request = Web::Request.new(
|
120
|
+
self,
|
121
|
+
:get,
|
122
|
+
"/users/#{user_id}"
|
123
|
+
)
|
124
|
+
|
125
|
+
request.perform
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
# -- For Enterprise mode only --
|
6
|
+
module Vendors
|
7
|
+
def list_vendors(query = {})
|
8
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
9
|
+
|
10
|
+
request = Web::Request.new(
|
11
|
+
self,
|
12
|
+
:get,
|
13
|
+
'/vendors',
|
14
|
+
query
|
15
|
+
)
|
16
|
+
|
17
|
+
request.perform
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
module Webhooks
|
6
|
+
def list_webhooks(query = {}, project_id = config.project_id)
|
7
|
+
project_id || raise_project_id_is_required_error
|
8
|
+
|
9
|
+
request = Web::Request.new(
|
10
|
+
self,
|
11
|
+
:get,
|
12
|
+
"/projects/#{project_id}/webhooks",
|
13
|
+
query
|
14
|
+
)
|
15
|
+
|
16
|
+
request.perform
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_webhook(query = {}, project_id = config.project_id)
|
20
|
+
project_id || raise_project_id_is_required_error
|
21
|
+
|
22
|
+
request = Web::Request.new(
|
23
|
+
self,
|
24
|
+
:post,
|
25
|
+
"/projects/#{project_id}/webhooks",
|
26
|
+
query
|
27
|
+
)
|
28
|
+
|
29
|
+
request.perform
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_webhook(webhook_id = nil, project_id = config.project_id)
|
33
|
+
webhook_id || raise_parameter_is_required_error(:webhook_id)
|
34
|
+
project_id || raise_project_id_is_required_error
|
35
|
+
|
36
|
+
request = Web::Request.new(
|
37
|
+
self,
|
38
|
+
:get,
|
39
|
+
"/projects/#{project_id}/webhooks/#{webhook_id}"
|
40
|
+
)
|
41
|
+
|
42
|
+
request.perform
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_webhook(webhook_id = nil, project_id = config.project_id)
|
46
|
+
webhook_id || raise_parameter_is_required_error(:webhook_id)
|
47
|
+
project_id || raise_project_id_is_required_error
|
48
|
+
|
49
|
+
request = Web::Request.new(
|
50
|
+
self,
|
51
|
+
:delete,
|
52
|
+
"/projects/#{project_id}/webhooks/#{webhook_id}"
|
53
|
+
)
|
54
|
+
|
55
|
+
request.perform
|
56
|
+
end
|
57
|
+
|
58
|
+
def edit_screenshot(webhook_id = nil, query = {}, project_id = config.project_id)
|
59
|
+
webhook_id || raise_parameter_is_required_error(:webhook_id)
|
60
|
+
project_id || raise_project_id_is_required_error
|
61
|
+
|
62
|
+
request = Web::Request.new(
|
63
|
+
self,
|
64
|
+
:patch,
|
65
|
+
"/projects/#{project_id}/webhooks/#{webhook_id}",
|
66
|
+
query
|
67
|
+
)
|
68
|
+
|
69
|
+
request.perform
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module ApiResources
|
5
|
+
# -- For Enterprise mode only --
|
6
|
+
module Workflows
|
7
|
+
def list_workflow_steps(query = {}, project_id = config.project_id)
|
8
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
9
|
+
project_id || raise_project_id_is_required_error
|
10
|
+
|
11
|
+
request = Web::Request.new(
|
12
|
+
self,
|
13
|
+
:get,
|
14
|
+
"/projects/#{project_id}/workflow-steps",
|
15
|
+
query
|
16
|
+
)
|
17
|
+
|
18
|
+
request.perform
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_workflow_step(step_id = nil, project_id = config.project_id)
|
22
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
23
|
+
step_id || raise_parameter_is_required_error(:step_id)
|
24
|
+
project_id || raise_project_id_is_required_error
|
25
|
+
|
26
|
+
request = Web::Request.new(
|
27
|
+
self,
|
28
|
+
:get,
|
29
|
+
"/projects/#{project_id}/workflow-steps/#{step_id}"
|
30
|
+
)
|
31
|
+
|
32
|
+
request.perform
|
33
|
+
end
|
34
|
+
|
35
|
+
def list_workflow_templates(query = {})
|
36
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
37
|
+
|
38
|
+
request = Web::Request.new(
|
39
|
+
self,
|
40
|
+
:get,
|
41
|
+
'/workflow-templates',
|
42
|
+
query
|
43
|
+
)
|
44
|
+
|
45
|
+
request.perform
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_workflow_template(template_id = nil)
|
49
|
+
config.enterprise_mode? || raise_only_for_enterprise_mode_error
|
50
|
+
template_id || raise_parameter_is_required_error(:template_id)
|
51
|
+
|
52
|
+
request = Web::Request.new(
|
53
|
+
self,
|
54
|
+
:get,
|
55
|
+
"/workflow-templates/#{template_id}"
|
56
|
+
)
|
57
|
+
|
58
|
+
request.perform
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# A wrapper and interface to the Crowdin API. Please visit the Crowdin developers site
|
5
|
+
# for a full explanation of what each of the Crowdin api methods expect and perform.
|
6
|
+
#
|
7
|
+
# https://support.crowdin.com/api/v2/
|
8
|
+
# https://support.crowdin.com/enterprise/api/
|
9
|
+
#
|
10
|
+
module Crowdin
|
11
|
+
#
|
12
|
+
# === Example
|
13
|
+
#
|
14
|
+
# require 'crowdin-api'
|
15
|
+
#
|
16
|
+
# crowdin = Crowdin::Client.new do |config|
|
17
|
+
# config.api_token = 'YOUR_API_TOKEN'
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# crowdin.list_projects
|
21
|
+
#
|
22
|
+
class Client
|
23
|
+
extend Utils
|
24
|
+
|
25
|
+
# API Resources modules
|
26
|
+
API_RESOURCES_MODULES = %i[Storages Languages Projects Workflows SourceFiles Translations SourceStrings
|
27
|
+
StringTranslations StringComments Screenshots Glossaries TranslationMemory
|
28
|
+
MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks
|
29
|
+
Dictionaries Distributions Labels TranslationStatus].freeze
|
30
|
+
|
31
|
+
# Error Raisers modules
|
32
|
+
ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze
|
33
|
+
|
34
|
+
# Processing all API Resources modules to include them to the Client
|
35
|
+
API_RESOURCES_MODULES.each do |module_name|
|
36
|
+
Client.send(:include, fetch_module_full_name_from_string("Crowdin::ApiResources::#{module_name}"))
|
37
|
+
end
|
38
|
+
|
39
|
+
# Processing all Error Raisers modules to include them to the Client
|
40
|
+
ERROR_RAISERS_MODULES.each do |module_name|
|
41
|
+
Client.send(:include, fetch_module_full_name_from_string("Crowdin::Errors::#{module_name}"))
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader :config
|
45
|
+
attr_reader :connection
|
46
|
+
attr_reader :options
|
47
|
+
attr_reader :logger
|
48
|
+
|
49
|
+
def initialize(&block)
|
50
|
+
build_configuration(&block)
|
51
|
+
|
52
|
+
check_logger
|
53
|
+
check_rest_client_proxy
|
54
|
+
|
55
|
+
build_connection
|
56
|
+
end
|
57
|
+
|
58
|
+
def log!(message)
|
59
|
+
!config.logger_enabled? || logger.debug(message)
|
60
|
+
end
|
61
|
+
|
62
|
+
def logger=(logger)
|
63
|
+
raise_logger_are_not_enabled_error unless config.logger_enabled?
|
64
|
+
@logger = logger
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def build_configuration
|
70
|
+
@config = Crowdin::Configuration.new
|
71
|
+
yield config if block_given?
|
72
|
+
end
|
73
|
+
|
74
|
+
def build_connection
|
75
|
+
@connection ||= ::RestClient::Resource.new(config.base_url, build_options)
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_options
|
79
|
+
@options ||= config.options.merge(headers: config.headers)
|
80
|
+
end
|
81
|
+
|
82
|
+
def set_default_logger
|
83
|
+
require 'logger'
|
84
|
+
@logger ||= Logger.new($stderr)
|
85
|
+
end
|
86
|
+
|
87
|
+
def check_rest_client_proxy
|
88
|
+
ENV['http_proxy'] ? ::RestClient.proxy = ENV['http_proxy'] : false
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_logger
|
92
|
+
config.logger_enabled? ? set_default_logger : config.enable_logger = false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :api_token
|
6
|
+
attr_accessor :project_id
|
7
|
+
attr_accessor :organization_domain
|
8
|
+
attr_accessor :enable_logger
|
9
|
+
|
10
|
+
attr_reader :target_api_url
|
11
|
+
|
12
|
+
alias logger_enabled? enable_logger
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@target_api_url = '/api/v2'
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
{
|
20
|
+
headers: {},
|
21
|
+
timeout: nil,
|
22
|
+
json: true
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def headers
|
27
|
+
{
|
28
|
+
'Accept' => 'application/json',
|
29
|
+
'Authorization' => "Bearer #{api_token}",
|
30
|
+
'Content-Type' => 'application/json',
|
31
|
+
'User-Agent' => "crowdin-rb/#{Crowdin::Client::VERSION}/#{RUBY_VERSION}/#{RUBY_PLATFORM}"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def base_url
|
36
|
+
if enterprise_mode?
|
37
|
+
organization_domain.include?('.com') ? organization_domain : "https://#{organization_domain}.api.crowdin.com"
|
38
|
+
else
|
39
|
+
'https://api.crowdin.com'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def organization_domain?
|
44
|
+
!!organization_domain
|
45
|
+
end
|
46
|
+
alias enterprise_mode? organization_domain?
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Crowdin
|
4
|
+
module Errors
|
5
|
+
# Client errors raiser
|
6
|
+
module ClientErrorsRaiser
|
7
|
+
def raise_logger_are_not_enabled_error
|
8
|
+
raise(LoggerAreNotEnabledError, 'Logger are not enabled in your Client configuration, enable it ' \
|
9
|
+
'before setting your own logger')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Command-Line Client errors raiser
|
14
|
+
module ClcErrorsRaiser
|
15
|
+
def raise_api_token_is_required_error
|
16
|
+
raise(ArgumentError, '--api-token option is required')
|
17
|
+
end
|
18
|
+
|
19
|
+
def raise_organization_domain_is_required_error
|
20
|
+
raise(ArgumentError, '--organization-domain option is required for Enterprise mode')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# API errors raiser
|
25
|
+
module ApiErrorsRaiser
|
26
|
+
def raise_only_for_enterprise_mode_error
|
27
|
+
raise(OnlyForEnterpriseModeError, 'This method can be called only for Enterprise mode')
|
28
|
+
end
|
29
|
+
|
30
|
+
def raise_project_id_is_required_error
|
31
|
+
raise(ArgumentError, ':project_id is required in parameters or while Client initialization')
|
32
|
+
end
|
33
|
+
|
34
|
+
def raise_parameter_is_required_error(parameter)
|
35
|
+
raise(ArgumentError, ":#{parameter} is required")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|