Skip to content

Commit 5f6985b

Browse files
committed
Fix translator
1 parent 57015d9 commit 5f6985b

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ gem 'sdoc', '~> 0.4.0', group: :doc
3333
# gem 'capistrano-rails', group: :development
3434

3535
gem 'json'
36+
gem 'gyoku'
37+
gem 'nori'
3638

3739
group :development, :test do
3840
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

Gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ GEM
5353
execjs (2.6.0)
5454
globalid (0.3.6)
5555
activesupport (>= 4.1.0)
56+
gyoku (1.3.1)
57+
builder (>= 2.1.2)
5658
i18n (0.7.0)
5759
jbuilder (2.3.1)
5860
activesupport (>= 3.0.0, < 5)
@@ -72,6 +74,7 @@ GEM
7274
multi_json (1.11.2)
7375
nokogiri (1.6.6.2)
7476
mini_portile (~> 0.6.0)
77+
nori (2.6.0)
7578
rack (1.6.4)
7679
rack-test (0.6.3)
7780
rack (>= 1.0)
@@ -141,9 +144,11 @@ PLATFORMS
141144
DEPENDENCIES
142145
byebug
143146
coffee-rails (~> 4.1.0)
147+
gyoku
144148
jbuilder (~> 2.0)
145149
jquery-rails
146150
json
151+
nori
147152
rails (= 4.2.4)
148153
sass-rails (~> 5.0)
149154
sdoc (~> 0.4.0)
+19-7
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,45 @@
11
class TranslatorController < ApplicationController
2+
3+
skip_before_filter :verify_authenticity_token
4+
25
require 'json'
36
require 'net/http'
47
require 'uri'
8+
require 'gyoku'
9+
require 'nori'
510

6-
def index
11+
def post
712
out_uri = URI.parse(get_destination)
813

914
out_http = Net::HTTP.new(out_uri.host, out_uri.port)
10-
out_request = Net::HTTP::Post.new(uri.request_uri)
1115

12-
out_request.body = get_hash.to_xml
16+
if params[:req_type] == 'get'
17+
out_request = Net::HTTP::Get.new(out_uri.request_uri)
18+
elsif params[:req_type] == 'post'
19+
out_request = Net::HTTP::Post.new(out_uri.request_uri)
20+
out_request.body = Gyoku.xml(get_hash).to_s
21+
end
1322

14-
request.headers.each do |key, value|
15-
out_request[key] = value
23+
unless request.headers[:authentication].blank?
24+
out_request[:authentication] = request.headers[:authentication]
1625
end
1726

1827
in_response = out_http.request(out_request)
1928

20-
render json: Hash.from_xml(in_response.body).to_json
29+
parser = Nori.new
30+
render json: parser.parse(in_response.body).to_json
2131
end
2232

2333
private
2434

2535
def get_destination
36+
Rails.logger.info { "destination: #{params[:destination]}" }
2637
params[:destination]
2738
end
2839

2940
def get_hash
30-
params.select { |key, value| key != :destination }
41+
Rails.logger.info { "site data: #{params[:site_data]}" }
42+
params[:site_data]
3143
end
3244

3345
end

config/routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Rails.application.routes.draw do
2-
post '/' => 'translator#index'
2+
post '/' => 'translator#post'
33

44
# The priority is based upon order of creation: first created -> highest priority.
55
# See how all your routes lay out with "rake routes".

0 commit comments

Comments
 (0)