crowdin-api 1.1.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test-and-lint.yml +1 -1
  3. data/.gitignore +2 -2
  4. data/.rubocop_todo.yml +114 -42
  5. data/README.md +26 -13
  6. data/bin/crowdin-console +5 -5
  7. data/crowdin-api.gemspec +1 -2
  8. data/lib/crowdin-api/api_resources/dictionaries.rb +32 -0
  9. data/lib/crowdin-api/api_resources/distributions.rb +92 -0
  10. data/lib/crowdin-api/api_resources/glossaries.rb +199 -0
  11. data/lib/crowdin-api/api_resources/labels.rb +98 -0
  12. data/lib/crowdin-api/api_resources/languages.rb +61 -0
  13. data/lib/crowdin-api/api_resources/machine_translation_engines.rb +79 -0
  14. data/lib/crowdin-api/api_resources/projects.rb +124 -0
  15. data/lib/crowdin-api/api_resources/reports.rb +120 -0
  16. data/lib/crowdin-api/api_resources/screenshots.rb +172 -0
  17. data/lib/crowdin-api/{api-resources → api_resources}/source_files.rb +68 -130
  18. data/lib/crowdin-api/{api-resources → api_resources}/source_strings.rb +19 -24
  19. data/lib/crowdin-api/api_resources/storages.rb +54 -0
  20. data/lib/crowdin-api/api_resources/string_comments.rb +68 -0
  21. data/lib/crowdin-api/api_resources/string_translations.rb +193 -0
  22. data/lib/crowdin-api/api_resources/tasks.rb +102 -0
  23. data/lib/crowdin-api/api_resources/teams.rb +135 -0
  24. data/lib/crowdin-api/api_resources/translation_memory.rb +131 -0
  25. data/lib/crowdin-api/{api-resources → api_resources}/translation_status.rb +24 -30
  26. data/lib/crowdin-api/{api-resources → api_resources}/translations.rb +41 -59
  27. data/lib/crowdin-api/api_resources/users.rb +161 -0
  28. data/lib/crowdin-api/api_resources/vendors.rb +21 -0
  29. data/lib/crowdin-api/api_resources/webhooks.rb +68 -0
  30. data/lib/crowdin-api/api_resources/workflows.rb +59 -0
  31. data/lib/crowdin-api/client/client.rb +72 -50
  32. data/lib/crowdin-api/client/configuration.rb +16 -12
  33. data/lib/crowdin-api/client/version.rb +1 -1
  34. data/lib/crowdin-api/core/errors.rb +2 -1
  35. data/lib/crowdin-api/core/{api_errors_raiser.rb → errors_raisers.rb} +21 -11
  36. data/lib/crowdin-api/core/request.rb +53 -88
  37. data/lib/crowdin-api/core/send_request.rb +67 -0
  38. data/lib/crowdin-api.rb +20 -11
  39. data/spec/api_resources/dictionaries_spec.rb +23 -0
  40. data/spec/api_resources/distributions_spec.rb +71 -0
  41. data/spec/api_resources/glossaries_spec.rb +167 -0
  42. data/spec/api_resources/labels_spec.rb +71 -0
  43. data/spec/api_resources/languages_spec.rb +51 -0
  44. data/spec/api_resources/machine_translation_engines_spec.rb +63 -0
  45. data/spec/api_resources/projects_spec.rb +215 -0
  46. data/spec/api_resources/reports_spec.rb +95 -0
  47. data/spec/api_resources/screenshots_spec.rb +134 -0
  48. data/spec/api_resources/source_files_spec.rb +13 -0
  49. data/spec/api_resources/source_strings_spec.rb +51 -0
  50. data/spec/api_resources/storages_spec.rb +13 -0
  51. data/spec/api_resources/string_comments_spec.rb +13 -0
  52. data/spec/api_resources/string_translations_spec.rb +13 -0
  53. data/spec/api_resources/tasks_spec.rb +79 -0
  54. data/spec/api_resources/teams_spec.rb +13 -0
  55. data/spec/api_resources/translation_memory_spec.rb +13 -0
  56. data/spec/api_resources/translation_status_spec.rb +15 -0
  57. data/spec/api_resources/translations_spec.rb +107 -0
  58. data/spec/api_resources/users_spec.rb +117 -0
  59. data/spec/api_resources/vendors_spec.rb +13 -0
  60. data/spec/api_resources/webhooks_spec.rb +51 -0
  61. data/spec/api_resources/workflows_spec.rb +41 -0
  62. data/spec/spec_helper.rb +20 -2
  63. data/spec/unit/client_spec.rb +85 -0
  64. metadata +65 -28
  65. data/bin/setup +0 -6
  66. data/lib/crowdin-api/api-resources/languages.rb +0 -81
  67. data/lib/crowdin-api/api-resources/projects.rb +0 -134
  68. data/lib/crowdin-api/api-resources/storages.rb +0 -102
  69. data/lib/crowdin-api/api-resources/workflows.rb +0 -59
  70. data/spec/core/config-instance_spec.rb +0 -72
  71. data/spec/crowdin-api_spec.rb +0 -7
