Skip to content

Commit

Permalink
Version 8
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Jul 21, 2023
1 parent e90eead commit f5e7234
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
LOKALISE_API_TOKEN=123
LOKALISE_API_TOKEN=123
OAUTH2_CLIENT_ID=123
OAUTH2_CLIENT_SECRET=123
OAUTH2_TOKEN=123
OAUTH2_REFRESH_TOKEN=123
OAUTH2_CODE=123
8 changes: 5 additions & 3 deletions docs/additional_info/changelog.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lokalise_api/concerns/attrs_loadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module RubyLokaliseApi
module Concerns
# Allows to set supported attributes for classes
module AttrsLoadable
class << self
def extended(klass)
Expand Down
1 change: 0 additions & 1 deletion lib/ruby_lokalise_api/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
15 changes: 15 additions & 0 deletions lib/ruby_lokalise_api/oauth2/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module RubyLokaliseApi
module OAuth2
# This class defines OAuth2 flow
class Auth
attr_reader :client_id, :client_secret, :timeout, :open_timeout

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_lokalise_api/utils/classes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module RubyLokaliseApi
# Basic utilitiy methods
module Utils
module Classes
refine Object do
Expand All @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_lokalise_api/utils/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_lokalise_api/utils/loaders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lokalise_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RubyLokaliseApi
VERSION = '8.0.0.rc1'
VERSION = '8.0.0'
end
2 changes: 1 addition & 1 deletion ruby-lokalise-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@

config.before(:suite) do
Fixtures.eager_load
WebMock.allow_net_connect!
end
end

0 comments on commit f5e7234

Please sign in to comment.