ruby-lokalise-api 9.1.0 → 9.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f104ba9751dfab41967f0a7c766d4cb631a9219ae6a7d6f791b48dd3f68b171
4
- data.tar.gz: 25416c89c5b24ca8439050a7adec02568eb5a6ed1379b6703957706dd33b4431
3
+ metadata.gz: 2dec4243f98c519d1dfb8d66de1d6d7cb6794d97e6ed1f7e8962d72ad141af1f
4
+ data.tar.gz: b2a1468269686f8e2fada398cbd19cb69e92e243aa968d5c70beec61fc43fb6f
5
5
  SHA512:
6
- metadata.gz: 9787b6d1bd962049fa0c1963a348dffa370dc03c23dfc1799688999128d5552f7bad9cc149cd204020ae04e5ff1301ca7a87208eb9cbd40f7fa78dbf2131e32e
7
- data.tar.gz: 26e9576d4b8f554954f7d1486c8abad86bab2c1cdde67aa7d57c8f8aa71b6eef3a3477e467e081d6b12c618d6239ea9c585e19e16a7d8f5633a91d3e7c7fc60c
6
+ metadata.gz: 4398fd7dfcde203df5e13af5c60fff8d22870c28b19bf97ffae1368123e531fbf4b843cbd8a67222de9ec37d507ff117bebb2c44004621102b85544884e1abcd
7
+ data.tar.gz: bd21d0e1072fd0dbda803c0eb93040de9c3a5e4c30f7684b31146c7a412994eb86d877f3c85b83014ce85bc9a7e6ca79acec3e4a9cfb37889f0568149a9022f5
@@ -4,7 +4,7 @@ module RubyLokaliseApi
4
4
  # Regular API client used to perform requests with a basic API token
5
5
  class Client < BaseClient
6
6
  def initialize(token, params = {})
7
- super(token, params)
7
+ super
8
8
 
9
9
  @token_header = 'x-api-token'
10
10
  end
@@ -32,13 +32,7 @@ module RubyLokaliseApi
32
32
  def next_page
33
33
  return nil if last_page?
34
34
 
35
- override_params = { page: current_page + 1 }
36
-
37
- self.class.new(
38
- reinit_endpoint(
39
- override_req_params: override_params
40
- ).do_get
41
- )
35
+ fetch_page(current_page + 1)
42
36
  end
43
37
 
44
38
  # Tries to fetch the next cursor for paginated collection
@@ -46,13 +40,7 @@ module RubyLokaliseApi
46
40
  def load_next_cursor
47
41
  return nil unless next_cursor?
48
42
 
49
- override_params = { cursor: next_cursor }
50
-
51
- self.class.new(
52
- reinit_endpoint(
53
- override_req_params: override_params
54
- ).do_get
55
- )
43
+ fetch_cursor(next_cursor)
56
44
  end
57
45
 
58
46
  # Tries to fetch the previous page for paginated collection
@@ -60,11 +48,7 @@ module RubyLokaliseApi
60
48
  def prev_page
61
49
  return nil if first_page?
62
50
 
63
- self.class.new(
64
- reinit_endpoint(
65
- override_req_params: { page: current_page - 1 }
66
- ).do_get
67
- )
51
+ fetch_page(current_page - 1)
68
52
  end
69
53
 
70
54
  # Checks whether the next page is available
@@ -131,7 +115,7 @@ module RubyLokaliseApi
131
115
  data_key_plural = collection_key_for klass: self.class.base_name
132
116
 
133
117
  resources_data = content[data_key_plural]
134
- other_data = content.reject { |key, _| key == data_key_plural }
118
+ other_data = content.except(data_key_plural)
135
119
 
136
120
  @collection = build_collection resources_data, other_data
137
121
  end
@@ -165,6 +149,16 @@ module RubyLokaliseApi
165
149
 
166
150
  klass.const_defined?(:RESOURCES_ENDPOINT) ? klass.const_get(:RESOURCES_ENDPOINT) : klass.const_get(:ENDPOINT)