@@ -1,82 +1,104 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # The Crowdin::Client library is used for interactions with a crowdin.com website.
4
+ # A wrapper and interface to the Crowdin API. Please visit the Crowdin developers site
5
+ # for a full explanation of what each of the Crowdin api methods expect and perform.
5
6
  #
6
- # == Example
7
- #
8
- # require 'crowdin-api'
9
- #
10
- # crowdin = Crowdin::Client.new do |config|
11
- # config.api_token = 'YOUR_API_TOKEN'
12
- # end
13
- #
14
- # crowdin.list_projects
7
+ # https://support.crowdin.com/api/v2/
8
+ # https://support.crowdin.com/enterprise/api/
15
9
  #
16
10
  module Crowdin
11
+ #
12
+ # === Example
13
+ #
14
+ # require 'crowdin-api'
15
+ #
16
+ # crowdin = Crowdin::Client.new do |config|
17
+ # config.api_token = 'YOUR_API_TOKEN'
18
+ # end
19
+ #
20
+ # crowdin.list_projects
21
+ #
17
22
  class Client
18
- # A wrapper and interface to the Crowdin api. Please visit the Crowdin developers
19
- # site for a full explanation of what each of the Crowdin api methods
20
- # expect and perform.
21
- #
22
- # https://support.crowdin.com/api/v2/
23
- #
24
- include ApiResources::Languages
25
- include ApiResources::Projects
26
- include ApiResources::SourceFiles
27
- include ApiResources::Storages
28
- include ApiResources::TranslationStatus
29
- include ApiResources::Translations
30
- include ApiResources::Workflows
31
- include ApiResources::SourceStrings
32
-
33
- include Errors::ApiErrorsRaiser
34
-
35
- attr_accessor :logger
23
+ # Processing API Resources modules to include them to the Client
24
+ API_RESOURCES_MODULES.each do |module_name|
25
+ Client.send(:include, Object.const_get("Crowdin::ApiResources::#{module_name}"))
26
+ end
36
27
 
28
+ # Processing Error Raisers modules to include them to the Client
29
+ ERROR_RAISERS_MODULES.each do |module_name|
30
+ Client.send(:include, Object.const_get("Crowdin::Errors::#{module_name}"))
31
+ end
32
+
33
+ # Config instance that includes configuration options for the Client
37
34
  attr_reader :config
35
+ # Instance with established connection through RestClient to the Crowdin API
38
36
  attr_reader :connection
37
+ # Instance with options and headers for RestClient connection
39
38
  attr_reader :options
39
+ # Logger instance
40
+ attr_reader :logger
40
41
 
41
42
  def initialize(&block)
42
43
  build_configuration(&block)
43
44
 
44
- check_logger
45
- check_rest_client_proxy
45
+ update_logger
46
+ update_rest_client_proxy
46
47
 
47
48
  build_connection
48
49
  end
49
50
 
50
- def log!(message)
51
- !config.logger_enabled? || logger.debug(message)
51
+ def log(message)
52
+ !logger_enabled? || logger.debug(message)
52
53
  end
53
54
 
54
- private
55
+ def logger=(logger)
56
+ raise_logger_are_not_enabled_error unless logger_enabled?
55
57
 
56
- def build_configuration
57
- @config = Crowdin::Configuration.new
58
- yield config if block_given?
58
+ @logger = logger
59
+ update_rest_client_logger
59
60
  end
60
61
 
61
- def build_connection
62
- @connection ||= ::RestClient::Resource.new(config.base_url, build_options)
62
+ def enterprise_mode?
63
+ !!config.organization_domain
63
64
  end
64
65
 
65
- def build_options
66
- @options ||= config.options.merge(headers: config.headers)
66
+ def logger_enabled?
67
+ config.logger_enabled?
67
68
  end
