Skip to content

Commit

Permalink
feat(Labels/SourceStrings/SourceFiles/TranslationMemory/Projects): AP…
Browse files Browse the repository at this point in the history
…I Resources updates and refactoring. Some other small style changes.
  • Loading branch information
keshandrr committed Mar 18, 2024
1 parent 98430f7 commit d32d068
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 117 deletions.
97 changes: 57 additions & 40 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-08-12 15:14:54 UTC using RuboCop version 1.26.0.
# on 2024-03-18 05:32:08 UTC using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: Include.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'crowdin-api.gemspec'

# Offense count: 1
# Configuration parameters: Include.
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'crowdin-api.gemspec'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Layout/CaseIndentation:
Exclude:
- 'lib/crowdin-api/client/client.rb'

# Offense count: 14
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'spec/api_resources/labels_spec.rb'
- 'spec/api_resources/projects_spec.rb'
- 'spec/api_resources/source_files_spec.rb'
- 'spec/api_resources/source_strings_spec.rb'
- 'spec/api_resources/translation_memory_spec.rb'

# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/crowdin-api/api_resources/labels.rb'
- 'lib/crowdin-api/api_resources/projects.rb'
- 'lib/crowdin-api/api_resources/source_files.rb'
- 'lib/crowdin-api/api_resources/source_strings.rb'
- 'lib/crowdin-api/api_resources/translation_memory.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyleAlignWith, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Layout/EndAlignment:
Exclude:
- 'lib/crowdin-api/client/client.rb'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
Expand All @@ -48,7 +72,7 @@ Layout/HashAlignment:
- 'lib/crowdin-api/client/configuration.rb'

# Offense count: 14
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, indented_internal_methods
Layout/IndentationConsistency:
Expand All @@ -58,31 +82,31 @@ Layout/IndentationConsistency:
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 14
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: Width, IgnoredPatterns.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Width, AllowedPatterns.
Layout/IndentationWidth:
Exclude:
- 'lib/crowdin-api/client/client.rb'
- 'lib/crowdin-api/core/request.rb'
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'crowdin-api.gemspec'
- 'spec/api_resources/projects_spec.rb'

# Offense count: 3
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 42

# Offense count: 46
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
# Offense count: 53
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 171

Expand All @@ -92,27 +116,27 @@ Metrics/ClassLength:
Max: 101

# Offense count: 1
# Configuration parameters: IgnoredMethods.
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 18

# Offense count: 6
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# Offense count: 15
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 41

# Offense count: 8
# Offense count: 11
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 256
Max: 215

# Offense count: 2
# Configuration parameters: Max, CountKeywordArgs.
Metrics/ParameterLists:
MaxOptionalParameters: 4

# Offense count: 1
# Configuration parameters: IgnoredMethods.
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 19

Expand All @@ -137,7 +161,7 @@ Naming/MemoizedInstanceVariableName:
- 'lib/crowdin-api/client/client.rb'

# Offense count: 7
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: separated, grouped
Style/AccessorGrouping:
Expand All @@ -146,34 +170,27 @@ Style/AccessorGrouping:
- 'lib/crowdin-api/core/request.rb'

# Offense count: 2
# This cop supports unsafe auto-correction (--auto-correct-all).
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CollectionCompact:
Exclude:
- 'lib/crowdin-api/core/request.rb'

# Offense count: 27
# Offense count: 29
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: allowed_in_returns, forbidden
Style/DoubleNegation:
Exclude:
- 'lib/crowdin-api/client/configuration.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'bin/crowdin-console'

# Offense count: 1
# Configuration parameters: MinBodyLength.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'lib/crowdin-api/client/client.rb'
Expand All @@ -184,22 +201,22 @@ Style/MixinUsage:
- 'bin/crowdin-console'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantFreeze:
Exclude:
- 'lib/crowdin-api/core/fetch_all_extensions.rb'

# Offense count: 8
# This cop supports safe auto-correction (--auto-correct).
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Exclude:
- 'spec/api_resources/projects_spec.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 122
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ GEM
yard (0.9.36)

