pco-url 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +10 -0
- data/.rubocop.yml +12 -0
- data/lib/pco/url.rb +18 -11
- data/lib/pco/url/church_center.rb +38 -0
- data/lib/pco/url/get.rb +13 -0
- data/lib/pco/url/version.rb +1 -1
- data/spec/pco/url/church_center_spec.rb +75 -0
- data/spec/pco_url_spec.rb +87 -49
- data/spec/spec_helper.rb +2 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd5c1701dc11bca36cd95692deaf7890af3d5ec
|
4
|
+
data.tar.gz: 5cd53a34ae90fcad2937255cdc6150d678fb9f3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1e1eaa9547e8dae3ff58e8e09d7ef7b4f5e9a114283603c99830ba80152b9b68dc8ea9c193df491a9323160d31cb8741af4f3c6488a2126d8e26c5b3906a048
|
7
|
+
data.tar.gz: 6804c37316401818e169d6bddd145c12f9076289667dfb661c3a5d80d6bc5355de522c9fbd2cbae313a27c7c0505db711ac6dd41a23cead682bf53165ce09265
|
data/.editorconfig
ADDED
data/.rubocop.yml
ADDED
data/lib/pco/url.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
require_relative "url/version"
|
2
|
+
require_relative "url/church_center"
|
3
|
+
require_relative "url/get"
|
2
4
|
require "uri"
|
3
5
|
require "URLcrypt"
|
4
6
|
|
@@ -10,32 +12,37 @@ module PCO
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def parse(string)
|
13
|
-
if uri = URI.parse(string)
|
15
|
+
if (uri = URI.parse(string))
|
14
16
|
app_name = uri.host.match(/(\w+)(-staging)?/)[1]
|
15
17
|
|
16
18
|
if uri.query
|
17
|
-
if encrypted_part = encrypted_query_string(uri.query)
|
19
|
+
if (encrypted_part = encrypted_query_string(uri.query))
|
18
20
|
uri.query.sub!("_e=#{encrypted_part}", decrypt_query_params(encrypted_part))
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
24
|
new(app_name: app_name, path: uri.path, query: uri.query)
|
23
25
|
else
|
24
|
-
|
26
|
+
fail InvalidPCOURLString, "Unrecognized PCO::URL url string"
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def method_missing(method_name, *args)
|
29
|
-
path = args.map { |p| p.sub(
|
30
|
-
|
31
|
+
path = args.map { |p| p.sub(%r{\A/+}, "").sub(%r{/+\Z}, "") }.join("/")
|
32
|
+
case method_name
|
33
|
+
when :church_center
|
34
|
+
PCO::URL::ChurchCenter.new(path: path).to_s
|
35
|
+
when :get
|
36
|
+
PCO::URL::Get.new(path: path).to_s
|
37
|
+
else
|
38
|
+
new(app_name: method_name, path: path).to_s
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
private
|
34
43
|
|
35
44
|
def encrypted_query_string(query_params)
|
36
|
-
if query_params =~ encrypted_params_regex
|
37
|
-
Regexp.last_match(:param)
|
38
|
-
end
|
45
|
+
Regexp.last_match(:param) if query_params =~ encrypted_params_regex
|
39
46
|
end
|
40
47
|
|
41
48
|
def encrypted_params_regex
|
@@ -48,7 +55,7 @@ module PCO
|
|
48
55
|
attr_reader :query
|
49
56
|
|
50
57
|
def initialize(app_name:, path: nil, query: nil, encrypt_query_params: false, domain: nil)
|
51
|
-
@app_name = app_name.to_s.
|
58
|
+
@app_name = app_name.to_s.tr("_", "-")
|
52
59
|
@path = path
|
53
60
|
@domain = domain
|
54
61
|
|
@@ -98,7 +105,7 @@ module PCO
|
|
98
105
|
|
99
106
|
def uri
|
100
107
|
q = query ? "?#{query}" : nil
|
101
|
-
url_string = "#{scheme}://#{hostname}/#{path}#{q}".sub(/
|
108
|
+
url_string = "#{scheme}://#{hostname}/#{path}#{q}".sub(%r{(/)+$}, "")
|
102
109
|
URI(url_string)
|
103
110
|
end
|
104
111
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PCO
|
2
|
+
class URL
|
3
|
+
class ChurchCenter < URL
|
4
|
+
def initialize(app_name: "church-center", path: nil, query: nil, encrypt_query_params: false, domain: nil, subdomain: nil)
|
5
|
+
super(
|
6
|
+
app_name: app_name,
|
7
|
+
path: path,
|
8
|
+
query: query,
|
9
|
+
encrypt_query_params: encrypt_query_params,
|
10
|
+
domain: domain
|
11
|
+
)
|
12
|
+
@subdomain = subdomain
|
13
|
+
end
|
14
|
+
|
15
|
+
def domain
|
16
|
+
return @domain if @domain
|
17
|
+
case env
|
18
|
+
when "production", "staging"
|
19
|
+
"churchcenteronline.com"
|
20
|
+
when "development"
|
21
|
+
"churchcenter.dev"
|
22
|
+
when "test"
|
23
|
+
"churchcenter.test"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def hostname
|
28
|
+
super if env_overridden_hostname
|
29
|
+
sub = "#{@subdomain}." if @subdomain
|
30
|
+
if env == "staging"
|
31
|
+
"#{sub}staging.#{domain}"
|
32
|
+
else
|
33
|
+
"#{sub}#{domain}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/pco/url/get.rb
ADDED
data/lib/pco/url/version.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PCO::URL::ChurchCenter do
|
4
|
+
context "when the env is production" do
|
5
|
+
before do
|
6
|
+
Rails.env = "production"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#to_s" do
|
10
|
+
context "given a subdomain" do
|
11
|
+
subject { described_class.new(subdomain: "foo") }
|
12
|
+
|
13
|
+
it "returns the proper URL" do
|
14
|
+
expect(subject.to_s).to eq("https://foo.churchcenteronline.com")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "given no subdomain" do
|
19
|
+
subject { described_class.new }
|
20
|
+
|
21
|
+
it "returns the proper URL" do
|
22
|
+
expect(subject.to_s).to eq("https://churchcenteronline.com")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when the env is staging" do
|
29
|
+
before do
|
30
|
+
Rails.env = "staging"
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#to_s" do
|
34
|
+
context "given a subdomain" do
|
35
|
+
subject { described_class.new(subdomain: "foo") }
|
36
|
+
|
37
|
+
it "returns the proper URL" do
|
38
|
+
expect(subject.to_s).to eq("https://foo.staging.churchcenteronline.com")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "given no subdomain" do
|
43
|
+
subject { described_class.new }
|
44
|
+
|
45
|
+
it "returns the proper URL" do
|
46
|
+
expect(subject.to_s).to eq("https://staging.churchcenteronline.com")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the env is development" do
|
53
|
+
before do
|
54
|
+
Rails.env = "development"
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#to_s" do
|
58
|
+
context "given a subdomain" do
|
59
|
+
subject { described_class.new(subdomain: "foo") }
|
60
|
+
|
61
|
+
it "returns the proper URL" do
|
62
|
+
expect(subject.to_s).to eq("http://foo.churchcenter.dev")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "given no subdomain" do
|
67
|
+
subject { described_class.new }
|
68
|
+
|
69
|
+
it "returns the proper URL" do
|
70
|
+
expect(subject.to_s).to eq("http://churchcenter.dev")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/spec/pco_url_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
|
3
|
+
APPLICATIONS = [
|
4
4
|
:accounts,
|
5
5
|
:avatars,
|
6
6
|
:services,
|
@@ -8,12 +8,14 @@ Applications = [
|
|
8
8
|
:people,
|
9
9
|
:registrations,
|
10
10
|
:resources,
|
11
|
-
:giving
|
11
|
+
:giving,
|
12
|
+
:get
|
12
13
|
]
|
13
14
|
|
14
15
|
describe PCO::URL do
|
15
16
|
before :all do
|
16
|
-
URLcrypt.key = "
|
17
|
+
URLcrypt.key = "984e9002e680dc9b9c2556434c47f7e4782191f52063277901e4a009797652e0" \
|
18
|
+
"8f28be069dfb4d4a1e3c9ab09fedab59be2c9b6486748bf44030182815ee4987"
|
17
19
|
end
|
18
20
|
|
19
21
|
describe "defaults" do
|
@@ -22,11 +24,15 @@ describe PCO::URL do
|
|
22
24
|
Rails.env = "development"
|
23
25
|
end
|
24
26
|
|
25
|
-
|
27
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
26
28
|
it "has an #{app} URL" do
|
27
|
-
expect(PCO::URL.send(app)).to eq("http://#{app.
|
29
|
+
expect(PCO::URL.send(app)).to eq("http://#{app.tr('_', '-')}.pco.dev")
|
28
30
|
end
|
29
31
|
end
|
32
|
+
|
33
|
+
it "has a church-center url" do
|
34
|
+
expect(PCO::URL.church_center).to eq("http://churchcenter.dev")
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
describe "staging" do
|
@@ -34,11 +40,20 @@ describe PCO::URL do
|
|
34
40
|
Rails.env = "staging"
|
35
41
|
end
|
36
42
|
|
37
|
-
|
43
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
44
|
+
next if app == "get"
|
38
45
|
it "has an #{app} URL" do
|
39
|
-
expect(PCO::URL.send(app)).to eq("https://#{app.
|
46
|
+
expect(PCO::URL.send(app)).to eq("https://#{app.tr('_', '-')}-staging.planningcenteronline.com")
|
40
47
|
end
|
41
48
|
end
|
49
|
+
|
50
|
+
it "has an http get URL" do
|
51
|
+
expect(PCO::URL.send("get")).to eq("http://get-staging.planningcenteronline.com")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "has a church-center url" do
|
55
|
+
expect(PCO::URL.church_center).to eq("https://staging.churchcenteronline.com")
|
56
|
+
end
|
42
57
|
end
|
43
58
|
|
44
59
|
describe "production" do
|
@@ -46,11 +61,20 @@ describe PCO::URL do
|
|
46
61
|
Rails.env = "production"
|
47
62
|
end
|
48
63
|
|
49
|
-
|
64
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
65
|
+
next if app == "get"
|
50
66
|
it "has an #{app} URL" do
|
51
|
-
expect(PCO::URL.send(app)).to eq("https://#{app.
|
67
|
+
expect(PCO::URL.send(app)).to eq("https://#{app.tr('_', '-')}.planningcenteronline.com")
|
52
68
|
end
|
53
69
|
end
|
70
|
+
|
71
|
+
it "has an http get URL" do
|
72
|
+
expect(PCO::URL.send("get")).to eq("http://get.planningcenteronline.com")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "has a church-center url" do
|
76
|
+
expect(PCO::URL.church_center).to eq("https://churchcenteronline.com")
|
77
|
+
end
|
54
78
|
end
|
55
79
|
|
56
80
|
describe "test" do
|
@@ -58,11 +82,15 @@ describe PCO::URL do
|
|
58
82
|
Rails.env = "test"
|
59
83
|
end
|
60
84
|
|
61
|
-
|
85
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
62
86
|
it "has an #{app} URL" do
|
63
|
-
expect(PCO::URL.send(app)).to eq("http://#{app.
|
87
|
+
expect(PCO::URL.send(app)).to eq("http://#{app.tr('_', '-')}.pco.test")
|
64
88
|
end
|
65
89
|
end
|
90
|
+
|
91
|
+
it "has a church-center url" do
|
92
|
+
expect(PCO::URL.church_center).to eq("http://churchcenter.test")
|
93
|
+
end
|
66
94
|
end
|
67
95
|
end
|
68
96
|
|
@@ -73,34 +101,33 @@ describe PCO::URL do
|
|
73
101
|
end
|
74
102
|
|
75
103
|
context "with path starting with /" do
|
76
|
-
|
104
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
77
105
|
it "has an #{app} URL with path" do
|
78
|
-
expect(PCO::URL.send(app, "/test")).to eq("http://#{app.
|
106
|
+
expect(PCO::URL.send(app, "/test")).to eq("http://#{app.tr('_', '-')}.pco.test/test")
|
79
107
|
end
|
80
108
|
end
|
81
109
|
end
|
82
110
|
|
83
111
|
context "with path NOT starting with /" do
|
84
|
-
|
112
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
85
113
|
it "has an #{app} URL with path" do
|
86
|
-
expect(PCO::URL.send(app, "test")).to eq("http://#{app.
|
114
|
+
expect(PCO::URL.send(app, "test")).to eq("http://#{app.tr('_', '-')}.pco.test/test")
|
87
115
|
end
|
88
116
|
end
|
89
117
|
end
|
90
118
|
|
91
119
|
context "with multiple path arguments" do
|
92
|
-
|
120
|
+
APPLICATIONS.map(&:to_s).each do |app|
|
93
121
|
it "has an #{app} URL with path" do
|
94
|
-
expect(PCO::URL.send(app, "test", "test2")).to
|
95
|
-
expect(PCO::URL.send(app, "test/", "test2")).to
|
96
|
-
expect(PCO::URL.send(app, "test", "/test2")).to
|
97
|
-
expect(PCO::URL.send(app, "/test/", "test2")).to eq("http://#{app.
|
98
|
-
expect(PCO::URL.send(app, "/test/test2")).to
|
122
|
+
expect(PCO::URL.send(app, "test", "test2")).to eq("http://#{app.tr('_', '-')}.pco.test/test/test2")
|
123
|
+
expect(PCO::URL.send(app, "test/", "test2")).to eq("http://#{app.tr('_', '-')}.pco.test/test/test2")
|
124
|
+
expect(PCO::URL.send(app, "test", "/test2")).to eq("http://#{app.tr('_', '-')}.pco.test/test/test2")
|
125
|
+
expect(PCO::URL.send(app, "/test/", "test2")).to eq("http://#{app.tr('_', '-')}.pco.test/test/test2")
|
126
|
+
expect(PCO::URL.send(app, "/test/test2")).to eq("http://#{app.tr('_', '-')}.pco.test/test/test2")
|
99
127
|
end
|
100
128
|
end
|
101
129
|
end
|
102
130
|
|
103
|
-
|
104
131
|
describe "overrides" do
|
105
132
|
describe "development with accounts URL override" do
|
106
133
|
before do
|
@@ -145,7 +172,7 @@ describe PCO::URL do
|
|
145
172
|
expect(subject.query).to_not eq("foo=bar")
|
146
173
|
end
|
147
174
|
|
148
|
-
it
|
175
|
+
it "puts the encrypted params into the _e key" do
|
149
176
|
expect(subject.query).to match(/^_e=(.*)/)
|
150
177
|
end
|
151
178
|
|
@@ -158,52 +185,62 @@ describe PCO::URL do
|
|
158
185
|
end
|
159
186
|
end
|
160
187
|
|
161
|
-
describe
|
188
|
+
describe ".parse" do
|
162
189
|
subject { PCO::URL.parse("https://people-staging.planningcenteronline.com") }
|
163
190
|
|
164
|
-
it
|
191
|
+
it "returns a PCO::URL object" do
|
165
192
|
expect(subject.class).to eq(PCO::URL)
|
166
193
|
end
|
167
194
|
|
168
|
-
context
|
195
|
+
context "when only a url string is passed" do
|
169
196
|
subject { PCO::URL.parse("http://people.pco.dev") }
|
170
197
|
|
171
|
-
it
|
172
|
-
expect(subject.app_name).to eq(
|
198
|
+
it "sets the app_name attr" do
|
199
|
+
expect(subject.app_name).to eq("people")
|
173
200
|
end
|
174
201
|
|
175
|
-
it
|
176
|
-
expect(PCO::URL.parse("https://people-staging.plannincenteronline.com").app_name).
|
177
|
-
to eq('people')
|
202
|
+
it "strips -staging if supplied" do
|
203
|
+
expect(PCO::URL.parse("https://people-staging.plannincenteronline.com").app_name).to eq("people")
|
178
204
|
end
|
179
205
|
end
|
180
206
|
|
181
|
-
context
|
207
|
+
context "when a string and path is passed" do
|
182
208
|
subject { PCO::URL.parse("https://people.planningcenteronline.com/households/2.json") }
|
183
209
|
|
184
|
-
it
|
185
|
-
expect(subject.app_name).to eq(
|
186
|
-
expect(subject.path).to eq(
|
210
|
+
it "sets the app_name and path attrs" do
|
211
|
+
expect(subject.app_name).to eq("people")
|
212
|
+
expect(subject.path).to eq("households/2.json")
|
187
213
|
end
|
188
214
|
end
|
189
215
|
|
190
|
-
context
|
191
|
-
let(:pco_url)
|
216
|
+
context "when a string, path and query are passed" do
|
217
|
+
let(:pco_url) do
|
218
|
+
PCO::URL.new(
|
219
|
+
app_name: :people,
|
220
|
+
path: "households/2.html",
|
221
|
+
query: "full_access=1&total_control=1",
|
222
|
+
encrypt_query_params: true
|
223
|
+
)
|
224
|
+
end
|
192
225
|
|
193
|
-
subject
|
226
|
+
subject do
|
227
|
+
PCO::URL.parse(
|
228
|
+
"https://people.planningcenteronline.com/households/2.html?full_access=1&total_control=1"
|
229
|
+
)
|
230
|
+
end
|
194
231
|
|
195
|
-
it
|
196
|
-
expect(subject.app_name).to eq(
|
197
|
-
expect(subject.path).to eq(
|
198
|
-
expect(subject.query).to eq(
|
232
|
+
it "sets the app_name, path, and query attrs" do
|
233
|
+
expect(subject.app_name).to eq("people")
|
234
|
+
expect(subject.path).to eq("households/2.html")
|
235
|
+
expect(subject.query).to eq("full_access=1&total_control=1")
|
199
236
|
end
|
200
237
|
|
201
|
-
context
|
238
|
+
context "when the query is encrypted" do
|
202
239
|
subject { PCO::URL.parse(pco_url.to_s) }
|
203
240
|
|
204
|
-
it
|
205
|
-
expect(pco_url.query).not_to eq(
|
206
|
-
expect(subject.query).to eq(
|
241
|
+
it "first decrypts the query" do
|
242
|
+
expect(pco_url.query).not_to eq("full_access=1&total_control=1")
|
243
|
+
expect(subject.query).to eq("full_access=1&total_control=1")
|
207
244
|
end
|
208
245
|
end
|
209
246
|
|
@@ -211,14 +248,15 @@ describe PCO::URL do
|
|
211
248
|
subject { PCO::URL.parse(pco_url.to_s + "&foo=bar") }
|
212
249
|
|
213
250
|
it "decrypts the encrypted portion and appends the unencrypted portion" do
|
214
|
-
expect(subject.query).to eq(
|
251
|
+
expect(subject.query).to eq("full_access=1&total_control=1&foo=bar")
|
215
252
|
end
|
216
253
|
|
217
254
|
it "returns the full url" do
|
218
|
-
expect(subject.to_s).to eq(
|
255
|
+
expect(subject.to_s).to eq(
|
256
|
+
"https://people-staging.planningcenteronline.com/households/2.html?full_access=1&total_control=1&foo=bar"
|
257
|
+
)
|
219
258
|
end
|
220
259
|
end
|
221
260
|
end
|
222
261
|
end
|
223
|
-
|
224
262
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pco-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.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: 2015-
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: urlcrypt
|
@@ -79,15 +79,20 @@ executables: []
|
|
79
79
|
extensions: []
|
80
80
|
extra_rdoc_files: []
|
81
81
|
files:
|
82
|
+
- ".editorconfig"
|
82
83
|
- ".gitignore"
|
84
|
+
- ".rubocop.yml"
|
83
85
|
- Gemfile
|
84
86
|
- LICENSE.txt
|
85
87
|
- README.md
|
86
88
|
- Rakefile
|
87
89
|
- circle.yml
|
88
90
|
- lib/pco/url.rb
|
91
|
+
- lib/pco/url/church_center.rb
|
92
|
+
- lib/pco/url/get.rb
|
89
93
|
- lib/pco/url/version.rb
|
90
94
|
- pco-url.gemspec
|
95
|
+
- spec/pco/url/church_center_spec.rb
|
91
96
|
- spec/pco_url_spec.rb
|
92
97
|
- spec/spec_helper.rb
|
93
98
|
homepage: https://github.com/ministrycentered/pco-url
|
@@ -115,5 +120,7 @@ signing_key:
|
|
115
120
|
specification_version: 4
|
116
121
|
summary: Generate URLs for PCO apps in all environments
|
117
122
|
test_files:
|
123
|
+
- spec/pco/url/church_center_spec.rb
|
118
124
|
- spec/pco_url_spec.rb
|
119
125
|
- spec/spec_helper.rb
|
126
|
+
has_rdoc:
|