phraseapp-rest 0.2.0 → 0.3.0

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: aeb5a1f70cc0b3bbc18e09db604d9d4d371dc1c2cd3be5c3654a6bcb1ec95df3
4
- data.tar.gz: 8d59180055808da44bda6677f6250391660efa02afc710fea82a27329212219a
3
+ metadata.gz: dcf5df54e3d660ea4a82d27e471fe32c871833e8d9b88b9ad17991eea0b0112a
4
+ data.tar.gz: cecae224b2fb9f3606b46a0fa368e1e2d9e25b41dc97ebc80aa693516bc999b9
5
5
  SHA512:
6
- metadata.gz: 8db678e36e6c2be20a1a852a5a67b967636af6f84737ee698793f691f395f2c69693fe891a35fd193a503f0c2b95ff678a891713b5880d362a000dfa50741f15
7
- data.tar.gz: 31079849e5161246bd714439d9e0d11b26cdd2bd12ab8450f5093c433e5cb50b615530d74a84d97d0874535c60403ef7debe6e83a74cbb0bc4cd49a40ad647a5
6
+ metadata.gz: e83f4398a972cc04f5dd89c756ce79df724d3fa5693df7da900432ea95dbd7bd453f9d9acbde328565625fb4edeaf53a9ff03f39bf62f93513f045e523f1c2f7
7
+ data.tar.gz: 8c0590aeaa06d5d2cdac8dfc110bb9815355cd6e05ec0d79cd33d1908abd08cee01d045cbd3ae9c8c054e34d6c44e3811d0029a4df5c6402e40bf6486310f8f4
@@ -4,22 +4,21 @@ module Phraseapp
4
4
  module Rest
5
5
  class Api
6
6
  BASE_URL = 'https://api.phraseapp.com/api/v2'
7
- def initialize(rest_client: client, token: access_token)
7
+ def initialize(rest_client:, token:)
8
8
  @client = rest_client
9
9
  @token = token
10
10
  end
11
11
 
12
12
  def get(path)
