whiplash-app 0.9.6 → 0.10.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 +4 -4
- data/lib/whiplash/app/canonical_host.rb +3 -2
- data/lib/whiplash/app/controller_helpers.rb +45 -7
- data/lib/whiplash/app/railtie.rb +1 -1
- data/lib/whiplash/app/version.rb +1 -1
- data/lib/whiplash/app.rb +14 -1
- data/whiplash-app.gemspec +2 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1bf73813a5c4e7bdc0417901e1734afb3dade5b3fbd9e1dc3c8b31b0b0bdcc3
|
4
|
+
data.tar.gz: 7ec1abc0b3adaf3f68d1f43f2c19f42bf700277b0c368e383c42cddedc80e1a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7b75b10c21856dd22bf2c1d2652ac875f5283d483f56d5123f9b86f93d71bfe76081b3a96cfb4bd5108fddad6f35ce89585128295fafc671ed62913060790c5
|
7
|
+
data.tar.gz: 7950a5979e5e3fbee7f91785507a22dbc5d506c83bcea2acb10ac22708abe13ba55b2fee353c298187df66457fb020bcab812896b81529006f61f8fda24e720a
|
@@ -9,7 +9,8 @@ module Whiplash
|
|
9
9
|
def require_canonical_host!
|
10
10
|
canonical_host = ENV.fetch('CANONICAL_HOST', false).in?([true, 'true', 1, '1'])
|
11
11
|
return unless canonical_host
|
12
|
-
|
12
|
+
return unless Rails.configuration.respond_to?(:application_url)
|
13
|
+
application_host = URI.parse(Rails.configuration.application_url).host
|
13
14
|
return if application_host == request.host
|
14
15
|
return unless request.method_symbol == :get # can't redirect PUT, POST, DELETE
|
15
16
|
|
@@ -17,7 +18,7 @@ module Whiplash
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def redirect_to_canonical_host(query_params, status=301)
|
20
|
-
redirect_to "#{Rails.configuration.
|
21
|
+
redirect_to "#{Rails.configuration.application_url}#{request.path}#{'?' if query_params.to_query.present?}#{query_params.to_query}", status: status
|
21
22
|
end
|
22
23
|
|
23
24
|
end
|
@@ -15,16 +15,49 @@ module Whiplash
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
+
def application_domain
|
19
|
+
return nil if Rails.configuration.application_url.blank?
|
20
|
+
host = URI.parse(Rails.configuration.application_url).host
|
21
|
+
'.' + host
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear_application_cookies!
|
25
|
+
return if application_domain.blank?
|
26
|
+
cookie_keys_we_care_about.each { |k| cookies.delete(k, domain: application_domain) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def clear_domain_cookies!
|
30
|
+
cookie_keys_we_care_about.each { |k| cookies.delete(k, domain: cookie_domain) }
|
31
|
+
end
|
32
|
+
|
18
33
|
def cookie_domain
|
19
|
-
|
34
|
+
host = URI.parse(core_url).host
|
35
|
+
host.gsub!('www.', '')
|
36
|
+
'.' + host
|
37
|
+
end
|
38
|
+
|
39
|
+
def cookie_keys_we_care_about
|
40
|
+
%i(
|
41
|
+
_session
|
42
|
+
customer
|
43
|
+
customer_id
|
44
|
+
oauth_token
|
45
|
+
partner_id
|
46
|
+
user
|
47
|
+
user_id
|
48
|
+
warehouse
|
49
|
+
warehouse_id
|
50
|
+
)
|
20
51
|
end
|
21
52
|
|
22
53
|
def core_url
|
23
|
-
ENV['WHIPLASH_API_URL']
|
54
|
+
ENV['WHIPLASH_CORE_URL'] || ENV['WHIPLASH_API_URL']
|
24
55
|
end
|
25
56
|
|
26
|
-
def core_url_for(path)
|
27
|
-
[core_url, path].join('/')
|
57
|
+
def core_url_for(path, query_params = {})
|
58
|
+
out = [core_url, path].join('/')
|
59
|
+
out = [out, query_params.to_query].join('?') if query_params.present?
|
60
|
+
return out
|
28
61
|
end
|
29
62
|
|
30
63
|
def current_customer
|
@@ -86,7 +119,10 @@ module Whiplash
|
|
86
119
|
end
|
87
120
|
|
88
121
|
def init_whiplash_api(options = {})
|
89
|
-
|
122
|
+
if cookies[:oauth_token].blank?
|
123
|
+
clear_application_cookies!
|
124
|
+
return redirect_to core_url_for('login', redirect_url: request.original_url)
|
125
|
+
end
|
90
126
|
token = {access_token: cookies[:oauth_token]}
|
91
127
|
begin
|
92
128
|
@whiplash_api = Whiplash::App.new(token, options)
|
@@ -97,7 +133,9 @@ module Whiplash
|
|
97
133
|
end
|
98
134
|
|
99
135
|
def require_user
|
100
|
-
|
136
|
+
return if current_user.present?
|
137
|
+
clear_application_cookies!
|
138
|
+
redirect_to core_url_for('login', redirect_url: request.original_url)
|
101
139
|
end
|
102
140
|
|
103
141
|
def set_locale!
|
@@ -139,7 +177,7 @@ module Whiplash
|
|
139
177
|
def set_current_warehouse_cookie!(warehouse_id, expires_at = nil)
|
140
178
|
warehouse = @whiplash_api.get!("warehouses/#{warehouse_id}").body
|
141
179
|
user = @whiplash_api.get!("me").body
|
142
|
-
fields_we_care_about = %w(id name)
|
180
|
+
fields_we_care_about = %w(id name slug)
|
143
181
|
warehouse_hash = warehouse.slice(*fields_we_care_about)
|
144
182
|
expires_at ||= user['current_sign_in_expires_at']
|
145
183
|
|
data/lib/whiplash/app/railtie.rb
CHANGED
@@ -20,7 +20,7 @@ module Whiplash
|
|
20
20
|
end
|
21
21
|
|
22
22
|
initializer "whiplash_app.action_controller" do
|
23
|
-
ActiveSupport.on_load(:
|
23
|
+
ActiveSupport.on_load(:action_controller_base) do
|
24
24
|
include Whiplash::App::CanonicalHost
|
25
25
|
include Whiplash::App::ControllerHelpers
|
26
26
|
end
|
data/lib/whiplash/app/version.rb
CHANGED
data/lib/whiplash/app.rb
CHANGED
@@ -6,6 +6,7 @@ require "whiplash/app/version"
|
|
6
6
|
require "errors/whiplash_api_error"
|
7
7
|
require "oauth2"
|
8
8
|
require "faraday"
|
9
|
+
require 'faraday/net_http_persistent'
|
9
10
|
|
10
11
|
# Rails app stuff
|
11
12
|
if defined?(Rails::Railtie)
|
@@ -40,9 +41,21 @@ module Whiplash
|
|
40
41
|
|
41
42
|
def connection
|
42
43
|
Faraday.new [self.class.api_url, versioned_api_url].join("/") do |conn|
|
44
|
+
# Authentication
|
43
45
|
conn.request :authorization, 'Bearer', token.token
|
44
46
|
conn.request :json
|
45
47
|
conn.response :json, :content_type => /\bjson$/
|
48
|
+
conn.options.timeout = 30 # Total request timeout
|
49
|
+
conn.options.open_timeout = 5 # Connection establishment timeout
|
50
|
+
|
51
|
+
# Use persistent HTTP connections (requires net-http-persistent gem)
|
52
|
+
begin
|
53
|
+
conn.adapter :net_http_persistent
|
54
|
+
rescue LoadError
|
55
|
+
# Fallback to default adapter if net-http-persistent isn't available
|
56
|
+
Rails.logger.warn "[WhiplashApp] net-http-persistent gem not found, using default adapter" if defined?(Rails)
|
57
|
+
conn.adapter Faraday.default_adapter
|
58
|
+
end
|
46
59
|
end
|
47
60
|
end
|
48
61
|
|
@@ -112,4 +125,4 @@ module Net
|
|
112
125
|
|
113
126
|
end
|
114
127
|
end
|
115
|
-
end
|
128
|
+
end
|
data/whiplash-app.gemspec
CHANGED
@@ -20,9 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "oauth2", "~> 2.0.4"
|
22
22
|
spec.add_dependency "faraday", "~> 2.7"
|
23
|
+
spec.add_dependency 'faraday-net_http_persistent'
|
23
24
|
|
24
25
|
spec.add_development_dependency "bundler", ">= 2.2"
|
25
26
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
26
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
-
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiplash-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Sullivan, Mark Dickson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday-net_http_persistent
|
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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +100,14 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
103
|
+
version: '0.14'
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
110
|
+
version: '0.14'
|
97
111
|
description: this gem provides connectivity to the Whiplash API for authentication
|
98
112
|
and REST requests.
|
99
113
|
email:
|
@@ -141,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
155
|
- !ruby/object:Gem::Version
|
142
156
|
version: '0'
|
143
157
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
158
|
+
rubygems_version: 3.1.6
|
145
159
|
signing_key:
|
146
160
|
specification_version: 4
|
147
161
|
summary: this gem provides connectivity to the Whiplash API for authentication and
|