Skip to content

Commit

Permalink
Merge pull request #16 from crowdin/client-updates
Browse files Browse the repository at this point in the history
Release '1.2.0'
  • Loading branch information
andrii-bodnar authored Feb 14, 2022
2 parents 9e63773 + dafc90f commit 17150cb
Show file tree
Hide file tree
Showing 37 changed files with 2,007 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']
ruby-version: [ '2.6', '2.7', '3.0' ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Ignore Ruby logs
.ruby-version
.idea

# Ignore MacOS logs
.DS_Store

# Ignore versioning file
# Ignore versioning files
Gemfile.lock
.ruby-version

# Ignore tests coverage folder
coverage
67 changes: 37 additions & 30 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 2021-12-13 20:26:23 UTC using RuboCop version 1.23.0.
# on 2022-02-14 06:05:44 UTC using RuboCop version 1.23.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,12 +21,15 @@ Gemspec/RequiredRubyVersion:
Exclude:
- 'crowdin-api.gemspec'

# Offense count: 2
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'bin/crowdin-console'
- 'lib/crowdin-api/client/configuration.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -47,24 +50,26 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 54

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

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

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

# Offense count: 1
# Offense count: 2
Naming/AccessorMethodName:
Exclude:
- 'lib/crowdin-api/api-resources/users.rb'
- 'lib/crowdin-api/core/request.rb'

# Offense count: 3
Expand All @@ -74,8 +79,8 @@ Naming/AccessorMethodName:
Naming/FileName:
Exclude:
- 'lib/crowdin-api.rb'
- 'spec/core/config-instance_spec.rb'
- 'spec/crowdin-api_spec.rb'
- 'spec/client/client-instance_spec.rb'
- 'spec/client/configuration-instance_spec.rb'

# Offense count: 3
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
Expand All @@ -91,7 +96,7 @@ Naming/RescuedExceptionsVariableName:
Exclude:
- 'lib/crowdin-api/core/request.rb'

# Offense count: 7
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: separated, grouped
Expand All @@ -106,24 +111,10 @@ Style/CollectionCompact:
Exclude:
- 'lib/crowdin-api/core/request.rb'

# Offense count: 12
# Offense count: 22
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/crowdin-api/api-resources/languages.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/storages.rb'
- 'lib/crowdin-api/api-resources/translation_status.rb'
- 'lib/crowdin-api/api-resources/translations.rb'
- 'lib/crowdin-api/api-resources/workflows.rb'
- 'lib/crowdin-api/client/client.rb'
- 'lib/crowdin-api/client/configuration.rb'
- 'lib/crowdin-api/core/api_errors_raiser.rb'
- 'lib/crowdin-api/core/request.rb'
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Expand All @@ -137,3 +128,19 @@ Style/FrozenStringLiteralComment:
Style/MixinUsage:
Exclude:
- 'bin/crowdin-console'

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Exclude:
- 'lib/crowdin-api/api-resources/labels.rb'
- 'lib/crowdin-api/api-resources/string_translations.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 122
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For more about Crowdin API v2 see the documentation:
- [Crowdin](https://support.crowdin.com/api/v2/)
- [Crowdin Enterprise](https://support.crowdin.com/enterprise/api/)

### Status
## Status

[![Gem](https://img.shields.io/gem/v/crowdin-api?logo=ruby&cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
[![Gem](https://img.shields.io/gem/dt/crowdin-api?cacheSeconds=1800)](https://rubygems.org/gems/crowdin-api)
Expand All @@ -22,21 +22,25 @@ For more about Crowdin API v2 see the documentation:
[![GitHub](https://img.shields.io/github/license/crowdin/crowdin-api-client-ruby?cacheSeconds=1800)](https://github.com/crowdin/crowdin-api-client-ruby/blob/main/LICENSE)

## Table of Contents
* [Requirements](#requirements)
* [Installation](#installation)
* [Quick Start](#quick-start)
* [Initialization](#initialization)
* [How to call methods](#how-to-call-methods)
* [Usage](#usage)
* [Command-Line Client](#command-line-client)
* [Seeking Assistance](#seeking-assistance)
* [Contributing](#contributing)
* [License](#license)

## Requirements
* Ruby >= 2.4

## Installation

Add this line to your application's Gemfile:

```gemfile
gem 'crowdin-api', '~> 1.1.0'
gem 'crowdin-api', '~> 1.2.0'
```

And then execute:
Expand Down Expand Up @@ -70,12 +74,13 @@ crowdin = Crowdin::Client.new do |config|
config.api_token = 'YourApiToken'
end

# Or you can intialize Enterprise Client instance by specifying your organization_domain in config options
# Or you can intialize Enterprise Client instance by specifying your
# organization_domain in config options
crowdin = Crowdin::Client.new do |config|
config.api_token = 'YourEnterpriseApiToken'
config.organization_domain = 'YourOrganizationDomain'
end
# Note: we use full specified organization domain if that includes .com
# Note: we use full specified organization domain if that includes '.com'
# config.organization_domain = your_domain -> https://your_domain.api.crowdin.com
# config.organization_domain = your_domain.com -> your_domain.com

Expand All @@ -86,8 +91,8 @@ crowdin = Crowdin::Client.new do |config|
config.project_id = 'YourProjectId' # [Integer] nil by default
config.enable_logger = true # [Boolean] false by default
end
# Note: Client will initialize default Logger instance if you have specify enable_logger to true,
# you can change it by crowdin.logger = YourLogger
# Note: Client will initialize default Logger instance if you have specify
# enable_logger to true, you can change it by crowdin.logger = YourLogger

# Also you can specify proxy by adding it to ENV['http_proxy'] before Client initialization
```
Expand Down Expand Up @@ -115,14 +120,20 @@ projects = crowdin.list_projects(offset: 10, limit: 20)
# Get specified project
project = crowdin.get_project(your_project_id)

# Edit project
project = crowdin.edit_project(project_id, [{op: 'replace',
path: '/name',
value: 'your_new_project_name'}])

# Add Storage
storage = crowdin.add_storage(File.open('YourFilename.extension', 'r'))
# or you can specify only filename
# or you can specify only absolute path to file
storage = crowdin.add_storage('YourFilename.extension')

# Download file
filename = crowdin.download_file(your_file_id, your_destination, your_project_id)
# your_destination - filename or full path to file, default - saving to currect directory with default filename
file = crowdin.download_file(your_file_id, your_destination, your_project_id)
# your_destination - filename or absolute path to file, optional
# Without destination option file will be saved to the current directory with a default filename
# project_id is optional, as it can be initialized with a Crowdin Client

# File revisions
Expand All @@ -143,9 +154,9 @@ $ bundle exec crowdin-console --enable-logger --api-token API_TOKEN --project-id
Or Crowdin Enterprise

```console
$ bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain YOUR_DOMAIN --project-id PROJECT_ID
$ bundle exec crowdin-console --enable-logger --enterprise --api-token API_TOKEN --organization-domain DOMAIN --project-id PROJECT_ID
```
Note: you can specify full organization domain by adding .com
Note: you can specify full organization domain by adding '.com'

When execute you'll have IRB console with configured *@crowdin* instance

Expand Down
8 changes: 4 additions & 4 deletions bin/crowdin-console
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require 'optparse'
# bundle exec crowdin-console --enterprise --api-token YOUR_ENTERPRISE_API_TOKEN --organization-domain YOUR_DOMAIN
#

include Crowdin::Errors::ApiErrorsRaiser
include Crowdin::Errors::ClcErrorsRaiser

options = {}

Expand All @@ -27,7 +27,7 @@ OptionParser.new do |opts|
opts.on('--enterprise', 'Enterprise API') { |v| options[:enterprise] = v }
opts.on('--api-token TOKEN', 'API Token') { |v| options[:api_token] = v }
opts.on('--organization-domain DOMAIN', 'Organization Domain') { |v| options[:organization_domain] = v }
opts.on('--project-id ID', 'Project ID') { |v| options[:project_id] = v }
opts.on('--project-id ID', 'Project ID') { |v| options[:project_id] = v }
opts.on('--enable-logger', 'Enable logger') { |v| options[:enable_logger] = v }
end.parse!

Expand All @@ -39,8 +39,8 @@ if options[:enterprise]
@crowdin = Crowdin::Client.new do |config|
config.api_token = options[:api_token]
config.organization_domain = options[:organization_domain]
config.enable_logger = options[:enable_logger] || false
config.project_id = options[:project_id] || nil
config.enable_logger = options[:enable_logger] || false
config.project_id = options[:project_id] || nil
end
else
@crowdin = Crowdin::Client.new do |config|
Expand Down
28 changes: 22 additions & 6 deletions lib/crowdin-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,36 @@

# Core modules
require 'crowdin-api/core/errors'
require 'crowdin-api/core/api_errors_raiser'
require 'crowdin-api/core/errors_raisers'
require 'crowdin-api/core/request'
require 'crowdin-api/core/utils'

# Api modules
# API modules
require 'crowdin-api/api-resources/storages'
require 'crowdin-api/api-resources/languages'
require 'crowdin-api/api-resources/projects'
require 'crowdin-api/api-resources/workflows'
require 'crowdin-api/api-resources/source_files'
require 'crowdin-api/api-resources/storages'
require 'crowdin-api/api-resources/translation_status'
require 'crowdin-api/api-resources/translations'
require 'crowdin-api/api-resources/workflows'
require 'crowdin-api/api-resources/source_strings'
require 'crowdin-api/api-resources/string_translations'
require 'crowdin-api/api-resources/string_comments'
require 'crowdin-api/api-resources/screenshots'
require 'crowdin-api/api-resources/glossaries'
require 'crowdin-api/api-resources/translation_memory'
require 'crowdin-api/api-resources/machine_translation_engines'
require 'crowdin-api/api-resources/reports'
require 'crowdin-api/api-resources/tasks'
require 'crowdin-api/api-resources/users'
require 'crowdin-api/api-resources/teams'
require 'crowdin-api/api-resources/vendors'
require 'crowdin-api/api-resources/webhooks'
require 'crowdin-api/api-resources/dictionaries'
require 'crowdin-api/api-resources/distributions'
require 'crowdin-api/api-resources/labels'
require 'crowdin-api/api-resources/translation_status'

# Client
# Client modules
require 'crowdin-api/client/version'
require 'crowdin-api/client/configuration'
require 'crowdin-api/client/client'
34 changes: 34 additions & 0 deletions lib/crowdin-api/api-resources/dictionaries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

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

request = Web::Request.new(
self,
:get,
"/projects/#{project_id}/dictionaries",
query
)

request.perform
end

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

request = Web::Request.new(
self,
:patch,
"/projects/#{project_id}/dictionaries/#{language_id}",
query
)

request.perform
end
end
end
end
Loading

0 comments on commit 17150cb

Please sign in to comment.