13
- rsp, err = @client::Request.execute(
13
+ rsp, _err = @client::Request.execute(
14
14
  url: "#{BASE_URL}#{path}",
15
15
  method: :get,
16
16
  user: @token,
17
- content_type: :json, accept: :json,
18
- verify_ssl: TRUE
17
+ content_type: :json, accept: :json, verify_ssl: TRUE
19
18
  )
20
- rsp
21
- rescue RestClient::ExceptionWithResponse => e
22
- return '[]' if e.response = 404
19
+ rsp.body
20
+ rescue @client::ExceptionWithResponse => e
21
+ return '[]' if e.response.code == 404
23
22
 
24
23
  raise e
25
24
  end
@@ -22,11 +22,17 @@ module Phraseapp
22
22
 
23
23
  def to_s
24
24
  hash = {}
25
- %w(branch sort order).each do |attr|
25
+ params.each do |attr|
26
26
  hash[attr.to_sym] = send(attr) unless send(attr).nil?
27
27
  end
28
28
  hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join('&').to_s
29
29
  end
30
+
31
+ protected
32
+
33
+ def params
34
+ %w(branch sort order)
35
+ end
30
36
  end
31
37
  end
32
38
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phraseapp
4
+ module Rest
5
+ module Parameter
6
+ class Download < Base
7
+ FILE_FORMAT = ['simple_json'].freeze
8
+
9
+ attr_reader :file_format
10
+
11
+ def initialize(file_format: 'simple_json')
12
+ self.file_format = file_format
13
+ end
14
+
15
+ def file_format=(format)
16
+ raise "file format #{format} not supported" unless FILE_FORMAT.include?(format)
17
+
18
+ @file_format = format
19
+ end
20
+
21
+ protected
22
+
23
+ def params
24
+ %w(file_format)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'parser'
4
3
  require_relative 'list'
4
+ require_relative 'parser'
5
5
 
6
6
  module Phraseapp
7
7
  module Rest
8
8
  module Resource
9
9
  class Key
10
- include Parser
11
10
  include List
12
11
 
13
12
  def initialize(client:, project_id:)
@@ -16,7 +15,7 @@ module Phraseapp
16
15
  end
17
16
 
18
17
  def get(id:)
19
- parse(@client.get("#{@path}/#{id}"))
18
+ Parser.parse(@client.get("#{@path}/#{id}"))
20
19
  end
21
20
  end
22
21
  end
@@ -1,16 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
+ require_relative 'page'
5
+ require_relative 'parser'
4
6
 
5
7
  module Phraseapp
6
8
  module Rest
7
9
  module Resource
8
10
  module List
9
- def list(updated_after: nil)
10
- items = parse(@client.get(@path))
11
- items.delete_if { |i| Time.parse(i.updated_at) < updated_after } unless updated_after.nil?
11
+ def list(updated_after: nil, page: nil)
12
+ path = @path + ("&#{page}" unless page.nil?).to_s
13
+ items = Parser.parse(@client.get(path))
14
+ items = remove(items, updated_after) unless updated_after.nil?
12
15
  items
13
16
  end
17
+
18
+ private
19
+
20
+ def remove(items, updated_after)
21
+ items.delete_if { |i| Time.parse(i[:updated_at]) < updated_after }
22
+ end
14
23
  end
15
24
  end
16
25
  end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'parser'
4
3
  require_relative 'list'
4
+ require_relative 'parser'
5
+ require_relative '../parameter/download'
5
6
 
6
7
  module Phraseapp
7
8
  module Rest
8
9
  module Resource
9
10
  class Locale
10
- include Parser
11
11
  include List
12
12
 
13
13
  def initialize(client:, project_id:)
@@ -16,7 +16,13 @@ module Phraseapp
16
16
  end
17
17
 
18
18
  def get(id:)
19
- parse(@client.get("#{@path}/#{id}"))
19
+ Parser.parse(@client.get("#{@path}/#{id}"))
20
+ end
21
+
22
+ def download(id:, params: Phraseapp::Rest::Parameter::Download.new)
23
+ path = "#{@path}/#{id}/download"
24
+ path += "?#{params}" unless params.nil?
25
+ @client.get(path)
20
26
  end
21
27
  end
22
28
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Phraseapp
4
+ module Rest
5
+ module Resource
6
+ class Page
7
+ def initialize(number: 1, size: 25)
8
+ @number = number
9
+ @size = size
10
+ end
11
+
12
+ def to_s
13
+ "page=#{@number}&per_page=#{@size}"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -6,9 +6,9 @@ module Phraseapp
6
6
  module Rest
7
7
  module Resource
8
8
  module Parser
9
- OPTIONS = { max_nesting: 4, symbolize_names: TRUE, object_class: OpenStruct }.freeze
9
+ OPTIONS = { max_nesting: 4, symbolize_names: TRUE }.freeze
10
10
 
11
- def parse(json)
11
+ def self.parse(json)
12
12
  JSON.parse(json, OPTIONS)
13
13
  end
14
14
  end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'parser'
4
3
  require_relative 'list'
4
+ require_relative 'parser'
5
5
 
6
6
  module Phraseapp
7
7
  module Rest
8
8
  module Resource
9
9
  class Project
10
- include Parser
11
10
  include List
12
11
 
13
12
  def initialize(client:)
@@ -16,7 +15,7 @@ module Phraseapp
16
15
  end
17
16
 
18
17
  def get(id:)
19
- parse(@client.get("#{@path}/#{id}"))
18
+ Parser.parse(@client.get("#{@path}/#{id}"))
20
19
  end
21
20
  end
22
21
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'page'
3
4
  require_relative 'parser'
4
5
 
5
6
  module Phraseapp
6
7
  module Rest
7
8
  module Resource
8
9
  class Translation
9
- include Parser
10
10
  require_relative 'list'
11
11
 
12
12
  def initialize(client:, project_id:)
@@ -15,23 +15,25 @@ module Phraseapp
15
15
  end
16
16
 
17
17
  def get(id:)
18
- parse(@client.get("#{@path}/translations/#{id}"))
18
+ Parser.parse(@client.get("#{@path}/translations/#{id}"))
19
19
  end
20
20
 
21
- def list
22
- parse(@client.get("#{@path}/translations"))
21
+ def list(page: Resource::Page.new)
22
+ path = "#{@path}/translations"
23
+ path += querystring(page: page)
24
+ Parser.parse(@client.get(path))
23
25
  end
24
26
 
25
- def list_by_locale(locale_id: id, param: nil, query: nil)
27
+ def list_by_locale(locale_id:, param: nil, query: nil, page: Resource::Page.new)
26
28
  path = "#{@path}/locales/#{locale_id}/translations"
27
- path += querystring(param: param, query: query)
28
- parse(@client.get(path))
29
+ path += querystring(param: param, query: query, page: page)
30
+ Parser.parse(@client.get(path))
29
31
  end
30
32
 
31
33
  private
32
34
 
33
- def querystring(param: nil, query: nil)
34
- str = [param.to_s, query.to_s].join('&')
35
+ def querystring(param: nil, query: nil, page:)
36
+ str = [param, query, page].compact.map(&:to_s).join('&')
35
37
  "?#{str}" unless str.empty?
36
38
  end
37
39
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phraseapp
4
4
  module Rest
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phraseapp-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Nepote
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-20 00:00:00.000000000 Z
11
+ date: 2018-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A ruby gem to interact with Phraseapp REST resources
14
14
  email: snepote@gmail.com
@@ -21,10 +21,12 @@ files:
21
21
  - lib/phraseapp-rest/configuration.rb
22
22
  - lib/phraseapp-rest/factory.rb
23
23
  - lib/phraseapp-rest/parameter/base.rb
24
+ - lib/phraseapp-rest/parameter/download.rb
24
25
  - lib/phraseapp-rest/query/base.rb
25
26
  - lib/phraseapp-rest/resource/key.rb
26
27
  - lib/phraseapp-rest/resource/list.rb
27
28
  - lib/phraseapp-rest/resource/locale.rb
29
+ - lib/phraseapp-rest/resource/page.rb
28
30
  - lib/phraseapp-rest/resource/parser.rb
29
31
  - lib/phraseapp-rest/resource/project.rb
30
32
  - lib/phraseapp-rest/resource/translation.rb