Skip to content

Commit

Permalink
Merge pull request #21 from crowdin/client-updates
Browse files Browse the repository at this point in the history
Release '1.4.0'
  • Loading branch information
andrii-bodnar authored Aug 15, 2022
2 parents 56a277e + 30cea5b commit 18f977e
Show file tree
Hide file tree
Showing 19 changed files with 943 additions and 79 deletions.
116 changes: 55 additions & 61 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-05-09 23:17:26 UTC using RuboCop version 1.26.0.
# on 2022-08-12 15:14:54 UTC using RuboCop version 1.26.0.
# 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
Expand All @@ -21,16 +21,21 @@ Gemspec/RequiredRubyVersion:
Exclude:
- 'crowdin-api.gemspec'

# Offense count: 18
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
# Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth.
# SupportedStyles: case, end
Layout/CaseIndentation:
Exclude:
- 'lib/crowdin-api/api_resources/machine_translation_engines.rb'
- 'lib/crowdin-api/api_resources/reports.rb'
- 'lib/crowdin-api/api_resources/teams.rb'
- 'lib/crowdin-api/api_resources/users.rb'
- 'lib/crowdin-api/api_resources/workflows.rb'
- 'lib/crowdin-api/client/client.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# 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).
Expand All @@ -42,7 +47,7 @@ Layout/HashAlignment:
Exclude:
- 'lib/crowdin-api/client/configuration.rb'

# Offense count: 13
# Offense count: 14
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, indented_internal_methods
Expand All @@ -52,7 +57,7 @@ Layout/IndentationConsistency:
- 'lib/crowdin-api/core/request.rb'
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 13
# Offense count: 14
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
Expand All @@ -61,59 +66,60 @@ Layout/IndentationWidth:
- 'lib/crowdin-api/core/request.rb'
- 'lib/crowdin-api/core/send_request.rb'

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

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 2
# Offense count: 3
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 23
Max: 42

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

# Offense count: 13
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 101

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

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

# Offense count: 9
# Offense count: 8
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 199
Max: 196

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

# Offense count: 2
# Offense count: 1
# Configuration parameters: IgnoredMethods.
Metrics/PerceivedComplexity:
Max: 19

# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- 'lib/crowdin-api/api_resources/users.rb'
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
Expand All @@ -130,13 +136,6 @@ Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/crowdin-api/client/client.rb'

# Offense count: 6
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: PreferredName.
Naming/RescuedExceptionsVariableName:
Exclude:
- 'lib/crowdin-api/core/send_request.rb'

# Offense count: 7
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
Expand All @@ -146,14 +145,13 @@ Style/AccessorGrouping:
- 'lib/crowdin-api/client/configuration.rb'
- 'lib/crowdin-api/core/request.rb'

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

# Offense count: 24
# Offense count: 27
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
Expand All @@ -175,25 +173,21 @@ Style/FrozenStringLiteralComment:
- 'bin/crowdin-console'

# Offense count: 1
Style/MixinUsage:
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'bin/crowdin-console'
- 'lib/crowdin-api/client/client.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
# Offense count: 1
Style/MixinUsage:
Exclude:
- 'lib/crowdin-api/api_resources/labels.rb'
- 'lib/crowdin-api/api_resources/string_translations.rb'
- 'bin/crowdin-console'

# Offense count: 1
# This cop supports unsafe auto-correction (--auto-correct-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
# This cop supports safe auto-correction (--auto-correct).
Style/RedundantFreeze:
Exclude:
- 'lib/crowdin-api/api_resources/projects.rb'
- 'lib/crowdin-api/core/fetch_all_extensions.rb'

# Offense count: 8
# This cop supports safe auto-correction (--auto-correct).
Expand All @@ -203,9 +197,9 @@ Style/StringLiterals:
Exclude:
- 'spec/api_resources/projects_spec.rb'

