ruby-lokalise-api 7.2.0 → 8.0.0
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 +32 -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 +17 -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 +48 -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 -185
- 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 +28 -0
- data/lib/ruby_lokalise_api/utils/keys.rb +33 -0
- data/lib/ruby_lokalise_api/utils/loaders.rb +27 -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 +3 -3
- metadata +76 -47
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95932448d2e531abc5dc2f30a4b7f1052fa9ba7b37a80e57a46117ac7102c453
|
4
|
+
data.tar.gz: d5101a2713268265021177c3bcb1eaa1adcfaaa2afe605d87747d55a5c4a6ec0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d290aa2c9844f3e8db8099968104845f7f7b7a52c96843b7f400124819031c3021acec02a318004079548b2666e3253cae845d447825cb5acf04d7cee43234
|
7
|
+
data.tar.gz: f2790492035aa26cd353372008fe8b4d41cecd47382700ec339e57d443cb5e637be24dc299ea7a1c9898f5c2446722a5709e79e684c081b1ee730d595788fb5e
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
|
+
# This class contains the base client. Inherited by Client (regular API client)
|
5
|
+
# and OAuth2Client (used for OAuth-2 based authentication)
|
4
6
|
class BaseClient
|
5
7
|
attr_reader :token, :token_header
|
6
8
|
attr_accessor :timeout, :open_timeout
|
@@ -11,39 +13,5 @@ module RubyLokaliseApi
|
|
11
13
|
@open_timeout = params.fetch(:open_timeout, nil)
|
12
14
|
@token_header = ''
|
13
15
|
end
|
14
|
-
|
15
|
-
# rubocop:disable Metrics/ParameterLists
|
16
|
-
# Constructs request to perform the specified action
|
17
|
-
# @param klass The actual class to call the method upon
|
18
|
-
# @param method [Symbol] The method to call (:new, :update, :create etc)
|
19
|
-
# @param endpoint_ids [Array, Hash] IDs that are used to generate the proper path to the endpoint
|
20
|
-
# @param params [Array, Hash] Request parameters
|
21
|
-
# @param object_key [String, Symbol] Key that should be used to wrap parameters into
|
22
|
-
# @param initial_ids [Array] IDs that should be used to generate base endpoint path.
|
23
|
-
# The base path is used for method chaining
|
24
|
-
def construct_request(klass, method, endpoint_ids, params = {}, object_key = nil, initial_ids = nil)
|
25
|
-
path = klass.endpoint(*endpoint_ids)
|
26
|
-
formatted_params = format_params(params, object_key)
|
27
|
-
formatted_params[:_initial_path] = klass.endpoint(*initial_ids) if initial_ids
|
28
|
-
klass.send method, self, path, formatted_params
|
29
|
-
end
|
30
|
-
# rubocop:enable Metrics/ParameterLists
|
31
|
-
|
32
|
-
# Converts `params` to hash with arrays under the `object_key` key.
|
33
|
-
# Used in bulk operations
|
34
|
-
#
|
35
|
-
# @return [Hash]
|
36
|
-
def format_params(params, object_key)
|
37
|
-
return params unless object_key
|
38
|
-
|
39
|
-
params = [params] unless params.is_a?(Array)
|
40
|
-
{object_key => params}
|
41
|
-
end
|
42
|
-
|
43
|
-
def base_url; end
|
44
|
-
|
45
|
-
def compression?; end
|
46
|
-
|
47
|
-
alias c_r construct_request
|
48
16
|
end
|
49
17
|
end
|
@@ -1,43 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
|
+
# Regular API client used to perform requests with a basic API token
|
4
5
|
class Client < BaseClient
|
5
|
-
include RubyLokaliseApi::Rest
|
6
|
-
include RubyLokaliseApi::Rest::Comments
|
7
|
-
include RubyLokaliseApi::Rest::Contributors
|
8
|
-
include RubyLokaliseApi::Rest::CustomTranslationStatuses
|
9
|
-
include RubyLokaliseApi::Rest::Files
|
10
|
-
include RubyLokaliseApi::Rest::Jwt
|
11
|
-
include RubyLokaliseApi::Rest::Keys
|
12
|
-
include RubyLokaliseApi::Rest::Languages
|
13
|
-
include RubyLokaliseApi::Rest::Orders
|
14
|
-
include RubyLokaliseApi::Rest::PaymentCards
|
15
|
-
include RubyLokaliseApi::Rest::Projects
|
16
|
-
include RubyLokaliseApi::Rest::QueuedProcesses
|
17
|
-
include RubyLokaliseApi::Rest::Screenshots
|
18
|
-
include RubyLokaliseApi::Rest::Segments
|
19
|
-
include RubyLokaliseApi::Rest::Snapshots
|
20
|
-
include RubyLokaliseApi::Rest::Tasks
|
21
|
-
include RubyLokaliseApi::Rest::TeamUserBillingDetails
|
22
|
-
include RubyLokaliseApi::Rest::TeamUserGroups
|
23
|
-
include RubyLokaliseApi::Rest::TeamUsers
|
24
|
-
include RubyLokaliseApi::Rest::Teams
|
25
|
-
include RubyLokaliseApi::Rest::TranslationProviders
|
26
|
-
include RubyLokaliseApi::Rest::Translations
|
27
|
-
include RubyLokaliseApi::Rest::Webhooks
|
6
|
+
include RubyLokaliseApi::Rest
|
28
7
|
|
29
8
|
def initialize(token, params = {})
|
30
9
|
super(token, params)
|
31
10
|
|
32
11
|
@token_header = 'x-api-token'
|
33
12
|
end
|
34
|
-
|
35
|
-
def base_url
|
36
|
-
'https://api.lokalise.com/api2/'
|
37
|
-
end
|
38
|
-
|
39
|
-
def compression?
|
40
|
-
true
|
41
|
-
end
|
42
13
|
end
|
43
14
|
end
|
@@ -2,116 +2,143 @@
|
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
4
|
module Collections
|
5
|
+
# Base collection. Collection is an array of resources. The actual resources can be found
|
6
|
+
# by calling the `.collection` method
|
5
7
|
class Base
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
extend RubyLokaliseApi::
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def initialize(response
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
8
|
+
include Enumerable
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
using RubyLokaliseApi::Utils::Classes
|
12
|
+
extend RubyLokaliseApi::Utils::Attributes
|
13
|
+
extend RubyLokaliseApi::Concerns::AttrsLoadable
|
14
|
+
include RubyLokaliseApi::Utils::Keys
|
15
|
+
|
16
|
+
ATTRS_FILENAME = 'collection_attributes.yml'
|
17
|
+
|
18
|
+
def_delegators :collection, :[], :last, :each
|
19
|
+
|
20
|
+
attr_reader :total_pages, :total_results, :results_per_page, :current_page,
|
21
|
+
:collection
|
22
|
+
|
23
|
+
def initialize(response)
|
24
|
+
@self_endpoint = response.endpoint
|
25
|
+
|
26
|
+
populate_common_attrs_from response
|
27
|
+
produce_collection_from response
|
26
28
|
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
# Tries to fetch the next page for paginated collection
|
31
|
+
# Returns a new collection or nil if the next page is not available
|
32
|
+
def next_page
|
33
|
+
return nil if last_page?
|
34
|
+
|
35
|
+
self.class.new(
|
36
|
+
reinit_endpoint(
|
37
|
+
override_req_params: { page: current_page + 1 }
|
38
|
+
).do_get
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Tries to fetch the previous page for paginated collection
|
43
|
+
# Returns a new collection or nil if the previous page is not available
|
44
|
+
def prev_page
|
45
|
+
return nil if first_page?
|
46
|
+
|
47
|
+
self.class.new(
|
48
|
+
reinit_endpoint(
|
49
|
+
override_req_params: { page: current_page - 1 }
|
50
|
+
).do_get
|
51
|
+
)
|
34
52
|
end
|
35
53
|
|
54
|
+
# Checks whether the next page is available
|
36
55
|
# @return [Boolean]
|
37
56
|
def next_page?
|
38
|
-
|
57
|
+
current_page.positive? && current_page < total_pages
|
39
58
|
end
|
40
59
|
|
60
|
+
# Checks whether the current page is the last one
|
41
61
|
# @return [Boolean]
|
42
62
|
def last_page?
|
43
63
|
!next_page?
|
44
64
|
end
|
45
65
|
|
66
|
+
# Checks whether the previous page is available
|
46
67
|
# @return [Boolean]
|
47
68
|
def prev_page?
|
48
|
-
|
69
|
+
current_page > 1
|
49
70
|
end
|
50
71
|
|
72
|
+
# Checks whether the current page is the first one
|
51
73
|
# @return [Boolean]
|
52
74
|
def first_page?
|
53
75
|
!prev_page?
|
54
76
|
end
|
55
77
|
|
56
|
-
|
57
|
-
def next_page
|
58
|
-
return nil if last_page?
|
78
|
+
private
|
59
79
|
|
60
|
-
|
80
|
+
# This method is utilized to recreate an endpoint for the current collection
|
81
|
+
def reinit_endpoint(req_params: @self_endpoint.req_params, override_req_params: {})
|
82
|
+
@self_endpoint.reinitialize(
|
83
|
+
req_params: req_params.merge(override_req_params)
|
84
|
+
)
|
61
85
|
end
|
62
86
|
|
63
|
-
|
64
|
-
|
65
|
-
|
87
|
+
def populate_common_attrs_from(response)
|
88
|
+
supported_attrs.each do |attrib|
|
89
|
+
instance_variable_set "@#{attrib}", response.content[attrib]
|
90
|
+
end
|
91
|
+
|
92
|
+
headers = response.headers
|
66
93
|
|
67
|
-
|
94
|
+
return unless headers.any?
|
95
|
+
|
96
|
+
@total_results = headers[:'x-pagination-total-count']
|
97
|
+
@total_pages = headers[:'x-pagination-page-count']
|
98
|
+
@results_per_page = headers[:'x-pagination-limit']
|
99
|
+
@current_page = headers[:'x-pagination-page']
|
68
100
|
end
|
69
101
|
|
70
|
-
|
102
|
+
def produce_collection_from(response)
|
103
|
+
content = response.content
|
104
|
+
return unless content
|
105
|
+
|
106
|
+
data_key_plural = collection_key_for klass: self.class.base_name
|
107
|
+
|
108
|
+
resources_data = content[data_key_plural]
|
109
|
+
other_data = content.reject { |key, _| key == data_key_plural }
|
71
110
|
|
72
|
-
|
73
|
-
@total_results = response['x-pagination-total-count'].to_i
|
74
|
-
@total_pages = response['x-pagination-page-count'].to_i
|
75
|
-
@results_per_page = response['x-pagination-limit'].to_i
|
76
|
-
@current_page = response['x-pagination-page'].to_i
|
111
|
+
@collection = build_collection resources_data, other_data
|
77
112
|
end
|
78
113
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
@request_params.merge(page: page_num)
|
114
|
+
def build_collection(resources_data, other_data)
|
115
|
+
resources_data.map do |raw_resource|
|
116
|
+
self.class.const_get(:RESOURCE).new(resource_data(raw_resource, other_data))
|
117
|
+
end
|
84
118
|
end
|
85
119
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
120
|
+
def resource_data(raw_resource, other_data)
|
121
|
+
RubyLokaliseApi::Response.new(
|
122
|
+
raw_resource.merge(other_data),
|
123
|
+
resource_endpoint.new(
|
124
|
+
@self_endpoint.client,
|
125
|
+
query: query_for(raw_resource, other_data)
|
126
|
+
)
|
127
|
+
)
|
128
|
+
end
|
90
129
|
|
91
|
-
|
92
|
-
|
130
|
+
def query_for(raw_resource, other_data)
|
131
|
+
main_params = self.class.const_get(:RESOURCE).const_get(:MAIN_PARAMS).to_array
|
93
132
|
|
94
|
-
|
95
|
-
|
96
|
-
@collection = response['content'][data_key_plural].map do |raw_model|
|
97
|
-
Module.const_get("RubyLokaliseApi::Resources::#{model_class}").new 'content' => raw_model,
|
98
|
-
'client' => response['client'],
|
99
|
-
'base_path' => response['path']
|
133
|
+
main_params.map do |param|
|
134
|
+
other_data[param.to_s] || raw_resource[param.to_s] || nil
|
100
135
|
end
|
101
136
|
end
|
102
137
|
|
103
|
-
def
|
104
|
-
|
105
|
-
@path = response['path']
|
106
|
-
|
107
|
-
return unless response['content']
|
138
|
+
def resource_endpoint
|
139
|
+
klass = self.class
|
108
140
|
|
109
|
-
|
110
|
-
# Project, team id, user id, and branch may not be present in some cases
|
111
|
-
@project_id = content['project_id']
|
112
|
-
@team_id = content['team_id']
|
113
|
-
@user_id = content['user_id']
|
114
|
-
@branch = content['branch']
|
141
|
+
klass.const_defined?(:RESOURCES_ENDPOINT) ? klass.const_get(:RESOURCES_ENDPOINT) : klass.const_get(:ENDPOINT)
|
115
142
|
end
|
116
143
|
end
|
117
144
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class CustomTranslationStatuses < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::CustomTranslationStatusesEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::CustomTranslationStatus
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class ProjectComments < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::ProjectCommentsEndpoint
|
7
|
+
RESOURCES_ENDPOINT = RubyLokaliseApi::Endpoints::KeyCommentsEndpoint
|
8
|
+
RESOURCE = RubyLokaliseApi::Resources::Comment
|
9
|
+
DATA_KEY = 'comments'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class ProjectLanguages < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::ProjectLanguagesEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::ProjectLanguage
|
8
|
+
DATA_KEY = 'languages'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class QueuedProcesses < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::QueuedProcessesEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::QueuedProcess
|
8
|
+
DATA_KEY = 'processes'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class SystemLanguages < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::SystemLanguagesEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::SystemLanguage
|
8
|
+
DATA_KEY = 'languages'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class TeamUserGroups < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::TeamUserGroupsEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::TeamUserGroup
|
8
|
+
DATA_KEY = 'user_groups'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Collections
|
5
|
+
class TranslationProviders < Base
|
6
|
+
ENDPOINT = RubyLokaliseApi::Endpoints::TranslationProvidersEndpoint
|
7
|
+
RESOURCE = RubyLokaliseApi::Resources::TranslationProvider
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Concerns
|
5
|
+
# Allows to set supported attributes for classes
|
6
|
+
module AttrsLoadable
|
7
|
+
class << self
|
8
|
+
def extended(klass)
|
9
|
+
klass.class_exec do
|
10
|
+
define_method :supported_attrs do
|
11
|
+
that_klass = self.class
|
12
|
+
that_klass.const_defined?(:ATTRS) ? that_klass.const_get(:ATTRS) : []
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def inherited(subclass)
|
19
|
+
klass_attributes = attributes_for subclass, const_get(:ATTRS_FILENAME)
|
20
|
+
|
21
|
+
if klass_attributes&.any?
|
22
|
+
subclass.class_exec do
|
23
|
+
const_set :ATTRS, klass_attributes
|
24
|
+
attr_reader(*klass_attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Concerns
|
5
|
+
# Adds the `[]` method for invariant access
|
6
|
+
module HashAccessible
|
7
|
+
def [](raw_key_attr)
|
8
|
+
key_attr = :"@#{raw_key_attr}"
|
9
|
+
|
10
|
+
return nil unless instance_variables.include?(key_attr) && respond_to?(raw_key_attr.to_sym)
|
11
|
+
|
12
|
+
instance_variable_get(key_attr)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyLokaliseApi
|
4
|
+
module Concerns
|
5
|
+
# Allows to undefine certain methods
|
6
|
+
module Unsupportable
|
7
|
+
def no_support_for(methods)
|
8
|
+
return unless methods.any?
|
9
|
+
|
10
|
+
methods.each do |method|
|
11
|
+
undef_method(method)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|