68
69
 
69
- def set_default_logger
70
- require 'logger'
71
- @logger ||= Logger.new($stderr)
72
- end
70
+ private
73
71
 
74
- def check_rest_client_proxy
75
- ENV['http_proxy'] ? ::RestClient.proxy = ENV['http_proxy'] : false
76
- end
72
+ def build_configuration
73
+ @config = Crowdin::Configuration.new
74
+ yield config if block_given?
75
+ end
77
76
 
78
- def check_logger
79
- config.logger_enabled? ? set_default_logger : config.enable_logger = false
80
- end
77
+ def build_connection
78
+ build_options
79
+ @connection ||= ::RestClient::Resource.new(config.base_url, options)
80
+ end
81
+
82
+ def build_options
83
+ @options ||= config.options.merge(headers: config.headers)
84
+ end
85
+
86
+ def set_default_logger
87
+ require 'logger'
88
+ @logger ||= Logger.new($stdout)
89
+ update_rest_client_logger
90
+ end
91
+
92
+ def update_rest_client_logger
93
+ ::RestClient.log = @logger
94
+ end
95
+
96
+ def update_rest_client_proxy
97
+ ENV['http_proxy'] ? ::RestClient.proxy = ENV.fetch('http_proxy') : false
98
+ end
99
+
100
+ def update_logger
101
+ config.logger_enabled? ? set_default_logger : config.enable_logger = false
102
+ end
81
103
  end
82
104
  end
@@ -5,13 +5,12 @@ module Crowdin
5
5
  attr_accessor :api_token
6
6
  attr_accessor :project_id
7
7
  attr_accessor :organization_domain
8
+
8
9
  attr_accessor :enable_logger
10
+ alias logger_enabled? enable_logger
9
11
 
10
12
  attr_reader :target_api_url
11
13
 
12
- alias logger_enabled? enable_logger
13
- alias enterprise_mode? organization_domain
14
-
15
14
  def initialize
16
15
  @target_api_url = '/api/v2'
17
16
  end
@@ -20,25 +19,30 @@ module Crowdin
20
19
  {
21
20
  headers: {},
22
21
  timeout: nil,
23
- json: true
22
+ json: true
24
23
  }
25
24
  end
26
25
 
27
26
  def headers
28
27
  {
29
- 'Accept' => 'application/json',
28
+ 'Accept' => 'application/json',
30
29
  'Authorization' => "Bearer #{api_token}",
31
- 'Content-Type' => 'application/json',
32
- 'User-Agent' => "crowdin-rb/#{Crowdin::Client::VERSION}/#{RUBY_VERSION}/#{RUBY_PLATFORM}"
30
+ 'Content-Type' => 'application/json',
31
+ 'User-Agent' => "crowdin-rb/#{Crowdin::Client::VERSION}/#{RUBY_VERSION}/#{RUBY_PLATFORM}"
33
32
  }
34
33
  end
35
34
 
36
35
  def base_url
37
- if enterprise_mode?
38
- organization_domain.include?('.com') ? organization_domain : "https://#{organization_domain}.api.crowdin.com"
39
- else
40
- 'https://api.crowdin.com'
41
- end
36
+ @base_url ||=
37
+ if !!organization_domain
38
+ if organization_domain.include?('.com')
39
+ "https://#{organization_domain}"
40
+ else
41
+ "https://#{organization_domain}.api.crowdin.com"
42
+ end
43
+ else
44
+ 'https://api.crowdin.com'
45
+ end
42
46
  end
43
47
  end
44
48
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Crowdin
4
4
  class Client
5
- VERSION = '1.1.1'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Crowdin
4
4
  module Errors
5
- class OnlyForEnterpriseMode < StandardError; end
5
+ class OnlyForEnterpriseModeError < StandardError; end
6
+ class LoggerAreNotEnabledError < StandardError; end
6
7
  end
7
8
  end
@@ -2,9 +2,29 @@
2
2
 
3
3
  module Crowdin
4
4
  module Errors
5
+ # Client errors raiser
6
+ module ClientErrorsRaiser
7
+ def raise_logger_are_not_enabled_error
8
+ raise(LoggerAreNotEnabledError, 'Logger are not enabled in your Client configuration, enable it ' \
9
+ 'before setting your logger')
10
+ end
11
+ end
12
+
13
+ # Command-Line Client errors raiser
14
+ module ClcErrorsRaiser
15
+ def raise_api_token_is_required_error
16
+ raise(ArgumentError, '--api-token option is required')
17
+ end
18
+
19
+ def raise_organization_domain_is_required_error
20
+ raise(ArgumentError, '--organization-domain option is required for Enterprise mode')
21
+ end
22
+ end
23
+
24
+ # API errors raiser
5
25
  module ApiErrorsRaiser