# Offense count: 1
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 121
Max: 122
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For more about Crowdin API v2 see the documentation:
* [Quick Start](#quick-start)
* [Initialization](#initialization)
* [Usage](#usage)
* [Fetch all records](#fetch-all-records)
* [Command-Line Client](#command-line-client)
* [Seeking Assistance](#seeking-assistance)
* [Contributing](#contributing)
Expand All @@ -40,7 +41,7 @@ For more about Crowdin API v2 see the documentation:
Add this line to your application's Gemfile:

```gemfile
gem 'crowdin-api', '~> 1.3.0'
gem 'crowdin-api', '~> 1.4.0'
```

And then execute:
Expand All @@ -66,6 +67,7 @@ gem install crowdin-api
## Quick start

### Initialization

```ruby
require 'crowdin-api'

Expand Down Expand Up @@ -145,6 +147,33 @@ file_revisions = crowdin.list_file_revisions(your_file_id, { limit: 10 }, your_p
# Note: more examples you can find in spec folder
```

### Fetch all records

There is a possibility to fetch all records from paginatable methods using `fetch_all` method.

```ruby
# FetchAll options:
# * limit, Integer, default: 500 | How many records need to load per one request
# * offset, Integer, default: 0
# * request_delay, Integer (seconds), default: 0 | Delay between requests. To specify a delay in milliseconds use float values like 0.100

# Examples:

@crowdin.fetch_all(:list_projects)

# with options
@crowdin.fetch_all(:list_projects, { limit: 10, request_delay: 1 })

# playing with response per fetch
# Note: the block actually don't make any effect to finite result
@crowdin.fetch_all(:list_projects, { limit: 10, request_delay: 1 }) { |response| puts response['data'] }

# also, you could specify a retry configuration to handle some exceptions
# fetch all execution will be terminated if response status code is the same as one of the error_messages array value
# otherwise, the request will be retried so many times, as indicated at retries_count
@crowdin.fetch_all(:list_projects, {}, { request_delay: 2, retries_count: 3, error_messages: ['401'] })
```

### Command-Line Client

The Crowdin Ruby client support crowdin-console, where you can test endpoints easier
Expand Down
3 changes: 2 additions & 1 deletion lib/crowdin-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Crowdin
API_RESOURCES_MODULES = %i[Storages Languages Projects Workflows SourceFiles Translations SourceStrings
StringTranslations StringComments Screenshots Glossaries TranslationMemory
MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks
Dictionaries Distributions Labels TranslationStatus].freeze
Dictionaries Distributions Labels TranslationStatus Bundles].freeze

# Error Raisers modules
ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze
Expand All @@ -21,6 +21,7 @@ module Crowdin
require 'crowdin-api/core/errors_raisers'
require 'crowdin-api/core/request'
require 'crowdin-api/core/send_request'
require 'crowdin-api/core/fetch_all_extensions'

# API modules
Crowdin::API_RESOURCES_MODULES.each do |api_resource|
Expand Down
81 changes: 81 additions & 0 deletions lib/crowdin-api/api_resources/bundles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# frozen_string_literal: true

module Crowdin
module ApiResources
module Bundles
def list_bundles(query = {}, project_id = config.project_id)
project_id || raise_project_id_is_required_error

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

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

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

def get_bundle(bundle_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error

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

def delete_bundle(bundle_id, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:delete,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}"
)
Web::SendRequest.new(request).perform
end

def edit_bundle(bundle_id, query = {}, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error

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

def bundle_list_files(bundle_id, query = {}, project_id = config.project_id)
bundle_id || raise_parameter_is_required_error(:bundle_id)
project_id || raise_project_id_is_required_error

request = Web::Request.new(
connection,
:get,
"#{config.target_api_url}/projects/#{project_id}/bundles/#{bundle_id}/files",
{ params: query }
)
Web::SendRequest.new(request).perform
end
end
end
end
2 changes: 1 addition & 1 deletion lib/crowdin-api/api_resources/string_translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_vote(vote_id = nil, project_id = config.project_id)
Web::SendRequest.new(request).perform
end

def edit_screenshot(vote_id = nil, project_id = config.project_id)
def cancel_vote(vote_id = nil, project_id = config.project_id)
vote_id || raise_parameter_is_required_error(:vote_id)
project_id || raise_project_id_is_required_error

Expand Down
Loading

0 comments on commit 18f977e

Please sign in to comment.