Class: LinkIO::AppTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/linkio/app_target.rb

Overview

A single app target that LinkIO can route to. A configuration may hold many of them, keyed by a routing value (e.g. a "role" such as "user" or "vendor"). Each target carries its own iOS/Android identifiers, schemes, store URLs, and an optional per-role fallback_url.

Constant Summary collapse

REQUIRED =

Fields required for a target to be usable.

%i[ios_app_id ios_team_id ios_bundle_id android_package_name].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, attributes = {}) ⇒ AppTarget

Returns a new instance of AppTarget.

Parameters:

  • key (String, Symbol)

    the routing key (role) for this target

  • attributes (Hash) (defaults to: {})

    optional attributes to assign



24
25
26
27
28
29
30
31
# File 'lib/linkio/app_target.rb', line 24

def initialize(key, attributes = {})
  @key = key.to_s
  @android_sha256_fingerprints = []
  attributes.each do |name, value|
    setter = "#{name}="
    public_send(setter, value) if respond_to?(setter)
  end
end

Instance Attribute Details

#android_app_schemeObject

Returns the value of attribute android_app_scheme.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def android_app_scheme
  @android_app_scheme
end

#android_package_nameObject

Returns the value of attribute android_package_name.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def android_package_name
  @android_package_name
end

#android_sha256_fingerprintsObject

Returns the value of attribute android_sha256_fingerprints.



20
21
22
# File 'lib/linkio/app_target.rb', line 20

def android_sha256_fingerprints
  @android_sha256_fingerprints
end

#fallback_urlObject

Returns the value of attribute fallback_url.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def fallback_url
  @fallback_url
end

#ios_app_idObject

Returns the value of attribute ios_app_id.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def ios_app_id
  @ios_app_id
end

#ios_app_schemeObject

Returns the value of attribute ios_app_scheme.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def ios_app_scheme
  @ios_app_scheme
end

#ios_bundle_idObject

Returns the value of attribute ios_bundle_id.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def ios_bundle_id
  @ios_bundle_id
end

#ios_team_idObject

Returns the value of attribute ios_team_id.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def ios_team_id
  @ios_team_id
end

#keyObject

Returns the value of attribute key.



12
13
14
# File 'lib/linkio/app_target.rb', line 12

def key
  @key
end

Instance Method Details

#android_store_urlString

Returns the Google Play URL for this target.

Returns:

  • (String)

    the Google Play URL for this target



43
44
45
# File 'lib/linkio/app_target.rb', line 43

def android_store_url
  "https://play.google.com/store/apps/details?id=#{android_package_name}"
end

#apple_app_idString

Returns the AASA appID, ".".

Returns:

  • (String)

    the AASA appID, "."



64
65
66
# File 'lib/linkio/app_target.rb', line 64

def apple_app_id
  "#{ios_team_id}.#{ios_bundle_id}"
end

#ios_store_urlString

Returns the iOS App Store URL for this target.

Returns:

  • (String)

    the iOS App Store URL for this target



38
39
40
# File 'lib/linkio/app_target.rb', line 38

def ios_store_url
  "https://apps.apple.com/app/id#{ios_app_id}"
end

#missing_fieldsArray<Symbol>

Returns required fields that are missing.

Returns:

  • (Array<Symbol>)

    required fields that are missing



69
70
71
# File 'lib/linkio/app_target.rb', line 69

def missing_fields
  REQUIRED.select { |field| blank?(public_send(field)) }
end

#scheme_for(platform) ⇒ String?

The custom URL scheme for the given platform, if any.

Parameters:

  • platform (String)

Returns:

  • (String, nil)


59
60
61
# File 'lib/linkio/app_target.rb', line 59

def scheme_for(platform)
  platform == Platform::ANDROID ? android_app_scheme : ios_app_scheme
end

#store_url(platform) ⇒ String

The store URL appropriate for the given platform.

Parameters:

  • platform (String)

    a Platform value

Returns:

  • (String)


51
52
53
# File 'lib/linkio/app_target.rb', line 51

def store_url(platform)
  platform == Platform::ANDROID ? android_store_url : ios_store_url
end