167
151
  end
152
+
153
+ # Helper method to fetch a page for paginated collections
154
+ def fetch_page(page)
155
+ self.class.new(reinit_endpoint(override_req_params: { page: page }).do_get)
156
+ end
157
+
158
+ # Helper method to fetch the next cursor
159
+ def fetch_cursor(cursor)
160
+ self.class.new(reinit_endpoint(override_req_params: { cursor: cursor }).do_get)
161
+ end
168
162
  end
169
163
  end
170
164
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Collections
5
+ class PermissionTemplates < Base
6
+ ENDPOINT = RubyLokaliseApi::Endpoints::PermissionTemplatesEndpoint
7
+ RESOURCE = RubyLokaliseApi::Resources::PermissionTemplate
8
+ DATA_KEY = 'roles'
9
+ end
10
+ end
11
+ end
@@ -4,10 +4,14 @@ module RubyLokaliseApi
4
4
  # Module to setup connection using Faraday
5
5
  module Connection
6
6
  # Creates a new Faraday object with specified params
7
+ #
8
+ # @param endpoint [Object] the API endpoint
9
+ # @param params [Hash] additional connection parameters
10
+ # @return [Faraday::Connection] the Faraday connection object
7
11
  def connection(endpoint, params = {})
8
12
  Faraday.new(options(endpoint, params), request_params_for(endpoint.client)) do |faraday|
9
13
  faraday.adapter Faraday.default_adapter
10
- faraday.request(:gzip)
14
+ faraday.request :gzip
11
15
  end
12
16
  end
13
17
 
@@ -17,19 +21,33 @@ module RubyLokaliseApi
17
21
  req_params = __base_options(endpoint)
18
22
  client = endpoint.client
19
23
 
20
- if client.respond_to?(:token) && client.respond_to?(:token_header)
21
- req_params[:headers][client.token_header] = client.token
22
- end
24
+ add_token_header(req_params, client) if client_responds_to_token?(client)
23
25
 
24
- # Sending content-type is needed only when the body is actually present
25
- # Trying to send this header in other cases seems to result in error 500
26
- req_params[:headers]['Content-type'] = 'application/json' if !params[:get_request] && endpoint.req_params
26
+ # Set Content-Type if required (skip for GET requests)
27
+ add_content_type_header(req_params, params, endpoint)
27
28
 
28
29
  req_params[:headers][:accept_encoding] = 'gzip,deflate,br'
29
30
 
30
31
  req_params
31
32
  end
32
33
 
34
+ # Adds the token header to the request parameters if token is present
35
+ def add_token_header(req_params, client)
36
+ req_params[:headers][client.token_header] = client.token
37
+ end
38
+
39
+ # Checks if the client can respond to token and token header methods
40
+ def client_responds_to_token?(client)
41
+ client.respond_to?(:token) && client.respond_to?(:token_header)
42
+ end
43
+
44
+ # Conditionally adds the Content-Type header
45
+ def add_content_type_header(req_params, params, endpoint)
46
+ return unless !params[:get_request] && endpoint.req_params
47
+
48
+ req_params[:headers]['Content-Type'] = 'application/json'
49
+ end
50
+
33
51
  def __base_options(endpoint)