PLATFORMS
arm64-darwin-23
x86_64-linux
ruby

DEPENDENCIES
bundler (~> 2.2, >= 2.2.32)
Expand Down
34 changes: 33 additions & 1 deletion lib/crowdin-api/api_resources/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Crowdin
module ApiResources
module Labels

def list_labels(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error

Expand Down Expand Up @@ -84,7 +85,37 @@ def unassign_label_from_strings(label_id = nil, query = {}, project_id = config.
response = ::RestClient::Request.execute(
{
method: :delete,
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}",
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/strings",
payload: query.to_json
}.merge(@options)
)

response.body.empty? ? response.code : JSON.parse(response.body)
rescue StandardError => e
e.message

Check warning on line 95 in lib/crowdin-api/api_resources/labels.rb

View check run for this annotation

Codecov / codecov/patch

lib/crowdin-api/api_resources/labels.rb#L95

Added line #L95 was not covered by tests
end

def assign_label_to_screenshots(label_id = nil, query = {}, project_id = config.project_id)
label_id || raise_parameter_is_required_error(:label_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/labels/#{label_id}/screenshots",
{ params: query }
)
Web::SendRequest.new(request).perform
end

def unassign_label_from_screenshots(label_id = nil, query = {}, project_id = config.project_id)
label_id || raise_parameter_is_required_error(:label_id)
project_id || raise_project_id_is_required_error

response = ::RestClient::Request.execute(
{
method: :delete,
url: config.base_url + config.target_api_url + "/projects/#{project_id}/labels/#{label_id}/screenshots",
payload: query.to_json
}.merge(@options)
)
Expand All @@ -93,6 +124,7 @@ def unassign_label_from_strings(label_id = nil, query = {}, project_id = config.
rescue StandardError => e
e.message
end

end
end
end
6 changes: 6 additions & 0 deletions lib/crowdin-api/api_resources/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Crowdin
module ApiResources
module Projects

# * {https://developer.crowdin.com/api/v2/#operation/api.projects.getMany API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.getMany Enterprise API Documentation}
# @param query [Hash] Request Body
Expand All @@ -20,6 +21,10 @@ def list_projects(query = {})
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.post Enterprise API Documentation}
# @param query [Hash] Request Body
def add_project(query = {})
%i[name sourceLanguageId].each do |param|
query[param] || raise_parameter_is_required_error(param)
end

request = Web::Request.new(
connection,
:post,
Expand Down Expand Up @@ -146,6 +151,7 @@ def edit_group(group_id = nil, query = {})
)
Web::SendRequest.new(request).perform
end

end
end
end
14 changes: 14 additions & 0 deletions lib/crowdin-api/api_resources/source_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Crowdin
module ApiResources
module SourceFiles

# @param query [Hash] Request Body
# * {https://developer.crowdin.com/api/v2/#operation/api.projects.branches.getMany API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.branches.getMany Enterprise API Documentation}
Expand Down Expand Up @@ -300,6 +301,19 @@ def get_file_revision(file_id = nil, revision_id = nil, project_id = config.proj
)
Web::SendRequest.new(request).perform
end

def download_file_preview(file_id = nil, project_id = config.project_id)
file_id || raise_parameter_is_required_error(:file_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/files/#{file_id}/preview"
)
Web::SendRequest.new(request).perform
end

end
end
end
14 changes: 14 additions & 0 deletions lib/crowdin-api/api_resources/source_strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Crowdin
module ApiResources
module SourceStrings

def list_strings(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error

Expand Down Expand Up @@ -64,6 +65,19 @@ def edit_string(string_id = nil, query = {}, project_id = config.project_id)
)
Web::SendRequest.new(request).perform
end

def string_batch_operations(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:patch,
"#{config.target_api_url}/projects/#{project_id}/strings",
{ params: query }
)
Web::SendRequest.new(request).perform
end

end
end
end
Loading

0 comments on commit d32d068

Please sign in to comment.