whiplash-app 0.9.6 → 0.10.2
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/.github/workflows/ci.yml +1 -1
- 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 +33 -2
- data/whiplash-app.gemspec +3 -1
- metadata +36 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: adc068051a8e2ecbb9ae56496bda52be1e358e668189b9cfe27ccda7d9712229
|
|
4
|
+
data.tar.gz: 9de47bfcf86b123b1b02fce2c629352cc19eacc77658b870da838f3babb9afe5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 593790e085faa0b104658e23204c3ced561c5a497cadab695e737b3eff7e194e8d5a636c3f4d0048b8ba15e2ff41a3d0d88b8671216a7ffabcc3bc522006af83
|
|
7
|
+
data.tar.gz: 9b9852b80909ce8d8a561f5167472792e0f25e9bb3c7a7b7d7e583a6a3f50b7670acd0087943a6dc03b9eb908d0fa2bfbfd4a27f323aa4349574911dc57a8599
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -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['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,8 @@ require "whiplash/app/version"
|
|
|
6
6
|
require "errors/whiplash_api_error"
|
|
7
7
|
require "oauth2"
|
|
8
8
|
require "faraday"
|
|
9
|
+
require "faraday/retry"
|
|
10
|
+
require 'faraday/net_http_persistent'
|
|
9
11
|
|
|
10
12
|
# Rails app stuff
|
|
11
13
|
if defined?(Rails::Railtie)
|
|
@@ -21,13 +23,14 @@ module Whiplash
|
|
|
21
23
|
include Whiplash::App::Connections
|
|
22
24
|
include Whiplash::App::FinderMethods
|
|
23
25
|
|
|
24
|
-
attr_accessor :customer_id, :shop_id, :token
|
|
26
|
+
attr_accessor :customer_id, :shop_id, :token, :retry_errors
|
|
25
27
|
|
|
26
28
|
def initialize(token, options={})
|
|
27
29
|
@token = format_token(token)
|
|
28
30
|
@customer_id = options[:customer_id]
|
|
29
31
|
@shop_id = options[:shop_id]
|
|
30
32
|
@api_version = options[:api_version] || 2 # can be 2_1
|
|
33
|
+
@retry_errors = options.fetch(:retry_errors, false)
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
def versioned_api_url
|
|
@@ -40,9 +43,37 @@ module Whiplash
|
|
|
40
43
|
|
|
41
44
|
def connection
|
|
42
45
|
Faraday.new [self.class.api_url, versioned_api_url].join("/") do |conn|
|
|
46
|
+
# Authentication
|
|
43
47
|
conn.request :authorization, 'Bearer', token.token
|
|
44
48
|
conn.request :json
|
|
49
|
+
|
|
50
|
+
if @retry_errors
|
|
51
|
+
conn.request :retry, max: 5,
|
|
52
|
+
interval: 1,
|
|
53
|
+
interval_randomness: 0.5,
|
|
54
|
+
backoff_factor: 2,
|
|
55
|
+
methods: [:get, :post, :put, :delete],
|
|
56
|
+
exceptions: [
|
|
57
|
+
'Faraday::TimeoutError',
|
|
58
|
+
'Faraday::ConnectionFailed',
|
|
59
|
+
'Errno::ETIMEDOUT',
|
|
60
|
+
'Timeout::Error'
|
|
61
|
+
],
|
|
62
|
+
retry_statuses: [502, 504]
|
|
63
|
+
end
|
|
64
|
+
|
|
45
65
|
conn.response :json, :content_type => /\bjson$/
|
|
66
|
+
conn.options.timeout = 30 # Total request timeout
|
|
67
|
+
conn.options.open_timeout = 5 # Connection establishment timeout
|
|
68
|
+
|
|
69
|
+
# Use persistent HTTP connections (requires net-http-persistent gem)
|
|
70
|
+
begin
|
|
71
|
+
conn.adapter :net_http_persistent
|
|
72
|
+
rescue LoadError
|
|
73
|
+
# Fallback to default adapter if net-http-persistent isn't available
|
|
74
|
+
Rails.logger.warn "[WhiplashApp] net-http-persistent gem not found, using default adapter" if defined?(Rails)
|
|
75
|
+
conn.adapter Faraday.default_adapter
|
|
76
|
+
end
|
|
46
77
|
end
|
|
47
78
|
end
|
|
48
79
|
|
|
@@ -112,4 +143,4 @@ module Net
|
|
|
112
143
|
|
|
113
144
|
end
|
|
114
145
|
end
|
|
115
|
-
end
|
|
146
|
+
end
|
data/whiplash-app.gemspec
CHANGED
|
@@ -20,9 +20,11 @@ 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'
|
|
24
|
+
spec.add_dependency "faraday-retry"
|
|
23
25
|
|
|
24
26
|
spec.add_development_dependency "bundler", ">= 2.2"
|
|
25
27
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
|
26
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
27
|
-
spec.add_development_dependency "pry"
|
|
29
|
+
spec.add_development_dependency "pry", "~> 0.14"
|
|
28
30
|
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.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Don Sullivan, Mark Dickson
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-07-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oauth2
|
|
@@ -38,6 +38,34 @@ 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'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: faraday-retry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
41
69
|
- !ruby/object:Gem::Dependency
|
|
42
70
|
name: bundler
|
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,14 +114,14 @@ dependencies:
|
|
|
86
114
|
requirements:
|
|
87
115
|
- - "~>"
|
|
88
116
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 0.
|
|
117
|
+
version: '0.14'
|
|
90
118
|
type: :development
|
|
91
119
|
prerelease: false
|
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
121
|
requirements:
|
|
94
122
|
- - "~>"
|
|
95
123
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 0.
|
|
124
|
+
version: '0.14'
|
|
97
125
|
description: this gem provides connectivity to the Whiplash API for authentication
|
|
98
126
|
and REST requests.
|
|
99
127
|
email:
|
|
@@ -126,7 +154,7 @@ files:
|
|
|
126
154
|
homepage: https://github.com/whiplashmerch/whiplash-app
|
|
127
155
|
licenses: []
|
|
128
156
|
metadata: {}
|
|
129
|
-
post_install_message:
|
|
157
|
+
post_install_message:
|
|
130
158
|
rdoc_options: []
|
|
131
159
|
require_paths:
|
|
132
160
|
- lib
|
|
@@ -141,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
141
169
|
- !ruby/object:Gem::Version
|
|
142
170
|
version: '0'
|
|
143
171
|
requirements: []
|
|
144
|
-
rubygems_version: 3.4.
|
|
145
|
-
signing_key:
|
|
172
|
+
rubygems_version: 3.4.6
|
|
173
|
+
signing_key:
|
|
146
174
|
specification_version: 4
|
|
147
175
|
summary: this gem provides connectivity to the Whiplash API for authentication and
|
|
148
176
|
REST requests.
|