radiant-ecom_engine-extension 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +22 -0
- data/Rakefile +12 -0
- data/app/controllers/page_mount_controller.rb +145 -0
- data/app/views/page_mount/proxy.erb +1 -0
- data/config/routes.rb +34 -0
- data/ecom_engine_extension.rb +13 -0
- data/lib/request_proxy.rb +90 -0
- data/radiant-ecom_engine-extension.gemspec +22 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b5d6b3ccfe4e8428598d53e395671f44359c860
|
4
|
+
data.tar.gz: 6967da35de9dd8f06c87ac2922262c52bb18ff67
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b02af186730b9a8bceb76f48a3aa907128d151563d5c006f2ca65da0915c909102ae21829a0075ffcb0548b4e9676ec757871178c1536cb4316e3e21a9d52316
|
7
|
+
data.tar.gz: 393fbe44cf84fe4a8a5c6fc80f7d53a754d91d51a3d69f18fb2b18461c57ca5f73c53484a648163a09429511ce35fb960d5270021ce11264ee5a4886d22f4a90
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
+# Change Log
|
2
|
+
+All notable changes to this project will be documented in this file.
|
3
|
+
+This project adheres to [Semantic Versioning](http://semver.org/).
|
4
|
+
+This changelog adheres to [Keep a
|
5
|
+
CHANGELOG](http://keepachangelog.com/).
|
6
|
+
|
7
|
+
## Unreleased
|
8
|
+
|
9
|
+
## 0.2.0
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
- [TT-1567] Hack for exclusive products fixed by storing additional details
|
13
|
+
(Requires CMS to use ajax login)
|
14
|
+
- [TT-1583] Rename to radiant-ecom_engine-extension
|
15
|
+
(requires ecom-engine)
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
- [TT-938] Remove deprecated secure-pay url
|
19
|
+
|
20
|
+
### Updated
|
21
|
+
- [TT-1377] Maintain the files original status code when proxying
|
22
|
+
- [TT-1340] Proxy more content-types as file
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Default: run specs.'
|
4
|
+
task :default => :spec
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
desc "Run specs"
|
9
|
+
RSpec::Core::RakeTask.new do |t|
|
10
|
+
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
11
|
+
# Put spec opts in a file named .rspec in root
|
12
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
class PageMountController < SiteController
|
2
|
+
no_login_required
|
3
|
+
|
4
|
+
radiant_layout { |controller| controller.domains_layout }
|
5
|
+
|
6
|
+
before_filter :set_monitoring_meta_data, only: :proxy
|
7
|
+
|
8
|
+
# Example:
|
9
|
+
# /accommodation/kangaroo-island/ozone-12?adults=1
|
10
|
+
#
|
11
|
+
# params[:paths] => ["kangaroo-island", "ozone-12"]
|
12
|
+
# params[:adults] => 1
|
13
|
+
def proxy
|
14
|
+
response = http_proxy(ecom_engine_url + request.path)
|
15
|
+
|
16
|
+
# TODO: Resolve so that response doesn't return blank for cookies on 500?
|
17
|
+
# ... or determine if having blank cookies means "don't set anything buddy"
|
18
|
+
session[:proxied_cookies] = response.cookies unless response.cookies.blank?
|
19
|
+
|
20
|
+
# Must be done before redirect (for logout)
|
21
|
+
store_client_type_id_in_cms_session(response, request)
|
22
|
+
|
23
|
+
if response.redirect?
|
24
|
+
redirect_to response.redirect_location
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
unless response.ok?
|
29
|
+
Rails.logger.error("Ecom-engine proxy failed. Response [#{response.code}] =>")
|
30
|
+
Rails.logger.error(response.body)
|
31
|
+
# TODO: Contact errbit? Can we improve this fail page...?
|
32
|
+
#
|
33
|
+
# This is rendered in ecom-engine: 'shared/quicktravel_unavailable'
|
34
|
+
# Probably, it should be here!
|
35
|
+
end
|
36
|
+
|
37
|
+
proxy_response = ProxyResponse.new(response)
|
38
|
+
if proxy_response.file?
|
39
|
+
send_file(proxy_response)
|
40
|
+
else
|
41
|
+
@title = proxy_response.headers[:x_title]
|
42
|
+
render text: proxy_response.body,
|
43
|
+
content_type: proxy_response.content_type,
|
44
|
+
status: proxy_response.code,
|
45
|
+
layout: (request.path != '/app_cells')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def domains_layout
|
50
|
+
calculator.domains_layout
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def store_client_type_id_in_cms_session(response, request)
|
56
|
+
# Special Hack so CC can show exclusive products for clients
|
57
|
+
case request.path
|
58
|
+
when '/parties/login.json'
|
59
|
+
json = JSON.parse(response.body)
|
60
|
+
session[:client_id] = json['client_id']
|
61
|
+
session[:client_type_id] = json['client_type_id']
|
62
|
+
session[:client_type_is_agent] = json['client_type_is_agent']
|
63
|
+
when '/parties/logout'
|
64
|
+
session[:client_id] = nil
|
65
|
+
session[:client_type_id] = nil
|
66
|
+
session[:client_type_is_agent] = nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def http_proxy(url)
|
71
|
+
RequestProxy.call(request, url, params, session[:proxied_cookies])
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_monitoring_meta_data
|
75
|
+
return unless defined?(NewRelic)
|
76
|
+
controller, action = extract_controller_action(request, params)
|
77
|
+
NewRelic::Agent.set_transaction_name("page_mount:#{controller}/#{action}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def extract_controller_action(request, params)
|
81
|
+
if request.path == '/cells'
|
82
|
+
params[:name].split('/', 2)
|
83
|
+
else
|
84
|
+
*parts, action = request.path[1..-1].split('/')
|
85
|
+
[parts.join('/'), action]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class_attribute :calculator
|
90
|
+
|
91
|
+
def calculator
|
92
|
+
@calculator ||= Radiant::Config['ecomengine.calculator'].constantize.new(request)
|
93
|
+
end
|
94
|
+
|
95
|
+
def ecom_engine_url
|
96
|
+
calculator.ecom_engine_url
|
97
|
+
end
|
98
|
+
|
99
|
+
# TODO: Check if we can delete this...
|
100
|
+
def protect_against_forgery?
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
def send_file(proxy_response)
|
105
|
+
send_data proxy_response.body,
|
106
|
+
status: proxy_response.code,
|
107
|
+
type: proxy_response.content_type,
|
108
|
+
disposition: proxy_response.content_disposition
|
109
|
+
end
|
110
|
+
|
111
|
+
class ProxyResponse
|
112
|
+
DEFAULT_CONTENT_DISPOSITION = 'inline'
|
113
|
+
|
114
|
+
attr_reader :response
|
115
|
+
|
116
|
+
def initialize(response)
|
117
|
+
@response = response
|
118
|
+
end
|
119
|
+
|
120
|
+
FILE_CONTENT_TYPES = %w(
|
121
|
+
application/octet-stream
|
122
|
+
application/javascript
|
123
|
+
text/plain # js.map
|
124
|
+
application/json
|
125
|
+
)
|
126
|
+
|
127
|
+
def file?
|
128
|
+
headers.key?(:content_disposition) || FILE_CONTENT_TYPES.include?(content_type)
|
129
|
+
end
|
130
|
+
|
131
|
+
def content_type
|
132
|
+
headers[:content_type].split(';').first
|
133
|
+
end
|
134
|
+
|
135
|
+
def content_disposition
|
136
|
+
headers[:content_disposition] || DEFAULT_CONTENT_DISPOSITION
|
137
|
+
end
|
138
|
+
|
139
|
+
delegate :body, :code, to: :response
|
140
|
+
|
141
|
+
def headers
|
142
|
+
@response.body.headers
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= raw @proxied_html %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
2
|
+
# Page-mounted App
|
3
|
+
map.with_options controller: 'page_mount', action: 'proxy' do |page_mount|
|
4
|
+
page_mount.connect 'search/accommodations'
|
5
|
+
|
6
|
+
# These are CMS pages:
|
7
|
+
# /accommodation/hotel-motel (for each type)
|
8
|
+
# /accommodation/kangaroo-island-accommodation/ (for landing page)
|
9
|
+
#
|
10
|
+
page_mount.connect ':region_name/:accommodation_id',
|
11
|
+
requirements: {
|
12
|
+
region_name: /[a-z-]*-accommodation/,
|
13
|
+
accommodation_id: /\d+.*/
|
14
|
+
}
|
15
|
+
|
16
|
+
page_mount.connect 'transport/*paths'
|
17
|
+
page_mount.connect 'tours/*paths'
|
18
|
+
|
19
|
+
page_mount.connect 'app_cells/*paths'
|
20
|
+
|
21
|
+
page_mount.connect 'cart/*paths'
|
22
|
+
|
23
|
+
page_mount.connect 'secure-payment'
|
24
|
+
page_mount.connect 'cart_activations/*paths'
|
25
|
+
page_mount.connect 'bookings/manage/*paths'
|
26
|
+
|
27
|
+
page_mount.connect 'parties/*paths'
|
28
|
+
page_mount.connect 'reset_password/*paths'
|
29
|
+
page_mount.connect 'documents/*paths'
|
30
|
+
|
31
|
+
page_mount.connect 'ecom-engine-js/*paths'
|
32
|
+
page_mount.connect 'media/*paths'
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
# require_dependency 'application_controller'
|
3
|
+
class EcomEngineExtension < Radiant::Extension
|
4
|
+
version "1.0"
|
5
|
+
description "This extension is communicating with Ecom Engine"
|
6
|
+
url 'https://github.com/sealink/radiant-ecom_engine-extension'
|
7
|
+
|
8
|
+
def activate
|
9
|
+
end
|
10
|
+
|
11
|
+
def deactivate
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class RequestProxy
|
4
|
+
def self.call(request, url, data, cookies)
|
5
|
+
proxy = new(request, url, data, cookies)
|
6
|
+
proxy.call
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(request, url, data, cookies)
|
10
|
+
@method = request.method
|
11
|
+
@url = url
|
12
|
+
@data = data
|
13
|
+
@cookies = cookies
|
14
|
+
@headers = request.headers
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
options = {
|
19
|
+
method: @method,
|
20
|
+
url: url,
|
21
|
+
cookies: @cookies,
|
22
|
+
headers: headers_for_booking_app,
|
23
|
+
}
|
24
|
+
options[:payload] = @data unless http_get?
|
25
|
+
|
26
|
+
RestClient::Request.execute(options) do |response, _request, _result, &_block|
|
27
|
+
WrappedResponse.new(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def http_get?
|
34
|
+
@method == :get
|
35
|
+
end
|
36
|
+
|
37
|
+
def url
|
38
|
+
url = @url
|
39
|
+
url += "?#{@data.to_query}" if http_get?
|
40
|
+
url
|
41
|
+
end
|
42
|
+
|
43
|
+
def headers_for_booking_app
|
44
|
+
{
|
45
|
+
accept: @headers['Accept'],
|
46
|
+
referer: @headers['HTTP_REFERER'],
|
47
|
+
'X-CSRF-Token' => @headers['X-CSRF-Token']
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
class WrappedResponse
|
52
|
+
def initialize(response)
|
53
|
+
@response = response
|
54
|
+
end
|
55
|
+
|
56
|
+
def redirect_location
|
57
|
+
location_uri = URI.parse(@response.headers[:location])
|
58
|
+
|
59
|
+
location = location_uri.path
|
60
|
+
location += '?' + location_uri.query if location_uri.query.present?
|
61
|
+
location += '#' + location_uri.fragment if location_uri.fragment.present?
|
62
|
+
location
|
63
|
+
end
|
64
|
+
|
65
|
+
def code
|
66
|
+
@response.code
|
67
|
+
end
|
68
|
+
|
69
|
+
def body
|
70
|
+
@response.body
|
71
|
+
end
|
72
|
+
|
73
|
+
def cookies
|
74
|
+
@response.cookies
|
75
|
+
end
|
76
|
+
|
77
|
+
def content_type
|
78
|
+
@response.headers[:content_type]
|
79
|
+
end
|
80
|
+
|
81
|
+
def ok?
|
82
|
+
(200..207).include? @response.code
|
83
|
+
end
|
84
|
+
|
85
|
+
def redirect?
|
86
|
+
(300..399).include? @response.code
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "radiant-ecom_engine-extension"
|
3
|
+
spec.version = '0.2.0'
|
4
|
+
spec.authors = ["Michael Noack"]
|
5
|
+
spec.email = ["support@travellink.com.au"]
|
6
|
+
spec.description = %q{Integrate ecom engine with radiant}
|
7
|
+
spec.summary = %q{Integrate ecom engine with radiant}
|
8
|
+
spec.homepage = 'http://github.com/sealink/radiant-ecom_engine-extension'
|
9
|
+
|
10
|
+
spec.license = "MIT"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_dependency 'radius'
|
18
|
+
spec.add_dependency 'rest-client', '1.7.2' # what kis-cms uses, 1.8 is last ruby 1.9 compatible but breaks cookies, 2.0 requires ruby 2.0
|
19
|
+
spec.add_dependency 'radiant-layouts-extension' # radiant_layout
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-ecom_engine-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Noack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: radius
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.7.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: radiant-layouts-extension
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
description: Integrate ecom engine with radiant
|
70
|
+
email:
|
71
|
+
- support@travellink.com.au
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.md
|
77
|
+
- Rakefile
|
78
|
+
- app/controllers/page_mount_controller.rb
|
79
|
+
- app/views/page_mount/proxy.erb
|
80
|
+
- config/routes.rb
|
81
|
+
- ecom_engine_extension.rb
|
82
|
+
- lib/request_proxy.rb
|
83
|
+
- radiant-ecom_engine-extension.gemspec
|
84
|
+
homepage: http://github.com/sealink/radiant-ecom_engine-extension
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.8
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Integrate ecom engine with radiant
|
108
|
+
test_files: []
|