6
26
  def raise_only_for_enterprise_mode_error
7
- raise(OnlyForEnterpriseMode, 'This method can be called only for Enterprise mode')
27
+ raise(OnlyForEnterpriseModeError, 'This method can be called only for Enterprise mode')
8
28
  end
9
29
 
10
30
  def raise_project_id_is_required_error
@@ -14,16 +34,6 @@ module Crowdin
14
34
  def raise_parameter_is_required_error(parameter)
15
35
  raise(ArgumentError, ":#{parameter} is required")
16
36
  end
17
-
18
- # crowdin-console errors
19
-
20
- def raise_api_token_is_required_error
21
- raise(ArgumentError, '--api-token option is required')
22
- end
23
-
24
- def raise_organization_domain_is_required_error
25
- raise(ArgumentError, '--organization-domain option is required for Enterprise mode')
26
- end
27
37
  end
28
38
  end
29
39
  end
@@ -3,116 +3,81 @@
3
3
  module Crowdin
4
4
  module Web
5
5
  class Request
6
- attr_reader :client
7
-
8
- def initialize(client, method, path, query = {}, headers = {}, destination = nil)
9
- @client = client
10
- @method = method
11
- @full_path = client.config.target_api_url + path
12
- @payload = perform_payload(query)
13
- @headers = headers
14
- @destination = destination
15
- @errors = []
6
+ attr_reader :connection
7
+ attr_reader :method
8
+ attr_reader :payload
9
+
10
+ def initialize(connection, method, url, payload = {})
11
+ @connection = connection[url]
12
+ @method = method
13
+ @payload = build_payload(payload)
16
14
  end
17
15
 
18
- def perform
19
- process_request!
20
- process_response!
16
+ def get?
17
+ method.eql?(:get)
21
18
  end
22
19
 
23
- private
24
-
25
- def process_request!
26
- return @response = client.connection[@full_path].delete if delete_request?
27
- return @response = client.connection[@full_path].get(@payload) if get_request?
28
-
29
- client.connection[@full_path].send(@method, @payload, @headers) { |response, _, _| @response = response }
30
- rescue StandardError => error
31
- client.log! error
32
-
33
- @errors << "Something went wrong while proccessing request. Details - #{error.class}"
20
+ def get
21
+ connection.get(prepare_payload(payload[:params]))
34
22
  end
35
23
 
36
- def process_response!
37
- return fetch_errors if @errors.any?
38
-
39
- begin
40
- if @response
41
- client.log! "args: #{@response.request.args}"
42
-
43
- if @response.body.empty?
44
- @response.code
45
- else
46
- doc = JSON.parse(@response.body)
47
-
48
- client.log! "body: #{doc}"
49
-
50
- data = fetch_response_data(doc)
51
-
52
- @errors.any? ? fetch_errors : data
53
- end
54
- end
55
- rescue StandardError => error
56
- client.log! error
57
-
58
- @errors << "Something went wrong while proccessing response. Details - #{error.class}"
59
-
60
- fetch_errors
61
- end
24
+ def delete?
25
+ method.eql?(:delete)
62
26
  end
63
27
 
64
- def perform_payload(query)
65
- return query if query.is_a?(File)
66
-
67
- get_request? ? { params: fetch_cleared_query(query) } : fetch_cleared_query(query).to_json
28
+ def delete
29
+ connection.delete
68
30
  end
69
31
 
