Class: LinkIO::Configuration
- Inherits:
-
Object
- Object
- LinkIO::Configuration
- Defined in:
- lib/linkio/configuration.rb
Overview
Configuration for a Client.
Two ways to configure app targets:
-
Single app (flat, Node.js-compatible) — set the iOS/Android attributes directly and they apply to one default target:
config.ios_app_id = "123" config.android_package_name = "com.example.app" -
Multiple apps keyed by a routing value (e.g. a "role") — register a target per role. The deep link's
role_paramselects which one to open:config.role_param = "role" # query/path param used to route (default) config.default_role = "user" # used when the param is missing/unknown config.app "user" do |app| app.ios_app_id = "111" # ... end config.app "vendor" do |app| app.ios_app_id = "222" # ... end
Constant Summary collapse
- DEFAULT_FALLBACK_TIMEOUT =
ms to wait in the smart-redirect page before falling back.
2500- DEFAULT_APP_KEY =
Key of the implicit target used by the flat single-app API.
"default"- DEFAULT_ROLE_PARAM =
Default name of the query/path param used to select an app target.
"role"- FLAT_ATTRIBUTES =
Attributes proxied to the implicit default AppTarget for single-app use.
%i[ ios_app_id ios_team_id ios_bundle_id ios_app_scheme android_package_name android_app_scheme android_sha256_fingerprints fallback_url ].freeze
Instance Attribute Summary collapse
-
#apps ⇒ Object
readonly
Returns the value of attribute apps.
-
#default_deep_link_path ⇒ Object
Returns the value of attribute default_deep_link_path.
-
#default_role ⇒ Object
Returns the value of attribute default_role.
-
#domain ⇒ Object
Returns the value of attribute domain.
- #fallback_timeout ⇒ Integer
-
#role_param ⇒ String
The routing param name (never blank).
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
-
#app(key, attributes = {}) {|target| ... } ⇒ AppTarget
Register or update an app target for a routing key (role).
-
#app_for(role) ⇒ AppTarget?
Resolve the app target for a routing value, falling back to the configured default role, then the implicit default target, then the first registered target.
-
#default_app ⇒ AppTarget
The implicit target backing the flat single-app API.
-
#initialize(attributes = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ self
Constructor Details
#initialize(attributes = {}) ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/linkio/configuration.rb', line 48 def initialize(attributes = {}) @apps = {} @fallback_timeout = DEFAULT_FALLBACK_TIMEOUT @role_param = DEFAULT_ROLE_PARAM @default_role = nil attributes.each do |name, value| setter = "#{name}=" public_send(setter, value) if respond_to?(setter) end end |
Instance Attribute Details
#apps ⇒ Object (readonly)
Returns the value of attribute apps.
45 46 47 |
# File 'lib/linkio/configuration.rb', line 45 def apps @apps end |
#default_deep_link_path ⇒ Object
Returns the value of attribute default_deep_link_path.
43 44 45 |
# File 'lib/linkio/configuration.rb', line 43 def default_deep_link_path @default_deep_link_path end |
#default_role ⇒ Object
Returns the value of attribute default_role.
43 44 45 |
# File 'lib/linkio/configuration.rb', line 43 def default_role @default_role end |
#domain ⇒ Object
Returns the value of attribute domain.
43 44 45 |
# File 'lib/linkio/configuration.rb', line 43 def domain @domain end |
#fallback_timeout ⇒ Integer
72 73 74 |
# File 'lib/linkio/configuration.rb', line 72 def fallback_timeout @fallback_timeout || DEFAULT_FALLBACK_TIMEOUT end |
#role_param ⇒ String
Returns the routing param name (never blank).
66 67 68 69 |
# File 'lib/linkio/configuration.rb', line 66 def role_param value = @role_param.to_s value.empty? ? DEFAULT_ROLE_PARAM : value end |
#storage ⇒ Object
Returns the value of attribute storage.
43 44 45 |
# File 'lib/linkio/configuration.rb', line 43 def storage @storage end |
Instance Method Details
#app(key, attributes = {}) {|target| ... } ⇒ AppTarget
Register or update an app target for a routing key (role).
config.app("vendor") { |app| app.ios_app_id = "222" }
config.app(:user, ios_app_id: "111")
85 86 87 88 89 90 91 92 93 |
# File 'lib/linkio/configuration.rb', line 85 def app(key, attributes = {}) target = (@apps[key.to_s] ||= AppTarget.new(key)) attributes.each do |name, value| setter = "#{name}=" target.public_send(setter, value) if target.respond_to?(setter) end yield target if block_given? target end |
#app_for(role) ⇒ AppTarget?
Resolve the app target for a routing value, falling back to the configured default role, then the implicit default target, then the first registered target.
108 109 110 111 112 113 |
# File 'lib/linkio/configuration.rb', line 108 def app_for(role) key = role.to_s return @apps[key] if !key.empty? && @apps.key?(key) default_target end |
#default_app ⇒ AppTarget
The implicit target backing the flat single-app API.
98 99 100 |
# File 'lib/linkio/configuration.rb', line 98 def default_app @apps[DEFAULT_APP_KEY] ||= AppTarget.new(DEFAULT_APP_KEY) end |
#validate! ⇒ self
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/linkio/configuration.rb', line 117 def validate! raise ConfigurationError, "LinkIO configuration requires a domain" if blank?(domain) raise ConfigurationError, "LinkIO configuration requires storage" if storage.nil? unless storage.respond_to?(:save_pending_link) raise ConfigurationError, "storage must implement the LinkIO::Storage::Base interface" end raise ConfigurationError, "at least one app target must be configured" if apps.empty? apps.each_value { |target| validate_target!(target) } self end |