diff --git a/.env.example b/.env.example index f6a3966..7ae121f 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,6 @@ -LOKALISE_API_TOKEN=123 \ No newline at end of file +LOKALISE_API_TOKEN=123 +OAUTH2_CLIENT_ID=123 +OAUTH2_CLIENT_SECRET=123 +OAUTH2_TOKEN=123 +OAUTH2_REFRESH_TOKEN=123 +OAUTH2_CODE=123 \ No newline at end of file diff --git a/docs/additional_info/changelog.md b/docs/additional_info/changelog.md index 9bb60f2..e0612a7 100644 --- a/docs/additional_info/changelog.md +++ b/docs/additional_info/changelog.md @@ -1,10 +1,10 @@ # Changelog -## 8.0.0 +## 8.0.0 (21-Jul-2023) In this version **SDK has been fully rewritten** to make it more robust, better tested, and even more comfortable to work with. While most of the methods have similar signatures, there are a few major changes. -Breaking changes: +**Breaking changes:** * Method `translation_statuses` has been renamed to `custom_translation_statuses` * Method `translation_status` has been renamed to `custom_translation_status` @@ -34,7 +34,7 @@ branch.name # => 'my-branch' branch[:name] # => 'my-branch' ``` -Updates: +**Updates:** * Added many new instance methods like `update`, `destroy`, and `reload_data`. @@ -70,6 +70,8 @@ response[:screenshot_deleted] # => true ``` * Test only with Ruby 3+ (though the SDK should still work with version 2.7+). Next major version will require Ruby 3+. +* Use WebMock for testing instead of VCR +* Use faraday-gzip version 2 and zlib version 3 ## 7.2.0 (11-Jan-2023) diff --git a/lib/ruby_lokalise_api/concerns/attrs_loadable.rb b/lib/ruby_lokalise_api/concerns/attrs_loadable.rb index 2ec1ed7..aeb3f1a 100644 --- a/lib/ruby_lokalise_api/concerns/attrs_loadable.rb +++ b/lib/ruby_lokalise_api/concerns/attrs_loadable.rb @@ -2,6 +2,7 @@ module RubyLokaliseApi module Concerns + # Allows to set supported attributes for classes module AttrsLoadable class << self def extended(klass) diff --git a/lib/ruby_lokalise_api/connection.rb b/lib/ruby_lokalise_api/connection.rb index 1e7f3d8..719acbe 100644 --- a/lib/ruby_lokalise_api/connection.rb +++ b/lib/ruby_lokalise_api/connection.rb @@ -3,7 +3,6 @@ module RubyLokaliseApi # Module to setup connection using Faraday module Connection - # Creates a new Faraday object with specified params def connection(endpoint) Faraday.new(options(endpoint), request_params_for(endpoint.client)) do |faraday| diff --git a/lib/ruby_lokalise_api/oauth2/auth.rb b/lib/ruby_lokalise_api/oauth2/auth.rb index bdf4efb..b80bd32 100644 --- a/lib/ruby_lokalise_api/oauth2/auth.rb +++ b/lib/ruby_lokalise_api/oauth2/auth.rb @@ -2,6 +2,7 @@ module RubyLokaliseApi module OAuth2 + # This class defines OAuth2 flow class Auth attr_reader :client_id, :client_secret, :timeout, :open_timeout @@ -14,10 +15,17 @@ def initialize(client_id, client_secret, params = {}) @open_timeout = params[:open_timeout] end + # Returns OAuth2 endpoint URI def oauth2_endpoint self.class.const_get(:OAUTH2_ENDPOINT) end + # Builds an OAuth2 link that customers have to visit + # in order to obtain a special code + # @return [String] + # @param scope [Array, String] + # @param redirect_uri [String] + # @param state [String] def auth(scope:, redirect_uri: nil, state: nil) get_params = { client_id: client_id, @@ -29,6 +37,10 @@ def auth(scope:, redirect_uri: nil, state: nil) oauth2_endpoint.new(self, query: 'auth', get: get_params).full_uri end + # Requests OAuth2 access token. Requires OAuth2 code obtained + # using the `.auth` method + # @return [RubyLokaliseApi::Resources::OAuth2Token] + # @param code [String] def token(code) endpoint = oauth2_endpoint.new( self, @@ -42,6 +54,9 @@ def token(code) RubyLokaliseApi::Resources::OAuth2Token.new endpoint.do_post end + # Refreshes expired OAuth2 access token. + # @return [RubyLokaliseApi::Resources::OAuth2RefreshedToken] + # @param refresh_token [String] def refresh(refresh_token) endpoint = oauth2_endpoint.new( self, diff --git a/lib/ruby_lokalise_api/utils/classes.rb b/lib/ruby_lokalise_api/utils/classes.rb index f02cd33..a28efa9 100644 --- a/lib/ruby_lokalise_api/utils/classes.rb +++ b/lib/ruby_lokalise_api/utils/classes.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module RubyLokaliseApi + # Basic utilitiy methods module Utils module Classes refine Object do @@ -9,10 +10,13 @@ def base_name name.split('::').last end + # Converts object to array unless it is already an array def to_array is_a?(Array) ? self : [self] end + # Converts object to array and then places this array + # inside hash under the provided key def to_array_obj(key) return self if is_a?(Hash) && (key?(key) || key?(key.to_s)) diff --git a/lib/ruby_lokalise_api/utils/keys.rb b/lib/ruby_lokalise_api/utils/keys.rb index d5ea41c..f7f242e 100644 --- a/lib/ruby_lokalise_api/utils/keys.rb +++ b/lib/ruby_lokalise_api/utils/keys.rb @@ -5,6 +5,8 @@ module Utils module Keys using RubyLokaliseApi::Utils::Strings + # Reads DATA_KEY for resources. DATA_KEY specifies the name of the key + # in the API response that contains the actual data def data_key_for(klass:) key = if Module.const_defined? "RubyLokaliseApi::Resources::#{klass}::DATA_KEY" Module.const_get "RubyLokaliseApi::Resources::#{klass}::DATA_KEY" @@ -15,6 +17,8 @@ def data_key_for(klass:) key.snakecase end + # Reads DATA_KEY for collections. DATA_KEY specifies the name of the key + # in the API response that contains the actual data def collection_key_for(klass:) key = if Module.const_defined?("RubyLokaliseApi::Collections::#{klass}::DATA_KEY") Module.const_get("RubyLokaliseApi::Collections::#{klass}::DATA_KEY") diff --git a/lib/ruby_lokalise_api/utils/loaders.rb b/lib/ruby_lokalise_api/utils/loaders.rb index 3f5833f..59705f0 100644 --- a/lib/ruby_lokalise_api/utils/loaders.rb +++ b/lib/ruby_lokalise_api/utils/loaders.rb @@ -5,16 +5,19 @@ module Utils module Loaders private + # Instantiates an endpoint def endpoint(name:, client: self, params: {}) klass = RubyLokaliseApi.const_get "Endpoints::#{name}Endpoint" klass.new client, params end + # Instantiates a resource def resource(name, data) klass = RubyLokaliseApi.const_get "Resources::#{name}" klass.new data end + # Instantiates a collection def collection(name, data) klass = RubyLokaliseApi.const_get "Collections::#{name}" klass.new data diff --git a/lib/ruby_lokalise_api/version.rb b/lib/ruby_lokalise_api/version.rb index 48056b5..2eadb07 100644 --- a/lib/ruby_lokalise_api/version.rb +++ b/lib/ruby_lokalise_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RubyLokaliseApi - VERSION = '8.0.0.rc1' + VERSION = '8.0.0' end diff --git a/ruby-lokalise-api.gemspec b/ruby-lokalise-api.gemspec index f8cabf9..75cf29b 100644 --- a/ruby-lokalise-api.gemspec +++ b/ruby-lokalise-api.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'addressable', '~> 2.5' spec.add_dependency 'faraday', '~> 2.0' - spec.add_dependency 'faraday-gzip', '>= 0.1', '< 2.0' + spec.add_dependency 'faraday-gzip', '~> 2.0' spec.add_dependency 'json', '~> 2' spec.add_dependency 'zeitwerk', '~> 2.4' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index de0467a..9d9eee0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -33,6 +33,5 @@ config.before(:suite) do Fixtures.eager_load - WebMock.allow_net_connect! end end