pco-url 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffffc4ec52600a23d033d2b75f4a7f0bc74db900
4
- data.tar.gz: 7cd6fae8170dc6493aaffc2ad12ad776142cefcc
3
+ metadata.gz: 1a6bcb896c6899ae3d2c38e9e6f0bdf3a4101a38
4
+ data.tar.gz: de4d8e15837e4d36336f8abdd69f26d588cf2683
5
5
  SHA512:
6
- metadata.gz: fffaf131fa4586c17340d679e0545a314167dea60c1c027cac95b87ef0ad663295259e89d5a61b6fba0e337f96febd86e3ac6c49b64aecfffbf02dfa1f101c09
7
- data.tar.gz: 67595608b41b2d9ea1493dac83bb938986f5def9834b6a6dd5328017bb4f59b4847068cce870b310f69907dc5f80a8ce46725c21010494d38457be4660924f8d
6
+ metadata.gz: 13b1f0a753ad9d5fdd13833f036101d0b852b94548e62c4a9c984cfa60b8a1f88d61b48333dcd9b953a2680f7f9ff260ca57183368937f96abeca51f2ff754a5
7
+ data.tar.gz: 6f4d1334ab40d917974c7c0a55c6a50f66d4d13a8d3d9899ac03c48ebbeb7e767c82836be2688352feb27b700df560efd6589be78de038ba78fe63dd1c43ee2f
data/README.md CHANGED
@@ -32,3 +32,18 @@ PCO::URL.accounts
32
32
  PCO::URL.services
33
33
  # => "https://services-staging.planningcenteronline.com"
34
34
  ```
35
+
36
+
37
+ You can also specify the path:
38
+
39
+
40
+ ```ruby
41
+ PCO::URL.accounts("/test")
42
+ # => "https://accounts-test1.planningcenteronline.com/test"
43
+
44
+ PCO::URL.accounts("test")
45
+ # => "https://accounts-test1.planningcenteronline.com/test"
46
+
47
+ PCO::URL.accounts("test", "working")
48
+ # => "https://accounts-test1.planningcenteronline.com/test/working"
49
+ ```
data/lib/pco/url.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  require "pco/url/version"
2
+ require 'uri'
2
3
 
3
4
  module PCO
4
5
  class URL
5
6
 
6
7
  class << self
7
- def method_missing(method_name)
8
- app_name = method_name.to_s.gsub("_", "-")
9
- env_var = method_name.to_s.upcase + "_URL"
10
-
11
- # Try "CHECK_INS_URL" then url_for_app("check-ins")
12
- ENV[env_var] || url_for_app(app_name)
8
+ def method_missing(method_name, *args)
9
+ url_for_app_with_path(method_name, args)
13
10
  end
14
11
 
15
12
  private
@@ -18,7 +15,22 @@ module PCO
18
15
  ENV["DEPLOY_ENV"] || Rails.env
19
16
  end
20
17
 
18
+ def env_url(app_name)
19
+ env_var = app_name.to_s.upcase + "_URL"
20
+ ENV[env_var]
21
+ end
22
+
23
+ def url_for_app_with_path(app_name, paths)
24
+ path = paths.map { |p| p.sub(/\A\/+/, "").sub(/\/+\Z/, "") }.join("/")
25
+
26
+ URI::join(url_for_app(app_name), path).to_s
27
+ end
28
+
21
29
  def url_for_app(app_name)
30
+ # Try "CHECK_INS_URL" then url_for_app("check-ins")
31
+ return env_url(app_name) if env_url(app_name)
32
+
33
+ app_name = app_name.to_s.gsub("_", "-")
22
34
  case env
23
35
  when "production"
24
36
  "https://#{app_name}.planningcenteronline.com"
@@ -1,5 +1,5 @@
1
1
  module PCO
2
2
  class URL
3
- VERSION = "1.2.0"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
data/spec/pco_url_spec.rb CHANGED
@@ -61,6 +61,35 @@ describe PCO::URL do
61
61
  end
62
62
  end
63
63
 
64
+ context "with path starting with /" do
65
+ Applications.map(&:to_s).each do |app|
66
+ it "has an #{app} URL with path" do
67
+ expect(PCO::URL.send(app, "/test")).to eq("http://#{app.gsub('_','-')}.pco.test/test")
68
+ end
69
+ end
70
+ end
71
+
72
+ context "with path NOT starting with /" do
73
+ Applications.map(&:to_s).each do |app|
74
+ it "has an #{app} URL with path" do
75
+ expect(PCO::URL.send(app, "test")).to eq("http://#{app.gsub('_','-')}.pco.test/test")
76
+ end
77
+ end
78
+ end
79
+
80
+ context "with multiple path arguments" do
81
+ Applications.map(&:to_s).each do |app|
82
+ it "has an #{app} URL with path" do
83
+ expect(PCO::URL.send(app, "test", "test2")).to eq("http://#{app.gsub('_','-')}.pco.test/test/test2")
84
+ expect(PCO::URL.send(app, "test/", "test2")).to eq("http://#{app.gsub('_','-')}.pco.test/test/test2")
85
+ expect(PCO::URL.send(app, "test", "/test2")).to eq("http://#{app.gsub('_','-')}.pco.test/test/test2")
86
+ expect(PCO::URL.send(app, "/test/", "test2")).to eq("http://#{app.gsub('_','-')}.pco.test/test/test2")
87
+ expect(PCO::URL.send(app, "/test/test2")).to eq("http://#{app.gsub('_','-')}.pco.test/test/test2")
88
+ end
89
+ end
90
+ end
91
+
92
+
64
93
  describe "overrides" do
65
94
  describe "development with accounts URL override" do
66
95
  before do
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.2.0
4
+ version: 1.3.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: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.4.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Generate URLs for app PCO apps in all environments