tr8n_core 4.2 → 4.3
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 +4 -4
- data/lib/tr8n/api/client.rb +23 -2
- data/lib/tr8n/application.rb +1 -0
- data/lib/tr8n/session.rb +26 -16
- data/lib/tr8n/utils.rb +22 -21
- data/lib/tr8n_core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4677e94f7e97da4ce77e060fe72c2bef2db5ca94
|
4
|
+
data.tar.gz: 3f05a3e92037e05497c4c005e48ff2ccdbf348a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aaa9a7bc5eb6000bc0b43314bad5e8352f7a484ac3eb83e0038de4b5503ff1e0849a17ea3b6bf47ce1b554ed3d8614e28f35a039049aab981d4fd6112e278eb
|
7
|
+
data.tar.gz: 7d3580bbc2b8acd859dce089ae21a4d0a6a7a93bf23ffea275564443733442f8243adac54d2ba1669a6209696741cadb5c8290e9bfefdb500c70025da00f3f9d
|
data/lib/tr8n/api/client.rb
CHANGED
@@ -39,16 +39,19 @@ class Tr8n::Api::Client < Tr8n::Base
|
|
39
39
|
attributes :application
|
40
40
|
|
41
41
|
def access_token
|
42
|
+
return Tr8n::Session.access_token if Tr8n::Session.access_token
|
43
|
+
|
42
44
|
application.access_token ||= begin
|
43
|
-
Tr8n.cache.fetch("#{application.key}/access_token") do
|
45
|
+
token = Tr8n.cache.fetch("#{application.key}/access_token") do
|
44
46
|
api('oauth/token', {
|
45
47
|
:client_id => application.key,
|
46
48
|
:client_secret => application.secret,
|
47
49
|
:grant_type => :client_credentials
|
48
50
|
}, {:method => :post})
|
49
51
|
end
|
52
|
+
Tr8n::Session.access_token = token['access_token']
|
53
|
+
Tr8n::Session.access_token
|
50
54
|
end
|
51
|
-
application.access_token['access_token']
|
52
55
|
end
|
53
56
|
|
54
57
|
def results(path, params = {}, opts = {})
|
@@ -63,6 +66,14 @@ class Tr8n::Api::Client < Tr8n::Base
|
|
63
66
|
api(path, params, opts.merge(:method => :post))
|
64
67
|
end
|
65
68
|
|
69
|
+
def put(path, params = {}, opts = {})
|
70
|
+
api(path, params, opts.merge(:method => :put))
|
71
|
+
end
|
72
|
+
|
73
|
+
def delete(path, params = {}, opts = {})
|
74
|
+
api(path, params, opts.merge(:method => :delete))
|
75
|
+
end
|
76
|
+
|
66
77
|
def self.error?(data)
|
67
78
|
not data['error'].nil?
|
68
79
|
end
|
@@ -128,10 +139,18 @@ class Tr8n::Api::Client < Tr8n::Base
|
|
128
139
|
path = prepare_api_path(path)
|
129
140
|
params = params.merge(:access_token => access_token) unless path.index('oauth')
|
130
141
|
|
142
|
+
if opts[:method] == :post
|
143
|
+
params = params.merge(:api_key => application.key)
|
144
|
+
end
|
145
|
+
|
131
146
|
Tr8n.logger.trace_api_call(path, params, opts) do
|
132
147
|
begin
|
133
148
|
if opts[:method] == :post
|
134
149
|
response = connection.post(path, params)
|
150
|
+
elsif opts[:method] == :put
|
151
|
+
response = connection.put(path, params)
|
152
|
+
elsif opts[:method] == :delete
|
153
|
+
response = connection.delete(path, params)
|
135
154
|
else
|
136
155
|
response = connection.get(path, params)
|
137
156
|
end
|
@@ -147,6 +166,8 @@ class Tr8n::Api::Client < Tr8n::Base
|
|
147
166
|
raise Tr8n::Exception.new("Error: #{response.body}")
|
148
167
|
end
|
149
168
|
|
169
|
+
return if response.body.nil? or response.body == ''
|
170
|
+
|
150
171
|
begin
|
151
172
|
data = JSON.parse(response.body)
|
152
173
|
rescue Exception => ex
|
data/lib/tr8n/application.rb
CHANGED
@@ -47,6 +47,7 @@ class Tr8n::Application < Tr8n::Base
|
|
47
47
|
def fetch
|
48
48
|
update_attributes(api_client.get('applications/current', {:definition => true}, {:cache_key => self.class.cache_key}))
|
49
49
|
rescue Tr8n::Exception => ex
|
50
|
+
pp ex, ex.backtrace
|
50
51
|
Tr8n.logger.error("Failed to load application: #{ex}")
|
51
52
|
self
|
52
53
|
end
|
data/lib/tr8n/session.rb
CHANGED
@@ -39,7 +39,7 @@ module Tr8n
|
|
39
39
|
class Session
|
40
40
|
# Session Attributes - Move to Session
|
41
41
|
attr_accessor :application, :current_user, :current_locale, :current_language, :current_translator,
|
42
|
-
:current_source, :current_component, :block_options, :cookie_params, :access_token
|
42
|
+
:current_source, :current_component, :block_options, :cookie_params, :access_token, :tools_enabled
|
43
43
|
|
44
44
|
def self.access_token
|
45
45
|
@access_token
|
@@ -56,8 +56,25 @@ module Tr8n
|
|
56
56
|
secret = opts[:secret] || Tr8n.config.application[:secret]
|
57
57
|
host = opts[:host] || Tr8n.config.application[:host]
|
58
58
|
|
59
|
+
Tr8n::Session.access_token ||= begin
|
60
|
+
self.access_token = opts[:token] || Tr8n.config.application[:token]
|
61
|
+
self.access_token ||= opts[:access_token] || Tr8n.config.application[:access_token]
|
62
|
+
end
|
63
|
+
|
64
|
+
Tr8n.cache.reset_version
|
65
|
+
|
66
|
+
self.application = Tr8n.memory.fetch(Tr8n::Application.cache_key) do
|
67
|
+
Tr8n::Application.new(:host => host, :key => key, :secret => secret, :access_token => Tr8n::Session.access_token).fetch
|
68
|
+
end
|
69
|
+
|
70
|
+
if Tr8n.cache.read_only?
|
71
|
+
self.class.access_token = self.application.access_token
|
72
|
+
end
|
73
|
+
|
74
|
+
# Tr8n.logger.info(self.cookie_params.inspect)
|
75
|
+
|
59
76
|
self.cookie_params = begin
|
60
|
-
cookie_name = "tr8n_#{key}"
|
77
|
+
cookie_name = "tr8n_#{self.application.key}"
|
61
78
|
if opts[:cookies] and opts[:cookies][cookie_name]
|
62
79
|
begin
|
63
80
|
HashWithIndifferentAccess.new(Tr8n::Utils.decode_and_verify_params(opts[:cookies][cookie_name], secret))
|
@@ -70,28 +87,16 @@ module Tr8n
|
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
73
|
-
|
74
|
-
|
75
|
-
self.access_token = opts[:access_token]
|
90
|
+
self.tools_enabled = opts[:tools_enabled]
|
76
91
|
self.current_user = opts[:user]
|
77
92
|
self.current_source = opts[:source] || '/tr8n/core'
|
78
93
|
self.current_component = opts[:component]
|
79
|
-
self.current_locale =
|
94
|
+
self.current_locale = opts[:locale] || self.cookie_params[:locale] || Tr8n.config.default_locale
|
80
95
|
|
81
96
|
if self.cookie_params['translator']
|
82
97
|
self.current_translator = Tr8n::Translator.new(self.cookie_params['translator'])
|
83
98
|
end
|
84
99
|
|
85
|
-
Tr8n.cache.reset_version
|
86
|
-
|
87
|
-
self.application = Tr8n.memory.fetch(Tr8n::Application.cache_key) do
|
88
|
-
Tr8n::Application.new(:host => host, :key => key, :secret => secret, :access_token => self.class.access_token).fetch
|
89
|
-
end
|
90
|
-
|
91
|
-
if Tr8n.cache.read_only?
|
92
|
-
self.class.access_token = self.application.access_token
|
93
|
-
end
|
94
|
-
|
95
100
|
if self.current_translator
|
96
101
|
self.current_translator.application = self.application
|
97
102
|
end
|
@@ -99,6 +104,10 @@ module Tr8n
|
|
99
104
|
self.current_language = self.application.language(self.current_locale)
|
100
105
|
end
|
101
106
|
|
107
|
+
def tools_enabled?
|
108
|
+
self.tools_enabled
|
109
|
+
end
|
110
|
+
|
102
111
|
def reset
|
103
112
|
self.application= nil
|
104
113
|
self.current_user= nil
|
@@ -106,6 +115,7 @@ module Tr8n
|
|
106
115
|
self.current_translator= nil
|
107
116
|
self.current_source= nil
|
108
117
|
self.current_component= nil
|
118
|
+
self.tools_enabled= nil
|
109
119
|
self.block_options= nil
|
110
120
|
end
|
111
121
|
|
data/lib/tr8n/utils.rb
CHANGED
@@ -92,31 +92,32 @@ module Tr8n
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def self.sign_and_encode_params(params, secret)
|
95
|
-
|
96
|
-
payload = Base64.encode64(payload)
|
95
|
+
URI::encode(Base64.encode64(params.to_json))
|
97
96
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
97
|
+
#payload = params.merge(:algorithm => 'HMAC-SHA256', :ts => Time.now.to_i).to_json
|
98
|
+
#payload = Base64.encode64(payload)
|
99
|
+
#sig = OpenSSL::HMAC.digest('sha256', secret, payload)
|
100
|
+
#encoded_sig = Base64.encode64(sig)
|
101
|
+
#URI::encode(Base64.encode64("#{encoded_sig}.#{payload}"))
|
102
102
|
end
|
103
103
|
|
104
104
|
def self.decode_and_verify_params(signed_request, secret)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
encoded_sig = parts.first
|
112
|
-
payload = parts.last
|
113
|
-
expected_sig = OpenSSL::HMAC.digest('sha256', secret, payload)
|
114
|
-
expected_sig = Base64.encode64(expected_sig)
|
115
|
-
if expected_sig != encoded_sig
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
|
105
|
+
payload = URI::decode(signed_request)
|
106
|
+
payload = Base64.decode64(payload)
|
107
|
+
JSON.parse(payload)
|
108
|
+
|
109
|
+
#parts = signed_request.split('.')
|
110
|
+
#return JSON.parse(Base64.decode64(parts.first)) if parts.size == 1
|
111
|
+
#encoded_sig = parts.first
|
112
|
+
#payload = parts.last
|
113
|
+
#expected_sig = OpenSSL::HMAC.digest('sha256', secret, payload)
|
114
|
+
#expected_sig = Base64.encode64(expected_sig)
|
115
|
+
#if expected_sig != encoded_sig
|
116
|
+
# raise Tr8n::Exception.new('Bad signature')
|
117
|
+
#end
|
118
|
+
#JSON.parse(Base64.decode64(payload))
|
119
|
+
rescue Exception => ex
|
120
|
+
{}
|
120
121
|
end
|
121
122
|
|
122
123
|
def self.split_sentences(paragraph)
|
data/lib/tr8n_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '4.
|
4
|
+
version: '4.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|