70
- def download_file(url)
71
- download = URI.parse(url).open
72
- destination = @destination || download.meta['content-disposition']
73
- .match(/filename=("?)(.+)\1/)[2]
32
+ def patch?
33
+ method.eql?(:patch)
34
+ end
74
35
 
75
- IO.copy_stream(download, destination)
36
+ def patch
37
+ connection.patch(prepare_payload(payload[:params]), payload[:headers]) { |response, _, _| response }
38
+ end
76
39
 
77
- destination
78
- rescue StandardError => error
79
- client.log! error
40
+ def post?
41
+ method.eql?(:post)
42
+ end
80
43
 
81
- @errors << "Something went wrong while downloading file. Details - #{error.class}"
44
+ def post
45
+ connection.post(prepare_payload(payload[:params]), payload[:headers]) { |response, _, _| response }
82
46
  end
83
47
 
84
- def fetch_errors
85
- @errors.join(';')
48
+ def put?
49
+ method.eql?(:put)
86
50
  end
87
51
 
88
- def fetch_response_data(doc)
89
- if doc['data'].is_a?(Hash) && doc['data']['url'] && doc['data']['url'].include?('response-content-disposition')
90
- download_file(doc['data']['url'])
91
- else
92
- doc
93
- end
52
+ def put
53
+ connection.put(prepare_payload(payload[:params]), payload[:headers]) { |response, _, _| response }
94
54
  end
95
55
 
96
- def fetch_cleared_query(query)
97
- case query
98
- when Array
99
- query.map do |el|
100
- el.reject { |_, value| value.nil? }
101
- end.reject(&:empty?)
102
- when Hash
103
- query.reject { |_, value| value.nil? }
104
- else
105
- query
56
+ private
57
+
58
+ def build_payload(payload)
59
+ %i[params headers].each do |key|
60
+ payload[key] ||= {}
61
+ end
62
+ payload
106
63
  end
107
- end
108
64
 
109
- def get_request?
110
- @method.eql?(:get)
111
- end
65
+ def prepare_payload(params)
66
+ return params if params.is_a?(File)
112
67
 
113
- def delete_request?
114
- @method.eql?(:delete)
115
- end
68
+ get? ? { params: fetch_cleared_params(params) } : fetch_cleared_params(params).to_json
69
+ end
70
+
71
+ def fetch_cleared_params(params)
72
+ case params
73
+ when Array
74
+ params.map { |el| el.reject { |_, value| value.nil? } }.reject(&:empty?)
75
+ when Hash
76
+ params.reject { |_, value| value.nil? }
77
+ else
78
+ params
79
+ end
80
+ end
116
81
  end
117
82
  end
118
83
  end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Crowdin
4
+ module Web
5
+ class SendRequest
6
+ attr_reader :request
7
+
8
+ def initialize(request, file_destination = nil)
9
+ @request = request
10
+ @file_destination = file_destination
11
+ @errors = []
12
+ end
13
+
14
+ def perform
15
+ parse_response(process_request)
16
+ end
17
+
18
+ private
19
+
20
+ def process_request
21
+ request.send(request.method)
22
+ rescue StandardError => e
23
+ @errors << "Something went wrong while request processing. Details - #{e.message}"
24
+ end
25
+
26
+ def parse_response(response)
27
+ return @errors.join('; ') if @errors.any?
28
+
29
+ begin
30
+ if response
31
+ if response.body.empty?
32
+ response.code
33
+ else
34
+ parsed_body = JSON.parse(response.body)
35
+ parsed_response = fetch_response_data(parsed_body)
36
+
37
+ @errors.any? ? @errors.join('; ') : parsed_response
38
+ end
39
+ end
40
+ rescue StandardError => e
41
+ @errors << "Something went wrong while response processing. Details - #{e.message}"
42
+ @errors.join('; ')
43
+ end
44
+ end
45
+
46
+ def fetch_response_data(doc)
47
+ if doc['data'].is_a?(Hash) && doc['data']['url'] && doc['data']['url'].include?('response-content-disposition')
48
+ download_file(doc['data']['url'])
49
+ else
50
+ doc
51
+ end
52
+ end
53
+
54
+ def download_file(url)
55
+ download = URI.parse(url).open
56
+ destination = @file_destination || download.meta['content-disposition']
57
+ .match(/filename=("?)(.+)\1/)[2]
58
+
59
+ IO.copy_stream(download, destination)
60
+
61
+ destination
62
+ rescue StandardError => e
63
+ @errors << "Something went wrong while downloading file. Details - #{e.message}"
64
+ end
65
+ end
66
+ end
67
+ end
data/lib/crowdin-api.rb CHANGED
@@ -1,5 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module Crowdin
4
+ # API Resources modules
5
+ API_RESOURCES_MODULES = %i[Storages Languages Projects Workflows SourceFiles Translations SourceStrings
6
+ StringTranslations StringComments Screenshots Glossaries TranslationMemory
7
+ MachineTranslationEngines Reports Tasks Users Teams Vendors Webhooks
8
+ Dictionaries Distributions Labels TranslationStatus].freeze
9
+
10
+ # Error Raisers modules
11
+ ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze
12
+ end
13
+
3
14
  # Libs
4
15
  require 'json'
5
16
  require 'open-uri'
@@ -7,20 +18,18 @@ require 'rest-client'
7
18
 
8
19
  # Core modules
9
20
  require 'crowdin-api/core/errors'
10
- require 'crowdin-api/core/api_errors_raiser'
21
+ require 'crowdin-api/core/errors_raisers'
11
22
  require 'crowdin-api/core/request'
23
+ require 'crowdin-api/core/send_request'
12
24
 
13
- # Api modules
14
- require 'crowdin-api/api-resources/languages'
15
- require 'crowdin-api/api-resources/projects'
16
- require 'crowdin-api/api-resources/source_files'
17
- require 'crowdin-api/api-resources/storages'
18
- require 'crowdin-api/api-resources/translation_status'
19
- require 'crowdin-api/api-resources/translations'
20
- require 'crowdin-api/api-resources/workflows'
21
- require 'crowdin-api/api-resources/source_strings'
25
+ # API modules
26
+ Crowdin::API_RESOURCES_MODULES.each do |api_resource|
27
+ require "crowdin-api/api_resources/#{api_resource.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase}"
28
+ rescue LoadError
29
+ # Ignored
30
+ end
22
31
 
23
- # Client
32
+ # Client modules
24
33
  require 'crowdin-api/client/version'
25
34
  require 'crowdin-api/client/configuration'
26
35
  require 'crowdin-api/client/client'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Dictionaries do
4
+ describe 'Default endpoints' do
5
+ describe '#list_dictionaries' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/dictionaries")
8
+ list_dictionaries = @crowdin.list_dictionaries({}, project_id)
9
+ expect(list_dictionaries).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#edit_dictionary' do
14
+ let(:language_id) { 1 }
15
+
16
+ it 'when request are valid', :default do
17
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/dictionaries/#{language_id}")
18
+ edit_dictionary = @crowdin.edit_dictionary(language_id, {}, project_id)
19
+ expect(edit_dictionary).to eq(200)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Crowdin::ApiResources::Distributions do
4
+ describe 'Default endpoints' do
5
+ describe '#list_distributions' do
6
+ it 'when request are valid', :default do
7
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions")
8
+ list_distributions = @crowdin.list_distributions({}, project_id)
9
+ expect(list_distributions).to eq(200)
10
+ end
11
+ end
12
+
13
+ describe '#add_distribution' do
14
+ it 'when request are valid', :default do
15
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions")
16
+ add_distribution = @crowdin.add_distribution({}, project_id)
17
+ expect(add_distribution).to eq(200)
18
+ end
19
+ end
20
+
21
+ describe '#get_distribution' do
22
+ let(:hash) { 1 }
23
+
24
+ it 'when request are valid', :default do
25
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions/#{hash}")
26
+ get_distribution = @crowdin.get_distribution(hash, project_id)
27
+ expect(get_distribution).to eq(200)
28
+ end
29
+ end
30
+
31
+ describe '#delete_distribution' do
32
+ let(:hash) { 1 }
33
+
34
+ it 'when request are valid', :default do
35
+ stub_request(:delete, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions/#{hash}")
36
+ delete_distribution = @crowdin.delete_distribution(hash, project_id)
37
+ expect(delete_distribution).to eq(200)
38
+ end
39
+ end
40
+
41
+ describe '#edit_distribution' do
42
+ let(:hash) { 1 }
43
+
44
+ it 'when request are valid', :default do
45
+ stub_request(:patch, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions/#{hash}")
46
+ edit_distribution = @crowdin.edit_distribution(hash, {}, project_id)
47
+ expect(edit_distribution).to eq(200)
48
+ end
49
+ end
50
+
51
+ describe '#get_distribution_release' do
52
+ let(:hash) { 1 }
53
+
54
+ it 'when request are valid', :default do
55
+ stub_request(:get, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions/#{hash}/release")
56
+ get_distribution_release = @crowdin.get_distribution_release(hash, project_id)
57
+ expect(get_distribution_release).to eq(200)
58
+ end
59
+ end
60
+
61
+ describe '#release_distribution' do
62
+ let(:hash) { 1 }
63
+
64
+ it 'when request are valid', :default do
65
+ stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/distributions/#{hash}/release")
66
+ release_distribution = @crowdin.release_distribution(hash, project_id)
67
+ expect(release_distribution).to eq(200)
68
+ end
69
+ end
70
+ end
71
+ end