ruby-lokalise-api 7.1.1 → 8.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_lokalise_api/base_client.rb +2 -34
- data/lib/ruby_lokalise_api/client.rb +2 -31
- data/lib/ruby_lokalise_api/collections/base.rb +97 -70
- data/lib/ruby_lokalise_api/collections/branches.rb +11 -0
- data/lib/ruby_lokalise_api/collections/contributors.rb +10 -0
- data/lib/ruby_lokalise_api/collections/custom_translation_statuses.rb +10 -0
- data/lib/ruby_lokalise_api/collections/files.rb +10 -0
- data/lib/ruby_lokalise_api/collections/key_comments.rb +11 -0
- data/lib/ruby_lokalise_api/collections/keys.rb +10 -0
- data/lib/ruby_lokalise_api/collections/orders.rb +10 -0
- data/lib/ruby_lokalise_api/collections/payment_cards.rb +10 -0
- data/lib/ruby_lokalise_api/collections/project_comments.rb +12 -0
- data/lib/ruby_lokalise_api/collections/project_languages.rb +11 -0
- data/lib/ruby_lokalise_api/collections/projects.rb +10 -0
- data/lib/ruby_lokalise_api/collections/queued_processes.rb +11 -0
- data/lib/ruby_lokalise_api/collections/screenshots.rb +10 -0
- data/lib/ruby_lokalise_api/collections/segments.rb +10 -0
- data/lib/ruby_lokalise_api/collections/snapshots.rb +10 -0
- data/lib/ruby_lokalise_api/collections/system_languages.rb +11 -0
- data/lib/ruby_lokalise_api/collections/tasks.rb +10 -0
- data/lib/ruby_lokalise_api/collections/team_user_groups.rb +11 -0
- data/lib/ruby_lokalise_api/collections/team_users.rb +10 -0
- data/lib/ruby_lokalise_api/collections/teams.rb +10 -0
- data/lib/ruby_lokalise_api/collections/translation_providers.rb +10 -0
- data/lib/ruby_lokalise_api/collections/translations.rb +10 -0
- data/lib/ruby_lokalise_api/collections/webhooks.rb +10 -0
- data/lib/ruby_lokalise_api/concerns/attrs_loadable.rb +31 -0
- data/lib/ruby_lokalise_api/concerns/hash_accessible.rb +16 -0
- data/lib/ruby_lokalise_api/concerns/unsupportable.rb +16 -0
- data/lib/ruby_lokalise_api/connection.rb +18 -9
- data/lib/ruby_lokalise_api/data/collection_attributes.yml +52 -0
- data/lib/ruby_lokalise_api/data/{attributes.yml → resource_attributes.yml} +64 -6
- data/lib/ruby_lokalise_api/endpoints/base_endpoint.rb +66 -0
- data/lib/ruby_lokalise_api/endpoints/branches_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/contributors_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/custom_translation_statuses_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/files_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/jwts_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/key_comments_endpoint.rb +17 -0
- data/lib/ruby_lokalise_api/endpoints/keys_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/main_endpoint.rb +25 -0
- data/lib/ruby_lokalise_api/endpoints/oauth2/oauth2_endpoint.rb +33 -0
- data/lib/ruby_lokalise_api/endpoints/orders_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/payment_cards_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/project_comments_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/project_languages_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/projects_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/queued_processes_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/screenshots_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/segments_endpoint.rb +17 -0
- data/lib/ruby_lokalise_api/endpoints/snapshots_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/system_languages_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/tasks_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/team_user_billing_details_endpoint.rb +15 -0
- data/lib/ruby_lokalise_api/endpoints/team_user_groups_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/team_users_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/teams_endpoint.rb +13 -0
- data/lib/ruby_lokalise_api/endpoints/translation_providers_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/translations_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/endpoints/webhooks_endpoint.rb +16 -0
- data/lib/ruby_lokalise_api/error.rb +1 -0
- data/lib/ruby_lokalise_api/generics.rb +25 -0
- data/lib/ruby_lokalise_api/json_handler.rb +1 -2
- data/lib/ruby_lokalise_api/oauth2/auth.rb +33 -39
- data/lib/ruby_lokalise_api/oauth2_client.rb +3 -0
- data/lib/ruby_lokalise_api/request.rb +66 -18
- data/lib/ruby_lokalise_api/resources/base.rb +41 -181
- data/lib/ruby_lokalise_api/resources/branch.rb +2 -21
- data/lib/ruby_lokalise_api/resources/comment.rb +11 -0
- data/lib/ruby_lokalise_api/resources/contributor.rb +1 -9
- data/lib/ruby_lokalise_api/resources/custom_translation_status.rb +1 -13
- data/lib/ruby_lokalise_api/resources/file.rb +2 -16
- data/lib/ruby_lokalise_api/resources/jwt.rb +2 -5
- data/lib/ruby_lokalise_api/resources/key.rb +5 -8
- data/lib/ruby_lokalise_api/resources/oauth2_refreshed_token.rb +9 -0
- data/lib/ruby_lokalise_api/resources/oauth2_token.rb +9 -0
- data/lib/ruby_lokalise_api/resources/order.rb +2 -9
- data/lib/ruby_lokalise_api/resources/payment_card.rb +2 -8
- data/lib/ruby_lokalise_api/resources/project.rb +85 -16
- data/lib/ruby_lokalise_api/resources/project_language.rb +2 -10
- data/lib/ruby_lokalise_api/resources/queued_process.rb +3 -10
- data/lib/ruby_lokalise_api/resources/screenshot.rb +1 -9
- data/lib/ruby_lokalise_api/resources/segment.rb +2 -11
- data/lib/ruby_lokalise_api/resources/snapshot.rb +3 -18
- data/lib/ruby_lokalise_api/resources/system_language.rb +2 -1
- data/lib/ruby_lokalise_api/resources/task.rb +1 -9
- data/lib/ruby_lokalise_api/resources/team.rb +2 -0
- data/lib/ruby_lokalise_api/resources/team_user.rb +1 -9
- data/lib/ruby_lokalise_api/resources/team_user_billing_details.rb +10 -5
- data/lib/ruby_lokalise_api/resources/team_user_group.rb +6 -14
- data/lib/ruby_lokalise_api/resources/translation.rb +2 -9
- data/lib/ruby_lokalise_api/resources/translation_provider.rb +2 -9
- data/lib/ruby_lokalise_api/resources/webhook.rb +2 -16
- data/lib/ruby_lokalise_api/response.rb +50 -0
- data/lib/ruby_lokalise_api/rest/branches.rb +52 -27
- data/lib/ruby_lokalise_api/rest/comments.rb +48 -23
- data/lib/ruby_lokalise_api/rest/contributors.rb +47 -23
- data/lib/ruby_lokalise_api/rest/custom_translation_statuses.rb +60 -36
- data/lib/ruby_lokalise_api/rest/files.rb +43 -24
- data/lib/ruby_lokalise_api/rest/jwts.rb +21 -0
- data/lib/ruby_lokalise_api/rest/keys.rb +67 -34
- data/lib/ruby_lokalise_api/rest/languages.rb +57 -28
- data/lib/ruby_lokalise_api/rest/orders.rb +36 -14
- data/lib/ruby_lokalise_api/rest/payment_cards.rb +29 -12
- data/lib/ruby_lokalise_api/rest/projects.rb +55 -32
- data/lib/ruby_lokalise_api/rest/queued_processes.rb +21 -13
- data/lib/ruby_lokalise_api/rest/screenshots.rb +45 -20
- data/lib/ruby_lokalise_api/rest/segments.rb +31 -18
- data/lib/ruby_lokalise_api/rest/snapshots.rb +34 -14
- data/lib/ruby_lokalise_api/rest/tasks.rb +41 -19
- data/lib/ruby_lokalise_api/rest/team_user_billing_details.rb +33 -12
- data/lib/ruby_lokalise_api/rest/team_user_groups.rb +82 -50
- data/lib/ruby_lokalise_api/rest/team_users.rb +35 -18
- data/lib/ruby_lokalise_api/rest/teams.rb +10 -5
- data/lib/ruby_lokalise_api/rest/translation_providers.rb +24 -9
- data/lib/ruby_lokalise_api/rest/translations.rb +28 -15
- data/lib/ruby_lokalise_api/rest/webhooks.rb +54 -30
- data/lib/ruby_lokalise_api/rest.rb +31 -0
- data/lib/ruby_lokalise_api/utils/attributes.rb +37 -0
- data/lib/ruby_lokalise_api/utils/classes.rb +24 -0
- data/lib/ruby_lokalise_api/utils/keys.rb +29 -0
- data/lib/ruby_lokalise_api/utils/loaders.rb +24 -0
- data/lib/ruby_lokalise_api/utils/strings.rb +20 -0
- data/lib/ruby_lokalise_api/version.rb +1 -1
- data/lib/ruby_lokalise_api.rb +6 -2
- data/ruby-lokalise-api.gemspec +2 -2
- metadata +76 -41
- data/lib/ruby_lokalise_api/base_request.rb +0 -73
- data/lib/ruby_lokalise_api/collections/branch.rb +0 -15
- data/lib/ruby_lokalise_api/collections/contributor.rb +0 -13
- data/lib/ruby_lokalise_api/collections/custom_translation_status.rb +0 -15
- data/lib/ruby_lokalise_api/collections/file.rb +0 -13
- data/lib/ruby_lokalise_api/collections/key.rb +0 -20
- data/lib/ruby_lokalise_api/collections/key_comment.rb +0 -14
- data/lib/ruby_lokalise_api/collections/order.rb +0 -13
- data/lib/ruby_lokalise_api/collections/payment_card.rb +0 -13
- data/lib/ruby_lokalise_api/collections/project.rb +0 -13
- data/lib/ruby_lokalise_api/collections/project_comment.rb +0 -13
- data/lib/ruby_lokalise_api/collections/project_language.rb +0 -13
- data/lib/ruby_lokalise_api/collections/queued_process.rb +0 -15
- data/lib/ruby_lokalise_api/collections/screenshot.rb +0 -13
- data/lib/ruby_lokalise_api/collections/segment.rb +0 -15
- data/lib/ruby_lokalise_api/collections/snapshot.rb +0 -13
- data/lib/ruby_lokalise_api/collections/system_language.rb +0 -13
- data/lib/ruby_lokalise_api/collections/task.rb +0 -13
- data/lib/ruby_lokalise_api/collections/team.rb +0 -13
- data/lib/ruby_lokalise_api/collections/team_user.rb +0 -13
- data/lib/ruby_lokalise_api/collections/team_user_group.rb +0 -15
- data/lib/ruby_lokalise_api/collections/translation.rb +0 -13
- data/lib/ruby_lokalise_api/collections/translation_provider.rb +0 -13
- data/lib/ruby_lokalise_api/collections/webhook.rb +0 -13
- data/lib/ruby_lokalise_api/oauth2/refresh.rb +0 -16
- data/lib/ruby_lokalise_api/oauth2/token.rb +0 -16
- data/lib/ruby_lokalise_api/resources/key_comment.rb +0 -19
- data/lib/ruby_lokalise_api/resources/project_comment.rb +0 -10
- data/lib/ruby_lokalise_api/rest/jwt.rb +0 -15
- data/lib/ruby_lokalise_api/utils/attribute_helpers.rb +0 -86
- data/lib/ruby_lokalise_api/utils/endpoint_helpers.rb +0 -14
- data/lib/ruby_lokalise_api/utils/string_utils.rb +0 -33
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class SegmentsEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(project_id, key_id, language_iso, segment_number = nil)
|
9
|
+
{
|
10
|
+
projects: project_id,
|
11
|
+
keys: key_id,
|
12
|
+
segments: [language_iso, segment_number]
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class SnapshotsEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(project_id, snapshot_id = nil)
|
9
|
+
{
|
10
|
+
projects: project_id,
|
11
|
+
snapshots: snapshot_id
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class TeamUserGroupsEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(team_id, group_id = nil, *actions)
|
9
|
+
{
|
10
|
+
teams: team_id,
|
11
|
+
groups: [group_id, actions]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class TranslationProvidersEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(team_id, provider_id = nil)
|
9
|
+
{
|
10
|
+
teams: team_id,
|
11
|
+
translation_providers: provider_id
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class TranslationsEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(project_id, translation_id = nil)
|
9
|
+
{
|
10
|
+
projects: project_id,
|
11
|
+
translations: translation_id
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Endpoints
|
5
|
+
class WebhooksEndpoint < MainEndpoint
|
6
|
+
private
|
7
|
+
|
8
|
+
def base_query(project_id, webhook_id = nil, *actions)
|
9
|
+
{
|
10
|
+
projects: project_id,
|
11
|
+
webhooks: [webhook_id, actions]
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
# Simple generic objects to decorate certain responses (usually, related to data deletion)
|
5
|
+
class Generics
|
6
|
+
include RubyLokaliseApi::Concerns::HashAccessible
|
7
|
+
|
8
|
+
DeletedResource = Class.new(self)
|
9
|
+
EmptiedResource = Class.new(self)
|
10
|
+
CustomStatusAvailableColors = Class.new(self)
|
11
|
+
DownloadBundle = Class.new(self)
|
12
|
+
MergedBranches = Class.new(self)
|
13
|
+
RegeneratedWebhookSecret = Class.new(self)
|
14
|
+
|
15
|
+
def initialize(raw_data)
|
16
|
+
raw_data.each do |att, val|
|
17
|
+
instance_variable_set "@#{att}", val
|
18
|
+
|
19
|
+
self.class.class_exec do
|
20
|
+
attr_reader att.to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module RubyLokaliseApi
|
6
|
+
# JSON custom parser. Uses built-in JSON by default but can be overridden to any other parser
|
6
7
|
module JsonHandler
|
7
|
-
# JSON custom parser. Uses built-in JSON by default but can be overridden to any other parser
|
8
|
-
|
9
8
|
# Converts Ruby object to JSON
|
10
9
|
def custom_dump(obj)
|
11
10
|
JSON.dump obj
|
@@ -3,10 +3,10 @@
|
|
3
3
|
module RubyLokaliseApi
|
4
4
|
module OAuth2
|
5
5
|
class Auth
|
6
|
-
include RubyLokaliseApi::BaseRequest
|
7
|
-
|
8
6
|
attr_reader :client_id, :client_secret, :timeout, :open_timeout
|
9
7
|
|
8
|
+
OAUTH2_ENDPOINT = RubyLokaliseApi::Endpoints::OAuth2::OAuth2Endpoint
|
9
|
+
|
10
10
|
def initialize(client_id, client_secret, params = {})
|
11
11
|
@client_id = client_id
|
12
12
|
@client_secret = client_secret
|
@@ -14,61 +14,55 @@ module RubyLokaliseApi
|
|
14
14
|
@open_timeout = params[:open_timeout]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
|
17
|
+
def oauth2_endpoint
|
18
|
+
self.class.const_get(:OAUTH2_ENDPOINT)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
def auth(scope:, redirect_uri: nil, state: nil)
|
22
|
+
get_params = {
|
21
23
|
client_id: client_id,
|
22
|
-
scope: scope
|
24
|
+
scope: (scope.is_a?(Array) ? scope.join(' ') : scope),
|
25
|
+
state: state,
|
26
|
+
redirect_uri: redirect_uri
|
23
27
|
}
|
24
|
-
params[:state] = state unless state.nil?
|
25
|
-
params[:redirect_uri] = redirect_uri unless redirect_uri.nil?
|
26
28
|
|
27
|
-
|
29
|
+
oauth2_endpoint.new(self, query: 'auth', get: get_params).full_uri
|
28
30
|
end
|
29
31
|
|
30
32
|
def token(code)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def refresh(token)
|
40
|
-
params = base_params.merge({
|
41
|
-
refresh_token: token,
|
42
|
-
grant_type: 'refresh_token'
|
43
|
-
})
|
33
|
+
endpoint = oauth2_endpoint.new(
|
34
|
+
self,
|
35
|
+
query: :token,
|
36
|
+
req: common_params.merge(
|
37
|
+
grant_type: 'authorization_code',
|
38
|
+
code: code
|
39
|
+
)
|
40
|
+
)
|
44
41
|
|
45
|
-
RubyLokaliseApi::
|
42
|
+
RubyLokaliseApi::Resources::OAuth2Token.new endpoint.do_post
|
46
43
|
end
|
47
44
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
45
|
+
def refresh(refresh_token)
|
46
|
+
endpoint = oauth2_endpoint.new(
|
47
|
+
self,
|
48
|
+
query: :token,
|
49
|
+
req: common_params.merge(
|
50
|
+
grant_type: 'refresh_token',
|
51
|
+
refresh_token: refresh_token
|
52
|
+
)
|
53
|
+
)
|
51
54
|
|
52
|
-
|
53
|
-
false
|
55
|
+
RubyLokaliseApi::Resources::OAuth2RefreshedToken.new endpoint.do_post
|
54
56
|
end
|
55
57
|
|
56
58
|
private
|
57
59
|
|
58
|
-
def
|
60
|
+
def common_params
|
59
61
|
{
|
60
|
-
client_id: client_id,
|
61
|
-
client_secret: client_secret
|
62
|
+
client_id: @client_id,
|
63
|
+
client_secret: @client_secret
|
62
64
|
}
|
63
65
|
end
|
64
|
-
|
65
|
-
def _build_url_from(params)
|
66
|
-
URI::HTTPS.build(
|
67
|
-
host: base_url.host,
|
68
|
-
path: "#{base_url.path}auth",
|
69
|
-
query: URI.encode_www_form(params)
|
70
|
-
).to_s
|
71
|
-
end
|
72
66
|
end
|
73
67
|
end
|
74
68
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
|
+
# Client used to perform API requests with an OAuth2 access token
|
4
5
|
class OAuth2Client < Client
|
6
|
+
include RubyLokaliseApi::Rest
|
7
|
+
|
5
8
|
def initialize(token, params = {})
|
6
9
|
super(token, params)
|
7
10
|
@token_header = 'Authorization'
|
@@ -1,31 +1,79 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
|
+
# Contains methods to perform the actual HTTP requests
|
4
5
|
module Request
|
5
|
-
include RubyLokaliseApi::
|
6
|
+
include RubyLokaliseApi::JsonHandler
|
7
|
+
include RubyLokaliseApi::Connection
|
6
8
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
9
|
+
# Sends a GET request
|
10
|
+
def get(endpoint)
|
11
|
+
respond_with(
|
12
|
+
connection(endpoint).get(prepare(endpoint.uri), endpoint.req_params),
|
13
|
+
endpoint
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sends a POST request
|
18
|
+
def post(endpoint)
|
19
|
+
respond_with(
|
20
|
+
connection(endpoint).post(prepare(endpoint.uri), custom_dump(endpoint.req_params)),
|
21
|
+
endpoint
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sends a PUT request
|
26
|
+
def put(endpoint)
|
27
|
+
respond_with(
|
28
|
+
connection(endpoint).put(prepare(endpoint.uri), custom_dump(endpoint.req_params)),
|
29
|
+
endpoint
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sends a PATCH request
|
34
|
+
def patch(endpoint)
|
35
|
+
respond_with(
|
36
|
+
connection(endpoint).patch(prepare(endpoint.uri),
|
37
|
+
endpoint.req_params.nil? ? nil : custom_dump(endpoint.req_params)),
|
38
|
+
endpoint
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sends a DELETE request
|
43
|
+
def delete(endpoint)
|
44
|
+
respond_with(
|
45
|
+
connection(endpoint).delete(prepare(endpoint.uri)) do |req|
|
46
|
+
req.body = custom_dump endpoint.req_params
|
47
|
+
end,
|
48
|
+
endpoint
|
49
|
+
)
|
50
|
+
end
|
10
51
|
|
11
52
|
private
|
12
53
|
|
13
|
-
|
54
|
+
# Get rid of double slashes in the `path`, leading and trailing slash
|
55
|
+
def prepare(path)
|
56
|
+
path.delete_prefix('/').gsub(%r{//}, '/').gsub(%r{/+\z}, '')
|
57
|
+
end
|
58
|
+
|
59
|
+
def raise_on_error!(response, body)
|
60
|
+
return unless !response.success? || (body.respond_to?(:has_key?) && body.key?('error'))
|
61
|
+
|
62
|
+
respond_with_error(response.status, body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def respond_with(response, endpoint)
|
14
66
|
body = custom_load response.body
|
15
|
-
|
67
|
+
|
16
68
|
raise_on_error! response, body
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
response.
|
26
|
-
headers.
|
27
|
-
to_h.
|
28
|
-
keep_if { |k, _v| PAGINATION_HEADERS.include?(k) }
|
69
|
+
|
70
|
+
RubyLokaliseApi::Response.new(body, endpoint, response.headers)
|
71
|
+
end
|
72
|
+
|
73
|
+
def respond_with_error(code, body)
|
74
|
+
raise(RubyLokaliseApi::Error, body['error'] || body) unless RubyLokaliseApi::Error::ERRORS.key? code
|
75
|
+
|
76
|
+
raise RubyLokaliseApi::Error::ERRORS[code].from_response(body)
|
29
77
|
end
|
30
78
|
end
|
31
79
|
end
|