34
52
  {
35
53
  headers: {
@@ -28,6 +28,7 @@ contributor:
28
28
  - is_reviewer
29
29
  - languages
30
30
  - admin_rights
31
+ - role_id
31
32
  custom_translation_status:
32
33
  - project_id
33
34
  - branch
@@ -142,6 +143,15 @@ queued_process:
142
143
  - created_at
143
144
  - created_at_timestamp
144
145
  - details
146
+ permission_template:
147
+ - id
148
+ - role
149
+ - permissions
150
+ - description
151
+ - tag
152
+ - tagColor
153
+ - tagInfo
154
+ - doesEnableAllReadOnlyLanguages
145
155
  screenshot:
146
156
  - project_id
147
157
  - branch
@@ -256,6 +266,7 @@ team_user_group:
256
266
  - team_id
257
267
  - projects
258
268
  - members
269
+ - role_id
259
270
  translation:
260
271
  - project_id
261
272
  - branch
@@ -28,11 +28,11 @@ module RubyLokaliseApi
28
28
  end
29
29
 
30
30
  def base_url
31
- self.class.const_get(:BASE_URL)
31
+ self.class::BASE_URL
32
32
  end
33
33
 
34
34
  def full_uri
35
- base_url + uri
35
+ base_url + uri.to_s
36
36
  end
37
37
 
38
38
  # Creates methods like `do_post`, `do_get` that proxy calls to the
@@ -52,7 +52,7 @@ module RubyLokaliseApi
52
52
  end
53
53
 
54
54
  def partial_uri_template
55
- self.class.const_get(:PARTIAL_URI_TEMPLATE)
55
+ self.class::PARTIAL_URI_TEMPLATE
56
56
  end
57
57
  end
58
58
  end
@@ -6,7 +6,7 @@ module RubyLokaliseApi
6
6
  BASE_URL = 'https://api.lokalise.com/api2'
7
7
 
8
8
  def initialize(client, params = {})
9
- super(client, params)
9
+ super
10
10
 
11
11
  @uri = partial_uri(base_query(*@query_params))
12
12
  end
@@ -8,22 +8,32 @@ module RubyLokaliseApi
8
8
  PARTIAL_URI_TEMPLATE = '{/segments*}{?query*}'
9
9
 
10
10
  def initialize(client, params = {})
11
- super(client, params)
11
+ super
12
12
 
13
- @uri = partial_uri(base_query(*@query_params), params.fetch(:get, []))
13
+ @uri = build_uri(params.fetch(:get, []))
14
14
  end
15
15
 
16
16
  private
17
17
 
18
+ # Builds the complete URI for the OAuth2 endpoint
19
+ def build_uri(query)
20
+ partial_uri(base_query(*@query_params), query)
21
+ end
22
+
18
23
  def partial_uri(segments, query)
19
24
  template = super
20
25
 
21
26
  template.expand(
22
27
  segments: segments.to_a.flatten,
23
- query: query.filter { |_k, v| !v.nil? }
28
+ query: filter_query_params(query)
24
29
  ).to_s
25
30
  end
26
31
 
32
+ # Filters out nil values from query parameters
33
+ def filter_query_params(query)
34
+ query.compact
35
+ end
36
+
27
37
  def base_query(segment = nil)
28
38
  [segment]
29
39
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Endpoints
5
+ class PermissionTemplatesEndpoint < MainEndpoint
6
+ private
7
+
8
+ def base_query(team_id)
9
+ {
10
+ teams: [team_id, :roles]
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -52,7 +52,7 @@ module RubyLokaliseApi
52
52
 
53
53
  # Initializes a new Error object
54
54
  def initialize(message = '')
55
- super(message)
55
+ super
56
56
  end
57
57
  end
58
58
  end
@@ -29,7 +29,7 @@ module RubyLokaliseApi
29
29
  def auth(scope:, redirect_uri: nil, state: nil)
30
30
  get_params = {
31
31
  client_id: client_id,
32
- scope: (scope.is_a?(Array) ? scope.join(' ') : scope),
32
+ scope: scope_to_string(scope),
33
33
  state: state,
34
34
  redirect_uri: redirect_uri
35
35
  }
@@ -37,41 +37,42 @@ module RubyLokaliseApi
37
37
  oauth2_endpoint.new(self, query: 'auth', get: get_params).full_uri
38
38
  end
39
39
 
40
- # Requests OAuth2 access token. Requires OAuth2 code obtained
41
- # using the `.auth` method
42
- # @return [RubyLokaliseApi::Resources::OAuth2Token]
43
- # @param code [String]
40
+ # Requests an OAuth2 access token using a code
41
+ # @param code [String] The authorization code
42
+ # @return [RubyLokaliseApi::Resources::OAuth2Token] The OAuth2 token resource
44
43
  def token(code)
45
- endpoint = oauth2_endpoint.new(
46
- self,
47
- query: :token,
48
- req: common_params.merge(
49
- grant_type: 'authorization_code',
50
- code: code
51
- )
52
- )
53
-
54
- RubyLokaliseApi::Resources::OAuth2Token.new endpoint.do_post
44
+ request_token(grant_type: 'authorization_code', code: code)
55
45
  end
56
46
 
57
- # Refreshes expired OAuth2 access token.
58
- # @return [RubyLokaliseApi::Resources::OAuth2RefreshedToken]
59
- # @param refresh_token [String]
47
+ # Refreshes an expired OAuth2 token
48
+ # @param refresh_token [String] The refresh token
49
+ # @return [RubyLokaliseApi::Resources::OAuth2RefreshedToken] The refreshed token resource
60
50
  def refresh(refresh_token)
61
- endpoint = oauth2_endpoint.new(
62
- self,
63
- query: :token,
64
- req: common_params.merge(
65
- grant_type: 'refresh_token',
66
- refresh_token: refresh_token
67
- )
68
- )
69
-
70
- RubyLokaliseApi::Resources::OAuth2RefreshedToken.new endpoint.do_post
51
+ request_token(grant_type: 'refresh_token', refresh_token: refresh_token)
71
52
  end
72
53
 
73
54
  private
74
55
 
56
+ # Generalized method for requesting a token
57
+ # @param params [Hash] Request parameters including grant type
58
+ # @return [RubyLokaliseApi::Resources::OAuth2Token, RubyLokaliseApi::Resources::OAuth2RefreshedToken]
59
+ def request_token(params)
60
+ endpoint = oauth2_endpoint.new(self, query: :token, req: common_params.merge(params))
61
+ resource_class = if params[:grant_type] == 'authorization_code'
62
+ RubyLokaliseApi::Resources::OAuth2Token
63
+ else
64
+ RubyLokaliseApi::Resources::OAuth2RefreshedToken
65
+ end
66
+ resource_class.new(endpoint.do_post)
67
+ end
68
+
69
+ # Converts scope to a space-separated string if it's an array
70
+ # @param scope [Array, String] The scope or scopes
71
+ # @return [String] The scope as a string
72
+ def scope_to_string(scope)
73
+ scope.is_a?(Array) ? scope.join(' ') : scope
74
+ end
75
+
75
76
  def common_params
76
77
  {
77
78
  client_id: @client_id,
@@ -4,7 +4,7 @@ module RubyLokaliseApi
4
4
  # Client used to perform API requests with an OAuth2 access token
5
5
  class OAuth2Client < Client
6
6
  def initialize(token, params = {})
7
- super(token, params)
7
+ super
8
8
  @token_header = 'Authorization'
9
9
  @token = "Bearer #{@token}"
10
10
  end
@@ -63,17 +63,19 @@ module RubyLokaliseApi
63
63
  end
64
64
 
65
65
  def respond_with(response, endpoint)
66
- begin
67
- body = custom_load response.body
68
- rescue JSON::ParserError
69
- respond_with_error(response.status, response.body)
70
- end
66
+ body = parse_response_body(response)
71
67
 
72
68
  raise_on_error! response, body
73
69
 
74
70
  RubyLokaliseApi::Response.new(body, endpoint, response.headers)
75
71
  end
76
72
 
73
+ def parse_response_body(response)
74
+ custom_load(response.body)
75
+ rescue JSON::ParserError
76
+ respond_with_error(response.status, response.body)
77
+ end
78
+
77
79
  def respond_with_error(code, body)
78
80
  raise(RubyLokaliseApi::Error, body['error'] || body) unless RubyLokaliseApi::Error::ERRORS.key? code
79
81
 
@@ -57,20 +57,28 @@ module RubyLokaliseApi
57
57
  @self_endpoint.reinitialize(query_params: read_main_params, req_params: req_params)
58
58
  end
59
59
 
60
+ # Populates attributes from the response content
60
61
  def populate_attrs_from(content)
61
62
  return unless content
62
63
 
63
- data_key = data_key_for klass: self.class.base_name
64
+ data_key = data_key_for(klass: self.class.base_name)
65
+ supported_attrs.each { |attrib| set_instance_variable(attrib, content, data_key) }
66
+ end
64
67
 
65
- supported_attrs.each do |attrib|
66
- value = if content.key?(data_key) && content[data_key].is_a?(Hash) && content[data_key].key?(attrib)
67
- content[data_key][attrib]
68
- else
69
- content[attrib]
70
- end
68
+ # Sets the instance variable for a given attribute
69
+ def set_instance_variable(attrib, content, data_key)
70
+ value = if content_key_exists?(content, data_key, attrib)
71
+ content[data_key][attrib]
72
+ else
73
+ content[attrib]
74
+ end
71
75
 
72
- instance_variable_set :"@#{attrib}", value
73
- end
76
+ instance_variable_set(:"@#{attrib}", value)
77
+ end
78
+
79
+ # Checks if the content contains the specified key
80
+ def content_key_exists?(content, data_key, attrib)
81
+ content.key?(data_key) && content[data_key].is_a?(Hash) && content[data_key].key?(attrib)
74
82
  end
75
83
  end
76
84
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Resources
5
+ class PermissionTemplate < Base
6
+ MAIN_PARAMS = %i[nil].freeze
7
+ no_support_for %i[update destroy reload_data]
8
+ end
9
+ end
10
+ end
@@ -31,19 +31,11 @@ module RubyLokaliseApi
31
31
  @endpoint = new_endpoint
32
32
  end
33
33
 
34
- # Returns an array of pagination headers
35
- def pagination_headers
36
- self.class.const_get(:PAGINATION_HEADERS)
37
- end
38
-
39
34
  private
40
35
 
41
36
  # Keep only pagination headers
42
37
  def extract_headers_from(raw_headers)
43
- raw_headers.
44
- to_h.
45
- keep_if { |header, _value| pagination_headers.include?(header) }.
46
- transform_keys(&:to_sym)
38
+ raw_headers.to_h.slice(*PAGINATION_HEADERS).transform_keys(&:to_sym)
47
39
  end
48
40
  end
49
41
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyLokaliseApi
4
+ module Rest
5
+ module PermissionTemplates
6
+ # Returns permission tempates for a team
7
+ #
8
+ # @see https://developers.lokalise.com/reference/list-all-permission-templates
9
+ # @return [RubyLokaliseApi::Collections::PermissionTemplates]
10
+ # @param team_id [Integer, String]
11
+ def permission_templates(team_id)
12
+ name = 'PermissionTemplates'
13
+ params = { query: team_id }
14
+
15
+ data = endpoint(name: name, params: params).do_get
16
+
17
+ collection name, data
18
+ end
19
+ end
20
+ end
21
+ end
@@ -14,6 +14,7 @@ module RubyLokaliseApi
14
14
  include Rest::Languages
15
15
  include Rest::Orders
16
16
  include Rest::PaymentCards
17
+ include Rest::PermissionTemplates
17
18
  include Rest::Projects
18
19
  include Rest::QueuedProcesses
19
20
  include Rest::Segments
@@ -14,11 +14,11 @@ module RubyLokaliseApi
14
14
  #
15
15
  # @return [Array<String>]
16
16
  def attributes_for(klass, filename)
17
- @attributes ||= YAML.load_file(File.expand_path("../data/#{filename}", __dir__)).freeze
17
+ @attributes ||= load_attributes(filename)
18
18
 
19
19
  name = unify klass.base_name.snakecase
20
20
 
21
- @attributes.key?(name) ? @attributes[name] : @attributes["#{name}s"]
21
+ @attributes[name] || @attributes["#{name}s"]
22
22
  end
23
23
 
24
24
  # Unify some resources' names (eg, `ProjectComment` and `KeyComment` have the same
@@ -26,11 +26,15 @@ module RubyLokaliseApi
26
26
  #
27
27
  # @return [String]
28
28
  def unify(name)
29
- UNIFIED_RESOURCES.each do |u_a|
30
- return u_a if name.match?(/#{u_a}/)
31
- end
29
+ UNIFIED_RESOURCES.find { |u_a| name.match?(/#{u_a}/) } || name
30
+ end
32
31
 
33
- name
32
+ # Loads attributes from a YAML file
33
+ #
34
+ # @param filename [String] The filename to load attributes from
35
+ # @return [Hash] The loaded attributes hash
36
+ def load_attributes(filename)
37
+ YAML.load_file(File.expand_path("../data/#{filename}", __dir__)).freeze
34
38
  end
35
39
  end
36
40
  end
@@ -5,18 +5,25 @@ module RubyLokaliseApi
5
5
  module Utils
6
6
  module Classes
7
7
  refine Object do
8
- # Turn `Module::Nested::ClassName` to just `ClassName`
8
+ # Extracts the base name of a class, removing any module nesting.
9
+ #
10
+ # @return [String] The base class name
9
11
  def base_name
10
12
  name.split('::').last
11
13
  end
12
14
 
13
- # Converts object to array unless it is already an array
15
+ # Converts the object to an array, unless it is already an array.
16
+ #
17
+ # @return [Array] The object wrapped in an array if not already an array
14
18
  def to_array
15
19
  is_a?(Array) ? self : [self]
16
20
  end
17
21
 
18
- # Converts object to array and then places this array
19
- # inside hash under the provided key
22
+ # Converts the object to an array, then places this array inside a hash
23
+ # under the provided key.
24
+ #
25
+ # @param key [Symbol, String] The key under which to place the array
26
+ # @return [Hash] The hash with the array under the provided key
20
27
  def to_array_obj(key)
21
28
  return self if is_a?(Hash) && (key?(key) || key?(key.to_s))
22
29
 
@@ -5,25 +5,36 @@ module RubyLokaliseApi
5
5
  module Keys
6
6
  using RubyLokaliseApi::Utils::Strings
7
7
 
8
- # Reads DATA_KEY for resources. DATA_KEY specifies the name of the key
9
- # in the API response that contains the actual data
8
+ # Retrieves the DATA_KEY for resources.
9
+ # DATA_KEY specifies the key in the API response containing the actual data.
10
+ #
11
+ # @param klass [Class] The class of the resource
12
+ # @return [String] The snake-cased DATA_KEY
10
13
  def data_key_for(klass:)
11
- key = if Module.const_defined? "RubyLokaliseApi::Resources::#{klass}::DATA_KEY"
12
- Module.const_get "RubyLokaliseApi::Resources::#{klass}::DATA_KEY"
13
- else
14
- klass
15
- end
16
-
17
- key.snakecase
14
+ retrieve_data_key("RubyLokaliseApi::Resources::#{klass}::DATA_KEY", klass)
18
15
  end
19
16
 
20
- # Reads DATA_KEY for collections. DATA_KEY specifies the name of the key
21
- # in the API response that contains the actual data
17
+ # Retrieves the DATA_KEY for collections.
18
+ # DATA_KEY specifies the key in the API response containing the actual data.
19
+ #
20
+ # @param klass [Class] The class of the collection
21
+ # @return [String] The snake-cased DATA_KEY
22
22
  def collection_key_for(klass:)
23
- key = if Module.const_defined?("RubyLokaliseApi::Collections::#{klass}::DATA_KEY")
24
- Module.const_get("RubyLokaliseApi::Collections::#{klass}::DATA_KEY")
23
+ retrieve_data_key("RubyLokaliseApi::Collections::#{klass}::DATA_KEY", klass)
24
+ end
25
+
26
+ private
27
+
28
+ # Helper method to retrieve the DATA_KEY for a given class.
29
+ #
30
+ # @param constant_path [String] The constant path to check
31
+ # @param fallback [Class] The fallback class if the constant isn't defined
32
+ # @return [String] The snake-cased key
33
+ def retrieve_data_key(constant_path, fallback)
34
+ key = if Module.const_defined?(constant_path)
35
+ Module.const_get(constant_path)
25
36
  else
26
- klass
37
+ fallback
27
38
  end
28
39
 
29
40
  key.snakecase
@@ -6,21 +6,40 @@ module RubyLokaliseApi
6
6
  private
7
7
 
8
8
  # Instantiates an endpoint
9
+ #
10
+ # @param name [String] The name of the endpoint
11
+ # @param client [Object] The client to associate with the endpoint (default: self)
12
+ # @param params [Hash] Additional parameters for the endpoint
13
+ # @return [Object] The instantiated endpoint
9
14
  def endpoint(name:, client: self, params: {})
10
- klass = RubyLokaliseApi.const_get "Endpoints::#{name}Endpoint"
11
- klass.new client, params
15
+ instantiate("Endpoints::#{name}Endpoint", client, params)
12
16
  end
13
17
 
14
18
  # Instantiates a resource
19
+ #
20
+ # @param name [String] The name of the resource
21
+ # @param data [Hash] The data to initialize the resource with
22
+ # @return [Object] The instantiated resource
15
23
  def resource(name, data)
16
- klass = RubyLokaliseApi.const_get "Resources::#{name}"
17
- klass.new data
24
+ instantiate("Resources::#{name}", data)
18
25
  end
19
26
 
20
27
  # Instantiates a collection
28
+ #
29
+ # @param name [String] The name of the collection
30
+ # @param data [Hash] The data to initialize the collection with
31
+ # @return [Object] The instantiated collection
21
32
  def collection(name, data)
22
- klass = RubyLokaliseApi.const_get "Collections::#{name}"
23
- klass.new data
33
+ instantiate("Collections::#{name}", data)
34
+ end
35
+
36
+ # Helper method to instantiate a class by constant name
37
+ #
38
+ # @param constant_path [String] The constant path for the class
39
+ # @param args [Array] Arguments to initialize the class with
40
+ # @return [Object] The instantiated class
41
+ def instantiate(constant_path, *args)
42
+ RubyLokaliseApi.const_get(constant_path).new(*args)
24
43
  end
25
44
  end
26
45
  end
@@ -4,15 +4,16 @@ module RubyLokaliseApi
4
4
  module Utils
5
5
  module Strings
6
6
  refine String do
7
- # Initial code taken from Facets gem by Rubyworks
7
+ # Converts a string to snake_case format.
8
+ # Original code inspired by the Facets gem by Rubyworks:
8
9
  # https://github.com/rubyworks/facets/blob/master/lib/core/facets/string/snakecase.rb
9
10
  def snakecase
10
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
11
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
12
- tr('-', '_').
13
- gsub(/\s/, '_').
14
- gsub(/__+/, '_').
15
- downcase
11
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). # Handle acronyms like 'HTMLParser'
12
+ gsub(/([a-z\d])([A-Z])/, '\1_\2'). # Handle camelCase to snake_case
13
+ tr('-', '_'). # Replace dashes with underscores
14
+ gsub(/\s/, '_'). # Replace spaces with underscores
15
+ gsub(/__+/, '_'). # Collapse multiple underscores
16
+ downcase # Convert everything to lowercase
16
17
  end
17
18
  end
18
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLokaliseApi
4
- VERSION = '9.1.0'
4
+ VERSION = '9.2.1'
5
5
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_dependency 'addressable', '~> 2.5'
25
25
  spec.add_dependency 'faraday', '~> 2.0'
26
- spec.add_dependency 'faraday-gzip', '~> 2.0'
26
+ spec.add_dependency 'faraday-gzip', '>= 2', '< 4'
27
27
  spec.add_dependency 'json', '~> 2'
28
28
  spec.add_dependency 'zeitwerk', '~> 2.4'
29
29
 
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
34
34
  spec.add_development_dependency 'rubocop', '~> 1.6'
35
35
  spec.add_development_dependency 'rubocop-performance', '~> 1.5'
36
36
  spec.add_development_dependency 'rubocop-rake', '~> 0.6'
37
- spec.add_development_dependency 'rubocop-rspec', '~> 2.0'
37
+ spec.add_development_dependency 'rubocop-rspec', '~> 3.0'
38
38
  spec.add_development_dependency 'simplecov', '~> 0.21'
39
39
  spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
40
40
  spec.add_development_dependency 'webmock', '~> 3.14'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lokalise-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Krukowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -42,16 +42,22 @@ dependencies:
42
42
  name: faraday-gzip
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '2'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '4'
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: '2.0'
57
+ version: '2'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '4'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: json
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +190,14 @@ dependencies:
184
190
  requirements:
185
191
  - - "~>"
186
192
  - !ruby/object:Gem::Version
187
- version: '2.0'
193
+ version: '3.0'
188
194
  type: :development
189
195
  prerelease: false
190
196
  version_requirements: !ruby/object:Gem::Requirement
191
197
  requirements:
192
198
  - - "~>"
193
199
  - !ruby/object:Gem::Version
194
- version: '2.0'
200
+ version: '3.0'
195
201
  - !ruby/object:Gem::Dependency
196
202
  name: simplecov
197
203
  requirement: !ruby/object:Gem::Requirement
@@ -263,6 +269,7 @@ files:
263
269
  - lib/ruby_lokalise_api/collections/keys.rb
264
270
  - lib/ruby_lokalise_api/collections/orders.rb
265
271
  - lib/ruby_lokalise_api/collections/payment_cards.rb
272
+ - lib/ruby_lokalise_api/collections/permission_templates.rb
266
273
  - lib/ruby_lokalise_api/collections/project_comments.rb
267
274
  - lib/ruby_lokalise_api/collections/project_languages.rb
268
275
  - lib/ruby_lokalise_api/collections/projects.rb
@@ -296,6 +303,7 @@ files:
296
303
  - lib/ruby_lokalise_api/endpoints/oauth2/oauth2_endpoint.rb
297
304
  - lib/ruby_lokalise_api/endpoints/orders_endpoint.rb
298
305
  - lib/ruby_lokalise_api/endpoints/payment_cards_endpoint.rb
306
+ - lib/ruby_lokalise_api/endpoints/permission_templates_endpoint.rb
299
307
  - lib/ruby_lokalise_api/endpoints/project_comments_endpoint.rb
300
308
  - lib/ruby_lokalise_api/endpoints/project_languages_endpoint.rb
301
309
  - lib/ruby_lokalise_api/endpoints/projects_endpoint.rb
@@ -330,6 +338,7 @@ files:
330
338
  - lib/ruby_lokalise_api/resources/oauth2_token.rb
331
339
  - lib/ruby_lokalise_api/resources/order.rb
332
340
  - lib/ruby_lokalise_api/resources/payment_card.rb
341
+ - lib/ruby_lokalise_api/resources/permission_template.rb
333
342
  - lib/ruby_lokalise_api/resources/project.rb
334
343
  - lib/ruby_lokalise_api/resources/project_language.rb
335
344
  - lib/ruby_lokalise_api/resources/queued_process.rb
@@ -357,6 +366,7 @@ files:
357
366
  - lib/ruby_lokalise_api/rest/languages.rb
358
367
  - lib/ruby_lokalise_api/rest/orders.rb
359
368
  - lib/ruby_lokalise_api/rest/payment_cards.rb
369
+ - lib/ruby_lokalise_api/rest/permission_templates.rb
360
370
  - lib/ruby_lokalise_api/rest/projects.rb
361
371
  - lib/ruby_lokalise_api/rest/queued_processes.rb
362
372
  - lib/ruby_lokalise_api/rest/screenshots.rb
@@ -397,7 +407,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
407
  - !ruby/object:Gem::Version
398
408
  version: '0'
399
409
  requirements: []
400
- rubygems_version: 3.5.10
410
+ rubygems_version: 3.5.22
401
411
  signing_key:
402
412
  specification_version: 4
403
413
  summary: Ruby interface to the Lokalise API