class PCO::URL
Constants
- DOMAINS
- VERSION
Attributes
app_name[R]
path[R]
query[R]
Public Class Methods
decrypt_query_params(string)
click to toggle source
# File lib/pco/url.rb, line 18 def decrypt_query_params(string) Encryption.decrypt(string) end
method_missing(method_name, *args)
click to toggle source
# File lib/pco/url.rb, line 38 def method_missing(method_name, *args) path = args.map { |p| p.sub(%r{\A/+}, "").sub(%r{/+\Z}, "") }.join("/") case method_name when :church_center PCO::URL::ChurchCenter.new(path: path).to_s when :get PCO::URL::Get.new(path: path).to_s else new(app_name: method_name, path: path).to_s end end
new(app_name:, path: nil, query: nil, encrypt_query_params: false, domain: nil)
click to toggle source
# File lib/pco/url.rb, line 65 def initialize(app_name:, path: nil, query: nil, encrypt_query_params: false, domain: nil) @app_name = app_name.to_s.tr("_", "-") @path = path @domain = domain @path = @path[1..-1] if @path && @path[0] == "/" if query @query = encrypt_query_params ? "_e=#{Encryption.encrypt(query)}" : query end end
parse(string)
click to toggle source
# File lib/pco/url.rb, line 22 def parse(string) if (uri = URI.parse(string)) app_name = uri.host.match(/(\w+)(-staging)?/)[1] if uri.query if (encrypted_part = encrypted_query_string(uri.query)) uri.query.sub!("_e=#{encrypted_part}", decrypt_query_params(encrypted_part)) end end new(app_name: app_name, path: uri.path, query: uri.query) else fail InvalidPCOURLString, "Unrecognized PCO::URL url string" end end
Private Class Methods
encrypted_params_regex()
click to toggle source
# File lib/pco/url.rb, line 56 def encrypted_params_regex /\b_e=(?<param>[^\&]*)/ end
encrypted_query_string(query_params)
click to toggle source
# File lib/pco/url.rb, line 52 def encrypted_query_string(query_params) Regexp.last_match(:param) if query_params =~ encrypted_params_regex end
Public Instance Methods
domain()
click to toggle source
# File lib/pco/url.rb, line 89 def domain return @domain if @domain return PCO::URL::Engine.domain if PCO::URL::Engine.domain case env when "production", "staging" "planningcenteronline.com" when "test" "pco.test" when "development" "pco.test" end end
hostname()
click to toggle source
# File lib/pco/url.rb, line 104 def hostname # Try "CHECK_INS_URL" then url_for_app("check-ins") return env_overridden_hostname.split("://")[1] if env_overridden_hostname case env when "staging" "#{app_name}-staging.#{domain}" else "#{app_name}.#{domain}" end end
scheme()
click to toggle source
# File lib/pco/url.rb, line 77 def scheme # Try "CHECK_INS_URL" then url_for_app("check-ins") return env_overridden_hostname.split("://")[0] if env_overridden_hostname case env when "production", "staging" "https" else "http" end end
to_s()
click to toggle source
# File lib/pco/url.rb, line 122 def to_s uri.to_s end
uri()
click to toggle source
# File lib/pco/url.rb, line 116 def uri q = query ? "?#{query}" : nil url_string = "#{scheme}://#{hostname}/#{path}#{q}".sub(%r{(/)+$}, "") URI(url_string) end
Private Instance Methods
env()
click to toggle source
# File lib/pco/url.rb, line 128 def env ENV["DEPLOY_ENV"] || Rails.env end
env_overridden_hostname()
click to toggle source
# File lib/pco/url.rb, line 132 def env_overridden_hostname env_var = app_name.to_s.upcase + "_URL" ENV[env_var] end