Class: BranchIOCLI::BranchApp

Inherits:
Object
  • Object
show all
Defined in:
lib/branch_io_cli/branch_app.rb

Constant Summary collapse

API_ENDPOINT =
"https://api.branch.io/v1/app-link-settings/"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ BranchApp

Returns a new instance of BranchApp.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/branch_io_cli/branch_app.rb', line 32

def initialize(key)
  @key = key

  spinner = TTY::Spinner.new "[:spinner] Fetching configuration from Branch Dashboard for #{key}.", format: :flip
  spinner.auto_spin

  begin
    @hash = JSON.parse(Helper::BranchHelper.fetch("#{API_ENDPOINT}#{key}", spin: false)).symbolize_keys.merge key: key
    spinner.success
    @valid = true
  rescue StandardError => e
    spinner.error
    say e.message
    @valid = false
    return
  end

  @alternate_short_url_domain = @hash[:alternate_short_url_domain]
  @android_package_name = @hash[:android_package_name]
  @android_uri_scheme = @hash[:android_uri_scheme]
  @default_short_url_domain = @hash[:default_short_url_domain]
  @ios_bundle_id = @hash[:ios_bundle_id]
  @ios_team_id = @hash[:ios_team_id]
  @ios_uri_scheme = @hash[:ios_uri_scheme]
  @short_url_domain = @hash[:short_url_domain]
end

Instance Attribute Details

#alternate_short_url_domainObject (readonly)

Returns the value of attribute alternate_short_url_domain.



23
24
25
# File 'lib/branch_io_cli/branch_app.rb', line 23

def alternate_short_url_domain
  @alternate_short_url_domain
end

#android_package_nameObject (readonly)

Returns the value of attribute android_package_name.



24
25
26
# File 'lib/branch_io_cli/branch_app.rb', line 24

def android_package_name
  @android_package_name
end

#android_uri_schemeObject (readonly)

Returns the value of attribute android_uri_scheme.



25
26
27
# File 'lib/branch_io_cli/branch_app.rb', line 25

def android_uri_scheme
  @android_uri_scheme
end

#default_short_url_domainObject (readonly)

Returns the value of attribute default_short_url_domain.



26
27
28
# File 'lib/branch_io_cli/branch_app.rb', line 26

def default_short_url_domain
  @default_short_url_domain
end

#ios_bundle_idObject (readonly)

Returns the value of attribute ios_bundle_id.



27
28
29
# File 'lib/branch_io_cli/branch_app.rb', line 27

def ios_bundle_id
  @ios_bundle_id
end

#ios_team_idObject (readonly)

Returns the value of attribute ios_team_id.



28
29
30
# File 'lib/branch_io_cli/branch_app.rb', line 28

def ios_team_id
  @ios_team_id
end

#ios_uri_schemeObject (readonly)

Returns the value of attribute ios_uri_scheme.



29
30
31
# File 'lib/branch_io_cli/branch_app.rb', line 29

def ios_uri_scheme
  @ios_uri_scheme
end

#keyObject (readonly)

Returns the value of attribute key.



22
23
24
# File 'lib/branch_io_cli/branch_app.rb', line 22

def key
  @key
end

#short_url_domainObject (readonly)

Returns the value of attribute short_url_domain.



30
31
32
# File 'lib/branch_io_cli/branch_app.rb', line 30

def short_url_domain
  @short_url_domain
end

Class Method Details

.[](key) ⇒ Object



9
10
11
# File 'lib/branch_io_cli/branch_app.rb', line 9

def [](key)
  fetch key
end

.fetch(key, cache: true) ⇒ Object



13
14
15
16
17
# File 'lib/branch_io_cli/branch_app.rb', line 13

def fetch(key, cache: true)
  @apps ||= {}
  @apps[key] = new(key) unless cache && @apps[key]
  @apps[key]
end

Instance Method Details

#domainsObject



63
64
65
# File 'lib/branch_io_cli/branch_app.rb', line 63

def domains
  [alternate_short_url_domain, default_short_url_domain, short_url_domain].compact.uniq
end

#inspectObject



79
80
81
# File 'lib/branch_io_cli/branch_app.rb', line 79

def inspect
  "#<BranchIOCLI::BranchApp #{self}>"
end

#to_hashObject



67
68
69
# File 'lib/branch_io_cli/branch_app.rb', line 67

def to_hash
  @hash
end

#to_sObject



71
72
73
74
75
76
77
# File 'lib/branch_io_cli/branch_app.rb', line 71

def to_s
  # Changes
  # {:key1=>"value1", :key2=>"value2"}
  # to
  # key1="value1" key2="value2"
  @hash.to_s.sub(/^\{\:/, '').sub(/\}$/, '').gsub(/, \:/, ' ').gsub(/\=\>/, '=')
end

#valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/branch_io_cli/branch_app.rb', line 59

def valid?
  @valid
end