phraseapp-rest 0.1.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 +7 -0
- data/lib/phraseapp-rest/api.rb +33 -0
- data/lib/phraseapp-rest/factory.rb +14 -0
- data/lib/phraseapp-rest/parameter/base.rb +33 -0
- data/lib/phraseapp-rest/query/base.rb +57 -0
- data/lib/phraseapp-rest/resource/key.rb +24 -0
- data/lib/phraseapp-rest/resource/list.rb +17 -0
- data/lib/phraseapp-rest/resource/locale.rb +24 -0
- data/lib/phraseapp-rest/resource/parser.rb +17 -0
- data/lib/phraseapp-rest/resource/project.rb +24 -0
- data/lib/phraseapp-rest/resource/translation.rb +40 -0
- data/lib/phraseapp-rest/version.rb +7 -0
- data/lib/phraseapp-rest.rb +10 -0
- metadata +55 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c5a5a272b0670ebe10aae74e43fad430ff6e24b37528b9de21f81e48abac480d
|
|
4
|
+
data.tar.gz: 52f2fe992459573931d2f2ae0df72fe385c9ac5b52e457fa8dfead7b124ef600
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dfbe176509ba75e52c82d7e0599e9d1939788e24c5f655b50c0624888662d1f0ed3fc56a2ca7051748dbab39bf9117ceed7861c361b0467c87a92383ce442843
|
|
7
|
+
data.tar.gz: a781f2e78575d6001db433de3d2388d2f8d7e9f3c8fbbbfb7a48ae232eeb09450cb0f5452c97165f65320b620a11be367519ea8bcb0c5cc75b96ec4520be5379
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phraseapp
|
|
4
|
+
module Rest
|
|
5
|
+
class Api
|
|
6
|
+
BASE_URL = 'https://api.phraseapp.com/api/v2'
|
|
7
|
+
def initialize(rest_client: client, token: access_token)
|
|
8
|
+
@client = rest_client
|
|
9
|
+
@token = token
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get(path)
|
|
13
|
+
response @client::Request.execute(
|
|
14
|
+
url: "#{BASE_URL}#{path}",
|
|
15
|
+
method: :get,
|
|
16
|
+
user: @token,
|
|
17
|
+
content_type: :json,
|
|
18
|
+
accept: :json,
|
|
19
|
+
verify_ssl: TRUE
|
|
20
|
+
)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def response(call)
|
|
26
|
+
rsp, err = call
|
|
27
|
+
raise err.inspect if err
|
|
28
|
+
|
|
29
|
+
rsp
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rest-client'
|
|
4
|
+
require_relative 'api'
|
|
5
|
+
|
|
6
|
+
module Phraseapp
|
|
7
|
+
module Rest
|
|
8
|
+
class Factory
|
|
9
|
+
def self.api
|
|
10
|
+
Phraseapp::Rest::Api.new(rest_client: RestClient, token: ENV['PHRASEAPP_API_KEY'])
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phraseapp
|
|
4
|
+
module Rest
|
|
5
|
+
module Parameter
|
|
6
|
+
class Base
|
|
7
|
+
attr_accessor :branch, :sort
|
|
8
|
+
attr_reader :order
|
|
9
|
+
|
|
10
|
+
def initialize(branch: nil, sort: nil, order: nil)
|
|
11
|
+
@branch = branch unless branch.nil?
|
|
12
|
+
@sort = sort unless sort.nil?
|
|
13
|
+
self.order = order unless order.nil?
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def order=(str)
|
|
17
|
+
message = "'#{str}' is not supported. Please use 'asc' or 'desc'"
|
|
18
|
+
raise message unless %w(asc desc).include?(str)
|
|
19
|
+
|
|
20
|
+
@order = str
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def to_s
|
|
24
|
+
hash = {}
|
|
25
|
+
%w(branch sort order).each do |attr|
|
|
26
|
+
hash[attr.to_sym] = send(attr) unless send(attr).nil?
|
|
27
|
+
end
|
|
28
|
+
hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join('&').to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'time'
|
|
5
|
+
|
|
6
|
+
module Phraseapp
|
|
7
|
+
module Rest
|
|
8
|
+
module Query
|
|
9
|
+
class Base
|
|
10
|
+
attr_accessor :id, :tags
|
|
11
|
+
attr_reader :unverified, :excluded, :updated_at
|
|
12
|
+
|
|
13
|
+
def initialize(id: nil, tags: nil, unverified: nil, excluded: nil, updated_at: nil)
|
|
14
|
+
@id = id
|
|
15
|
+
@tags = tags
|
|
16
|
+
self.unverified = unverified unless unverified.nil?
|
|
17
|
+
self.excluded = excluded unless excluded.nil?
|
|
18
|
+
self.updated_at = updated_at unless updated_at.nil?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def unverified=(bool)
|
|
22
|
+
@unverified = set bool
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def excluded=(bool)
|
|
26
|
+
@excluded = set bool
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def updated_at=(date_range)
|
|
30
|
+
# validates that date format is ISO8601
|
|
31
|
+
regex = /[<=>]+[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(Z|((\+|\-)[0-9]{2}:[0-9]{2}))+/
|
|
32
|
+
error_message = ArgumentError.new 'updated_at must be of format {>=|<=}2013-02-21T00:00:00Z'
|
|
33
|
+
raise error_message if date_range.nil? || date_range.match(regex).nil?
|
|
34
|
+
|
|
35
|
+
@updated_at = date_range
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def to_s
|
|
39
|
+
hash = {}
|
|
40
|
+
%w(id tags unverified excluded updated_at).each do |attr|
|
|
41
|
+
hash[attr.to_sym] = URI.encode_www_form_component(send(attr)) unless send(attr).nil?
|
|
42
|
+
end
|
|
43
|
+
'q=' + hash.to_a.map { |x| "#{x[0]}:#{x[1]}" }.join('%20').to_s unless hash.empty?
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def set(bool)
|
|
49
|
+
message = "#{caller(1..1).first} error '#{bool}' is not supported. Please use TRUE or FALSE"
|
|
50
|
+
raise message unless [true, false].include? bool
|
|
51
|
+
|
|
52
|
+
bool.to_s
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'parser'
|
|
4
|
+
require_relative 'list'
|
|
5
|
+
|
|
6
|
+
module Phraseapp
|
|
7
|
+
module Rest
|
|
8
|
+
module Resource
|
|
9
|
+
class Key
|
|
10
|
+
include Parser
|
|
11
|
+
include List
|
|
12
|
+
|
|
13
|
+
def initialize(client:, project_id:)
|
|
14
|
+
@client = client
|
|
15
|
+
@path = "/projects/#{project_id}/keys"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(id:)
|
|
19
|
+
parse(@client.get("#{@path}/#{id}"))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'time'
|
|
4
|
+
|
|
5
|
+
module Phraseapp
|
|
6
|
+
module Rest
|
|
7
|
+
module Resource
|
|
8
|
+
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?
|
|
12
|
+
items
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'parser'
|
|
4
|
+
require_relative 'list'
|
|
5
|
+
|
|
6
|
+
module Phraseapp
|
|
7
|
+
module Rest
|
|
8
|
+
module Resource
|
|
9
|
+
class Locale
|
|
10
|
+
include Parser
|
|
11
|
+
include List
|
|
12
|
+
|
|
13
|
+
def initialize(client:, project_id:)
|
|
14
|
+
@client = client
|
|
15
|
+
@path = "/projects/#{project_id}/locales"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(id:)
|
|
19
|
+
parse(@client.get("#{@path}/#{id}"))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module Phraseapp
|
|
6
|
+
module Rest
|
|
7
|
+
module Resource
|
|
8
|
+
module Parser
|
|
9
|
+
OPTIONS = { max_nesting: 4, symbolize_names: TRUE, object_class: OpenStruct }.freeze
|
|
10
|
+
|
|
11
|
+
def parse(json)
|
|
12
|
+
JSON.parse(json, OPTIONS)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'parser'
|
|
4
|
+
require_relative 'list'
|
|
5
|
+
|
|
6
|
+
module Phraseapp
|
|
7
|
+
module Rest
|
|
8
|
+
module Resource
|
|
9
|
+
class Project
|
|
10
|
+
include Parser
|
|
11
|
+
include List
|
|
12
|
+
|
|
13
|
+
def initialize(client:)
|
|
14
|
+
@client = client
|
|
15
|
+
@path = '/projects'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get(id:)
|
|
19
|
+
parse(@client.get("#{@path}/#{id}"))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'parser'
|
|
4
|
+
|
|
5
|
+
module Phraseapp
|
|
6
|
+
module Rest
|
|
7
|
+
module Resource
|
|
8
|
+
class Translation
|
|
9
|
+
include Parser
|
|
10
|
+
require_relative 'list'
|
|
11
|
+
|
|
12
|
+
def initialize(client:, project_id:)
|
|
13
|
+
@client = client
|
|
14
|
+
@path = "/projects/#{project_id}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get(id:)
|
|
18
|
+
parse(@client.get("#{@path}/translations/#{id}"))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def list
|
|
22
|
+
parse(@client.get("#{@path}/translations"))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def list_by_locale(locale_id: id, param: nil, query: nil)
|
|
26
|
+
path = "#{@path}/locales/#{locale_id}/translations"
|
|
27
|
+
path += querystring(param: param, query: query)
|
|
28
|
+
parse(@client.get(path))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def querystring(param: nil, query: nil)
|
|
34
|
+
str = [param.to_s, query.to_s].join('&')
|
|
35
|
+
"?#{str}" unless str.empty?
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'phraseapp-rest/version'
|
|
4
|
+
require_relative 'phraseapp-rest/factory'
|
|
5
|
+
require_relative 'phraseapp-rest/parameter/base'
|
|
6
|
+
require_relative 'phraseapp-rest/query/base'
|
|
7
|
+
require_relative 'phraseapp-rest/resource/key'
|
|
8
|
+
require_relative 'phraseapp-rest/resource/locale'
|
|
9
|
+
require_relative 'phraseapp-rest/resource/project'
|
|
10
|
+
require_relative 'phraseapp-rest/resource/translation'
|
metadata
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: phraseapp-rest
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sebastian Nepote
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-11-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A ruby gem to interact with Phraseapp REST resources
|
|
14
|
+
email: snepote@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/phraseapp-rest.rb
|
|
20
|
+
- lib/phraseapp-rest/api.rb
|
|
21
|
+
- lib/phraseapp-rest/factory.rb
|
|
22
|
+
- lib/phraseapp-rest/parameter/base.rb
|
|
23
|
+
- lib/phraseapp-rest/query/base.rb
|
|
24
|
+
- lib/phraseapp-rest/resource/key.rb
|
|
25
|
+
- lib/phraseapp-rest/resource/list.rb
|
|
26
|
+
- lib/phraseapp-rest/resource/locale.rb
|
|
27
|
+
- lib/phraseapp-rest/resource/parser.rb
|
|
28
|
+
- lib/phraseapp-rest/resource/project.rb
|
|
29
|
+
- lib/phraseapp-rest/resource/translation.rb
|
|
30
|
+
- lib/phraseapp-rest/version.rb
|
|
31
|
+
homepage: http://rubygems.org/gems/phraseapp-rest
|
|
32
|
+
licenses:
|
|
33
|
+
- MIT
|
|
34
|
+
metadata: {}
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubyforge_project:
|
|
51
|
+
rubygems_version: 2.7.7
|
|
52
|
+
signing_key:
|
|
53
|
+
specification_version: 4
|
|
54
|
+
summary: Phraseapp rest api resource collection
|
|
55
|
+
test_files: []
|