loco-rb 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 206e7b0e2b517985ead122d426453905eff36f523dcb413ac096fb97384e8674
4
- data.tar.gz: b45d912a7d2f8ce5cd604e03d34701e5a999bb21a1a9a25a33077540282aeb7e
3
+ metadata.gz: 2fc7ba233f13ce60d62bbc5b14b17974c5105b056693e3ecbf06fabcdafb2bce
4
+ data.tar.gz: 6c80afc1af56d4c825be427adf08f72da38ca8fd19c48e85992c634eb6494f81
5
5
  SHA512:
6
- metadata.gz: b355529324747b5ad437e9e70dd35cb21d74c6f4ee4ddf2f157d8d1f409013737aa7d414e283ff402e4f758b68291cde1350b08797e9627be227a877bac4b98b
7
- data.tar.gz: 253a49f4d26c4b5a0c2ec1bbb649845da14abf78fc8fcb616881b34e9f4c5c4a831087f4101c8d7b9b837b92a2347c13a390a2cee2d44806045b534347db4d68
6
+ metadata.gz: f48d608b516d9b1ee044e2b6101d967d75b1fdf50a38aeeedf6d2b2009a0c2eeaf43ecb3f2b785ff504b8a19d44fcc59eba6879c1b678089a3665c961f5f7c86
7
+ data.tar.gz: 5fa9447cdc99ece9f57db9c40419a784f8bc29bad468420aa520692074718dce9706a371101dec36960e45ce8ca7b80e7bd492a367d1b43d37f4fa3ab4cb7c45
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile CHANGED
@@ -4,4 +4,6 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
- gem "minitest", "~> 5.0"
7
+ gem 'faraday', '~> 1.10.0'
8
+ gem 'rspec', '~> 3.5'
9
+ gem 'webmock', '~> 3.14'
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ loco-rb (0.1.0)
5
+ faraday (~> 1.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ crack (0.4.5)
13
+ rexml
14
+ diff-lcs (1.5.0)
15
+ faraday (1.10.0)
16
+ faraday-em_http (~> 1.0)
17
+ faraday-em_synchrony (~> 1.0)
18
+ faraday-excon (~> 1.1)
19
+ faraday-httpclient (~> 1.0)
20
+ faraday-multipart (~> 1.0)
21
+ faraday-net_http (~> 1.0)
22
+ faraday-net_http_persistent (~> 1.0)
23
+ faraday-patron (~> 1.0)
24
+ faraday-rack (~> 1.0)
25
+ faraday-retry (~> 1.0)
26
+ ruby2_keywords (>= 0.0.4)
27
+ faraday-em_http (1.0.0)
28
+ faraday-em_synchrony (1.0.0)
29
+ faraday-excon (1.1.0)
30
+ faraday-httpclient (1.0.1)
31
+ faraday-multipart (1.0.3)
32
+ multipart-post (>= 1.2, < 3)
33
+ faraday-net_http (1.0.1)
34
+ faraday-net_http_persistent (1.2.0)
35
+ faraday-patron (1.0.0)
36
+ faraday-rack (1.0.0)
37
+ faraday-retry (1.0.3)
38
+ hashdiff (1.0.1)
39
+ multipart-post (2.2.0)
40
+ public_suffix (4.0.7)
41
+ rake (12.3.3)
42
+ rexml (3.2.5)
43
+ rspec (3.11.0)
44
+ rspec-core (~> 3.11.0)
45
+ rspec-expectations (~> 3.11.0)
46
+ rspec-mocks (~> 3.11.0)
47
+ rspec-core (3.11.0)
48
+ rspec-support (~> 3.11.0)
49
+ rspec-expectations (3.11.0)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.11.0)
52
+ rspec-mocks (3.11.1)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.11.0)
55
+ rspec-support (3.11.0)
56
+ ruby2_keywords (0.0.5)
57
+ webmock (3.14.0)
58
+ addressable (>= 2.8.0)
59
+ crack (>= 0.3.2)
60
+ hashdiff (>= 0.4.0, < 2.0.0)
61
+
62
+ PLATFORMS
63
+ universal-darwin-21
64
+
65
+ DEPENDENCIES
66
+ faraday (~> 1.10.0)
67
+ loco-rb!
68
+ rake (~> 12.0)
69
+ rspec (~> 3.5)
70
+ webmock (~> 3.14)
71
+
72
+ BUNDLED WITH
73
+ 2.3.6
@@ -0,0 +1,29 @@
1
+ module LocoRb
2
+ module Api
3
+ module Asset
4
+ PATH = 'assets'
5
+ CREATE_PARAMS = %i[id text type context notes default].freeze
6
+
7
+ def get_assets(options={})
8
+ opts = {}
9
+ opts[:params] = { filter: options[:filter].join(',') } if options.dig( :filter)
10
+ response = get(PATH, opts)
11
+ response.data.map do |asset|
12
+ LocoRb::Resource::Asset.new(asset, response.headers, 'asset')
13
+ end
14
+ end
15
+
16
+ def create_asset(options={})
17
+ opts = {}
18
+ options.each do |key, value|
19
+ if CREATE_PARAMS.include?(key)
20
+ opts[:body] = {} unless opts.key?(:body)
21
+ opts[:body][key] = value
22
+ end
23
+ end
24
+ response = post(PATH, opts)
25
+ LocoRb::Resource::Asset.new(response.data, response.headers, 'asset')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module LocoRb
2
+ module Api
3
+ module Export
4
+ PATH = 'export'
5
+
6
+ def export_locale(options={locale: 'en', ext: 'json'})
7
+ response = get("#{PATH}/locale/#{options[:locale]}.#{options[:ext]}")
8
+ LocoRb::Resource::Locale.new(response.data, response.headers, 'locale').table
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module LocoRb
2
+ module Api
3
+ module Import
4
+ PATH = 'import'
5
+
6
+ def import_locale(options={ext: 'json'})
7
+ opts = {}
8
+ opts[:params] = { locale: options[:locale] } if options.dig( :locale)
9
+ opts[:params] = opts[:params].merge({ "tag-updated": options[:tag_updated] }) if options.dig( :tag_updated)
10
+ opts[:body] = IO.read(options[:path])
11
+ response = post("#{PATH}/#{options[:ext] || 'json'}", opts)
12
+ LocoRb::Resource::Import.new(response.data, response.headers, 'import')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module LocoRb
2
+ module Api
3
+ module Locale
4
+ PATH = 'locales'
5
+ CREATE_PARAMS = %i[code].freeze
6
+
7
+ def create_locale(options={})
8
+ opts = {}
9
+ options.each do |key, value|
10
+ if CREATE_PARAMS.include?(key)
11
+ opts[:body] = {} unless opts.key?(:body)
12
+ opts[:body][key] = value
13
+ end
14
+ end
15
+ response = post(PATH, opts)
16
+ LocoRb::Resource::Locale.new(response.data, response.headers, 'locale')
17
+ end
18
+
19
+ def get_locale(options={code: 'en'})
20
+ response = get("#{PATH}/#{options[:code]}")
21
+ LocoRb::Resource::Locale.new(response.data, response.headers, 'locale')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ require 'loco-rb/api/asset'
2
+ require 'loco-rb/api/locale'
3
+ require 'loco-rb/api/export'
4
+ require 'loco-rb/api/import'
@@ -0,0 +1,68 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'ostruct'
4
+ require 'loco-rb/resource'
5
+ require 'loco-rb/api'
6
+
7
+ module LocoRb
8
+ class Client
9
+ include LocoRb::Api::Asset
10
+ include LocoRb::Api::Locale
11
+ include LocoRb::Api::Export
12
+ include LocoRb::Api::Import
13
+
14
+ FILE_FORMAT = %w[application/pdf application/zip]
15
+
16
+ attr_accessor :options
17
+
18
+ private
19
+
20
+ def get(path, options={})
21
+ request_method(path, :get, options)
22
+ end
23
+
24
+ def post(path, options={})
25
+ request_method(path, :post, options)
26
+ end
27
+
28
+ def put(path, options={})
29
+ request_method(path, :put, options)
30
+ end
31
+
32
+ def delete(path, options={})
33
+ request_method(path, :delete, options)
34
+ end
35
+
36
+ def request_method(path, method_verb, options={})
37
+ response = request(path, method_verb, options)
38
+ validate(response)
39
+ parsed_response = parse(response)
40
+ OpenStruct.new({ headers: response.headers, data: parsed_response })
41
+ end
42
+
43
+ def request(path, method_verb, options={})
44
+ make_connection.send(method_verb) do |request|
45
+ request.url(path)
46
+ request.headers["Authorization"] = "Loco #{LocoRb.configuration.api_key}"
47
+ request.params = options[:params] if options[:params]
48
+ request.body = options[:body] if options[:body]
49
+ end
50
+ end
51
+
52
+ def make_connection
53
+ Faraday.new(url: LocoRb::Configuration::DEFAULT_ENDPOINT)
54
+ end
55
+
56
+ def validate(response)
57
+ raise LocoRb::Error.new(response.body) if response.status >= 400
58
+ end
59
+
60
+ def parse(response)
61
+ return response.body if FILE_FORMAT.include?(response['content-type'])
62
+ return {} if response.body.strip.empty?
63
+
64
+ JSON.parse(response.body.strip)
65
+ end
66
+ end
67
+ end
68
+
@@ -0,0 +1,14 @@
1
+ module LocoRb
2
+ class Configuration
3
+
4
+ DEFAULT_ENDPOINT = 'https://localise.biz/api'
5
+
6
+ attr_accessor :api_key, :locale_paths
7
+
8
+ def initialize
9
+ @api_key = nil
10
+ @locale_paths = []
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'loco-rb/resource/base_resource'
2
+
3
+ module LocoRb
4
+ module Resource
5
+ class Asset < LocoRb::Resource::BaseResource
6
+ def initialize(asset, headers, key='asset')
7
+ super(asset, headers, key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module LocoRb
2
+ module Resource
3
+ class BaseResource < OpenStruct
4
+ attr_reader :key, :headers
5
+ def initialize(resource, headers, key=nil)
6
+ @key = key
7
+ @headers = headers
8
+ super(resource)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'loco-rb/resource/base_resource'
2
+
3
+ module LocoRb
4
+ module Resource
5
+ class Export < LocoRb::Resource::BaseResource
6
+ def initialize(asset, headers, key='export')
7
+ super(asset, headers, key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'loco-rb/resource/base_resource'
2
+
3
+ module LocoRb
4
+ module Resource
5
+ class Import < LocoRb::Resource::BaseResource
6
+ def initialize(asset, headers, key='import')
7
+ super(asset, headers, key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'loco-rb/resource/base_resource'
2
+
3
+ module LocoRb
4
+ module Resource
5
+ class Locale < LocoRb::Resource::BaseResource
6
+ def initialize(asset, headers, key='locale')
7
+ super(asset, headers, key)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ require 'loco-rb/resource/asset'
2
+ require 'loco-rb/resource/locale'
3
+ require 'loco-rb/resource/import'
4
+ require 'loco-rb/resource/export'
@@ -1,3 +1,3 @@
1
1
  module LocoRb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/loco-rb.rb CHANGED
@@ -1,6 +1,15 @@
1
1
  require "loco-rb/version"
2
+ require "loco-rb/configuration"
3
+ require "loco-rb/client"
2
4
 
3
5
  module LocoRb
4
6
  class Error < StandardError; end
5
- # Your code goes here...
7
+
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration)
14
+ end
6
15
  end
data/loco-rb.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = %q{Ruby client for Localize.biz Developer API}
11
11
  spec.homepage = "https://github.com/mahesh-karipe/loco-rb"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.0.0")
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://github.com/mahesh-karipe/loco-rb"
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
+ spec.add_runtime_dependency "faraday", ['~> 1.10.0']
27
28
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loco-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mahesh Karipe
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-25 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.0
13
27
  description: Ruby client for Localize.biz Developer API
14
28
  email:
15
29
  - mahesh.karipe@ooma.com
@@ -18,16 +32,31 @@ extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - ".gitignore"
35
+ - ".rspec"
21
36
  - ".travis.yml"
22
37
  - CHANGELOG.md
23
38
  - CODE_OF_CONDUCT.md
24
39
  - Gemfile
40
+ - Gemfile.lock
25
41
  - LICENSE.txt
26
42
  - README.md
27
43
  - Rakefile
28
44
  - bin/console
29
45
  - bin/setup
30
46
  - lib/loco-rb.rb
47
+ - lib/loco-rb/api.rb
48
+ - lib/loco-rb/api/asset.rb
49
+ - lib/loco-rb/api/export.rb
50
+ - lib/loco-rb/api/import.rb
51
+ - lib/loco-rb/api/locale.rb
52
+ - lib/loco-rb/client.rb
53
+ - lib/loco-rb/configuration.rb
54
+ - lib/loco-rb/resource.rb
55
+ - lib/loco-rb/resource/asset.rb
56
+ - lib/loco-rb/resource/base_resource.rb
57
+ - lib/loco-rb/resource/export.rb
58
+ - lib/loco-rb/resource/import.rb
59
+ - lib/loco-rb/resource/locale.rb
31
60
  - lib/loco-rb/version.rb
32
61
  - loco-rb.gemspec
33
62
  homepage: https://github.com/mahesh-karipe/loco-rb
@@ -45,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
74
  requirements:
46
75
  - - ">="
47
76
  - !ruby/object:Gem::Version
48
- version: 2.3.0
77
+ version: 2.0.0
49
78
  required_rubygems_version: !ruby/object:Gem::Requirement
50
79
  requirements:
51
80
  - - ">="
52
81
  - !ruby/object:Gem::Version
53
82
  version: '0'
54
83
  requirements: []
55
- rubygems_version: 3.1.2
84
+ rubygems_version: 3.0.9
56
85
  signing_key:
57
86
  specification_version: 4
58
87
  summary: Ruby client for Localize.biz Developer API