pco-url 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/circle.yml +3 -0
- data/lib/pco/url/version.rb +1 -1
- data/lib/pco/url.rb +87 -25
- data/pco-url.gemspec +2 -1
- data/spec/pco_url_spec.rb +85 -1
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed356d2dbbab3e8708ea65a815ca446bcd3e03f4
|
4
|
+
data.tar.gz: 9cd7d6c4b34c7a5ae5bbfd8c09d223e6eb41cb81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebdba2d53cc88b853682bde6c207878c6a5101050031327b6b43ddddf1f2e37f422118c5abc4abd34333b7ed220e9e6ad55c2252eb97e162d8049bf548299e01
|
7
|
+
data.tar.gz: aaaa5009648ba29dee52ab3d6065069d9494d48ac9b7b8e241a922f399170d91142947828eaae423d7e1c0010b5edb9e6a031ce678965851380a8e9f32f975dc
|
data/LICENSE.txt
CHANGED
data/circle.yml
ADDED
data/lib/pco/url/version.rb
CHANGED
data/lib/pco/url.rb
CHANGED
@@ -1,48 +1,110 @@
|
|
1
1
|
require "pco/url/version"
|
2
|
-
require
|
2
|
+
require "uri"
|
3
|
+
require "URLcrypt"
|
3
4
|
|
4
5
|
module PCO
|
5
6
|
class URL
|
6
|
-
|
7
7
|
class << self
|
8
|
+
def decrypt_query_params(string)
|
9
|
+
URLcrypt.decrypt(string)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(string)
|
13
|
+
if uri = URI.parse(string)
|
14
|
+
app_name = uri.host.match(/(\w+)(-staging)?/)[1]
|
15
|
+
|
16
|
+
if uri.query
|
17
|
+
if encrypted_part = encrypted_query_string(uri.query)
|
18
|
+
uri.query.sub!("_e=#{encrypted_part}", decrypt_query_params(encrypted_part))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
new(app_name: app_name, path: uri.path, query: uri.query)
|
23
|
+
else
|
24
|
+
raise InvalidPCOURLString, "Unrecognized PCO::URL url string"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
8
28
|
def method_missing(method_name, *args)
|
9
|
-
|
29
|
+
path = args.map { |p| p.sub(/\A\/+/, "").sub(/\/+\Z/, "") }.join("/")
|
30
|
+
new(app_name: method_name, path: path).to_s
|
10
31
|
end
|
11
32
|
|
12
33
|
private
|
13
34
|
|
14
|
-
def
|
15
|
-
|
35
|
+
def encrypted_query_string(query_params)
|
36
|
+
if query_params =~ encrypted_params_regex
|
37
|
+
Regexp.last_match(:param)
|
38
|
+
end
|
16
39
|
end
|
17
40
|
|
18
|
-
def
|
19
|
-
|
20
|
-
ENV[env_var]
|
41
|
+
def encrypted_params_regex
|
42
|
+
/^_e=(?<param>[^\&]*)/
|
21
43
|
end
|
44
|
+
end
|
22
45
|
|
23
|
-
|
24
|
-
|
46
|
+
attr_reader :app_name
|
47
|
+
attr_reader :path
|
48
|
+
attr_reader :query
|
25
49
|
|
26
|
-
|
50
|
+
def initialize(app_name:, path: nil, query: nil, encrypt_query_params: false)
|
51
|
+
@app_name = app_name.to_s.gsub("_", "-")
|
52
|
+
@path = path
|
53
|
+
|
54
|
+
if query
|
55
|
+
@query = encrypt_query_params ? "_e=#{URLcrypt.encrypt(query)}" : query
|
27
56
|
end
|
57
|
+
end
|
28
58
|
|
29
|
-
|
30
|
-
|
31
|
-
|
59
|
+
def scheme
|
60
|
+
# Try "CHECK_INS_URL" then url_for_app("check-ins")
|
61
|
+
return env_overridden_hostname.split("://")[0] if env_overridden_hostname
|
32
62
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"https://#{app_name}-staging.planningcenteronline.com"
|
39
|
-
when "development"
|
40
|
-
"http://#{app_name}.pco.dev"
|
41
|
-
when "test"
|
42
|
-
"http://#{app_name}.pco.test"
|
43
|
-
end
|
63
|
+
case env
|
64
|
+
when "production", "staging"
|
65
|
+
"https"
|
66
|
+
else
|
67
|
+
"http"
|
44
68
|
end
|
45
69
|
end
|
46
70
|
|
71
|
+
def hostname
|
72
|
+
# Try "CHECK_INS_URL" then url_for_app("check-ins")
|
73
|
+
return env_overridden_hostname.split("://")[1] if env_overridden_hostname
|
74
|
+
|
75
|
+
case env
|
76
|
+
when "production"
|
77
|
+
"#{@app_name}.planningcenteronline.com"
|
78
|
+
when "staging"
|
79
|
+
"#{@app_name}-staging.planningcenteronline.com"
|
80
|
+
when "development"
|
81
|
+
"#{@app_name}.pco.dev"
|
82
|
+
when "test"
|
83
|
+
"#{@app_name}.pco.test"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def uri
|
88
|
+
query = @query ? "?#{@query}" : nil
|
89
|
+
url_string = "#{scheme}://#{hostname}/#{@path}#{query}".sub(/(\/)+$/,'')
|
90
|
+
URI(url_string)
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
uri.to_s
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def env
|
100
|
+
ENV["DEPLOY_ENV"] || Rails.env
|
101
|
+
end
|
102
|
+
|
103
|
+
def env_overridden_hostname
|
104
|
+
env_var = @app_name.to_s.upcase + "_URL"
|
105
|
+
ENV[env_var]
|
106
|
+
end
|
47
107
|
end
|
108
|
+
|
109
|
+
class InvalidPCOURLString < StandardError; end
|
48
110
|
end
|
data/pco-url.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = PCO::URL::VERSION
|
9
9
|
spec.authors = ["James Miller"]
|
10
10
|
spec.email = ["bensie@gmail.com"]
|
11
|
-
spec.summary = %q{Generate URLs for
|
11
|
+
spec.summary = %q{Generate URLs for PCO apps in all environments}
|
12
12
|
spec.homepage = "https://github.com/ministrycentered/pco-url"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
+
spec.add_dependency "urlcrypt", ">= 0.1.1"
|
20
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
23
|
spec.add_development_dependency "rspec", ">= 3.0.0", "< 4"
|
data/spec/pco_url_spec.rb
CHANGED
@@ -7,10 +7,15 @@ Applications = [
|
|
7
7
|
:check_ins,
|
8
8
|
:people,
|
9
9
|
:registrations,
|
10
|
-
:resources
|
10
|
+
:resources,
|
11
|
+
:giving
|
11
12
|
]
|
12
13
|
|
13
14
|
describe PCO::URL do
|
15
|
+
before :all do
|
16
|
+
URLcrypt.key = "984e9002e680dc9b9c2556434c47f7e4782191f52063277901e4a009797652e08f28be069dfb4d4a1e3c9ab09fedab59be2c9b6486748bf44030182815ee4987"
|
17
|
+
end
|
18
|
+
|
14
19
|
describe "defaults" do
|
15
20
|
describe "development" do
|
16
21
|
before do
|
@@ -127,4 +132,83 @@ describe PCO::URL do
|
|
127
132
|
end
|
128
133
|
end
|
129
134
|
|
135
|
+
describe "encrypted params" do
|
136
|
+
subject { PCO::URL.new(app_name: "people", query: "foo=bar", encrypt_query_params: true) }
|
137
|
+
|
138
|
+
it "encrypts URL parameters" do
|
139
|
+
expect(subject.query).to_not eq("foo=bar")
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'puts the encrypted params into the _e key' do
|
143
|
+
expect(subject.query).to match(/^_e=(.*)/)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "encrypts and decrypts URL parameters" do
|
147
|
+
expect(URLcrypt.decrypt(subject.query.gsub("_e=", ""))).to eq("foo=bar")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "decrypts using #decrypt_query_params" do
|
151
|
+
expect(PCO::URL.decrypt_query_params(subject.query.gsub("_e=", ""))).to eq("foo=bar")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '.parse' do
|
156
|
+
subject { PCO::URL.parse("https://people-staging.planningcenteronline.com") }
|
157
|
+
|
158
|
+
it 'returns a PCO::URL object' do
|
159
|
+
expect(subject.class).to eq(PCO::URL)
|
160
|
+
end
|
161
|
+
|
162
|
+
context 'when only a url string is passed' do
|
163
|
+
subject { PCO::URL.parse("http://people.pco.dev") }
|
164
|
+
|
165
|
+
it 'sets the app_name attr' do
|
166
|
+
expect(subject.app_name).to eq('people')
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'strips -staging if supplied' do
|
170
|
+
expect(PCO::URL.parse("https://people-staging.plannincenteronline.com").app_name).
|
171
|
+
to eq('people')
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context 'when a string and path is passed' do
|
176
|
+
subject { PCO::URL.parse("https://people.planningcenteronline.com/households/2.json") }
|
177
|
+
|
178
|
+
it 'sets the app_name and path attrs' do
|
179
|
+
expect(subject.app_name).to eq('people')
|
180
|
+
expect(subject.path).to eq('/households/2.json')
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when a string, path and query are passed' do
|
185
|
+
let(:pco_url) { PCO::URL.new(app_name: :people, path: 'households/2.html', query: 'full_access=1&total_control=1', encrypt_query_params: true) }
|
186
|
+
|
187
|
+
subject { PCO::URL.parse("https://people.planningcenteronline.com/households/2.html?full_access=1&total_control=1") }
|
188
|
+
|
189
|
+
it 'sets the app_name, path, and query attrs' do
|
190
|
+
expect(subject.app_name).to eq('people')
|
191
|
+
expect(subject.path).to eq('/households/2.html')
|
192
|
+
expect(subject.query).to eq('full_access=1&total_control=1')
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when the query is encrypted' do
|
196
|
+
subject { PCO::URL.parse(pco_url.to_s) }
|
197
|
+
|
198
|
+
it 'first decrypts the query' do
|
199
|
+
expect(pco_url.query).not_to eq('full_access=1&total_control=1')
|
200
|
+
expect(subject.query).to eq('full_access=1&total_control=1')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "when part of the query string is encrypted" do
|
205
|
+
subject { PCO::URL.parse(pco_url.to_s + "&foo=bar") }
|
206
|
+
|
207
|
+
it "decrypts the encrypted portion and appends the unencrypted portion" do
|
208
|
+
expect(subject.query).to eq('full_access=1&total_control=1&foo=bar')
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
130
214
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pco-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: urlcrypt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,6 +84,7 @@ files:
|
|
70
84
|
- LICENSE.txt
|
71
85
|
- README.md
|
72
86
|
- Rakefile
|
87
|
+
- circle.yml
|
73
88
|
- lib/pco/url.rb
|
74
89
|
- lib/pco/url/version.rb
|
75
90
|
- pco-url.gemspec
|
@@ -95,10 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
110
|
version: '0'
|
96
111
|
requirements: []
|
97
112
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.4.
|
113
|
+
rubygems_version: 2.4.5
|
99
114
|
signing_key:
|
100
115
|
specification_version: 4
|
101
|
-
summary: Generate URLs for
|
116
|
+
summary: Generate URLs for PCO apps in all environments
|
102
117
|
test_files:
|
103
118
|
- spec/pco_url_spec.rb
|
104
119
|
- spec/spec_helper.rb
|