Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sugan0tech committed Nov 13, 2023
2 parents 9c912f8 + a167f9c commit cc4c139
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

:tada: First off, thanks for taking the time to contribute! :tada:

The Crowdin API client provides methods that essentially call Crowdin's APIs. This makes it much easier for other developers to make calls to Crowdin's APIs, as the client abstracts a lot of the work required. In short, the API client provides a lightweight interface for making API requests to Crowdin.

The following is a set of guidelines for contributing to Crowdin Ruby Client. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.

This project and everyone participating in it are governed by the [Code of Conduct](/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.
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,8 @@ 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 Bundles Applications].freeze
Dictionaries Distributions Labels TranslationStatus Bundles Notifications
Applications].freeze

# Error Raisers modules
ERROR_RAISERS_MODULES = %i[ApiErrorsRaiser ClientErrorsRaiser].freeze
Expand Down
4 changes: 1 addition & 3 deletions lib/crowdin-api/api_resources/applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
module Crowdin
module ApiResources
module Applications

# * {https://developer.crowdin.com/api/v2/#operation/api.projects.applications.api.get API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.get API Documentation}
def get_application_data(query = {}, application_identifier = nil, path = nil )
def get_application_data(application_identifier = nil, path = nil)
application_identifier || raise_parameter_is_required_error(:application_identifier)
application_identifier || raise_parameter_is_required_error(:path)

Expand Down Expand Up @@ -63,7 +62,6 @@ def delete_application_data(query = {}, application_identifier = nil, path = nil
Web::SendRequest.new(request).perform
end


# * {https://developer.crowdin.com/api/v2/#operation/api.projects.applications.api.patch API Documentation}
# * {https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.applications.api.patch API Documentation}
def edit_application_data(query = {}, application_identifier = nil, path = nil)
Expand Down
53 changes: 53 additions & 0 deletions lib/crowdin-api/api_resources/notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

module Crowdin
module ApiResources
module Notifications
def send_notification_to_authenticated_user(query = {})
%i[message].each do |param|
query[param] || raise_parameter_is_required_error(param)
end

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

def send_notification_to_organization_members(query = {})
enterprise_mode? || raise_only_for_enterprise_mode_error

%i[message].each do |param|
query[param] || raise_parameter_is_required_error(param)
end

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

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

%i[message].each do |param|
query[param] || raise_parameter_is_required_error(param)
end

request = Web::Request.new(
connection,
:post,
"#{config.target_api_url}/projects/#{project_id}/notify",
{ params: query }
)
Web::SendRequest.new(request).perform
end
end
end
end
6 changes: 2 additions & 4 deletions spec/api_resources/applications_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# frozen_string_literal: true

describe Crowdin::ApiResources::Applications do
let(:application_identifier) {"identifier of the application"}
let(:path) {"application implemented path"}
let(:application_identifier) { 'identifier of the application' }
let(:path) { 'application implemented path' }
describe 'Default endpoints' do

describe '#get_application_data' do
it 'when request are valid', :default do
stub_request(:get, "https://api/crowdin.com/#{target_api_url}/applications/#{application_identifier}/api/#{path}")
Expand Down Expand Up @@ -44,6 +43,5 @@
expect(get_application_data).to eq(200)
end
end

end
end
64 changes: 64 additions & 0 deletions spec/api_resources/notifications_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

describe Crowdin::ApiResources::Notifications do
describe 'Default endpoints' do
describe '#send_notification_to_authenticated_user' do
it 'when request are valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/notify")
.with(body: { 'message' => 'New notification message' })
query = { message: 'New notification message' }
response = @crowdin.send_notification_to_authenticated_user(query)
expect(response).to eq(200)
end

it 'raises ArgumentError when request is missing required query parameter', :default do
expect do
@crowdin.send_notification_to_authenticated_user({})
end.to raise_error(ArgumentError, ':message is required')
end
end

describe '#send_notifications_to_project_members' do
let(:project_id) { 1 }

it 'when request are valid', :default do
stub_request(:post, "https://api.crowdin.com/#{target_api_url}/projects/#{project_id}/notify")
.with(body: { 'message' => 'New notification message' })
query = { message: 'New notification message' }
response = @crowdin.send_notifications_to_project_members(query, project_id)
expect(response).to eq(200)
end

it 'raises ArgumentError when request is missing required query parameter', :default do
expect do
@crowdin.send_notifications_to_project_members({}, project_id)
end.to raise_error(ArgumentError, ':message is required')
end

it 'raises ArgumentError when request is missing project_id parameter', :default do
query = { message: 'New notification message' }
expect do
@crowdin.send_notifications_to_project_members(query, nil)
end.to raise_error(ArgumentError, ':project_id is required in parameters or while Client initialization')
end
end
end

describe 'Enterprise endpoints' do
describe '#send_notification_to_organization_members' do
it 'when request are valid', :enterprise do
stub_request(:post, "https://domain.api.crowdin.com/#{target_api_url}/notify")
.with(body: { 'message' => 'New notification message' })
query = { message: 'New notification message' }
response = @crowdin.send_notification_to_organization_members(query)
expect(response).to eq(200)
end

it 'raises ArgumentError when request is missing required query parameter', :enterprise do
expect do
@crowdin.send_notification_to_organization_members({})
end.to raise_error(ArgumentError, ':message is required')
end
end
end
end

0 comments on commit cc4c139

Please sign in to comment.