Class: BranchIOCLI::Helper::BranchHelper

Inherits:
Object
  • Object
show all
Extended by:
AndroidHelper, IOSHelper
Defined in:
lib/branch_io_cli/helper/branch_helper.rb

Constant Summary

Constants included from IOSHelper

IOSHelper::APPLINKS, IOSHelper::ASSOCIATED_DOMAINS, IOSHelper::CODE_SIGN_ENTITLEMENTS, IOSHelper::DEVELOPMENT_TEAM, IOSHelper::PRODUCT_BUNDLE_IDENTIFIER, IOSHelper::RELEASE_CONFIGURATION

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from IOSHelper

add_branch_universal_link_domains_to_info_plist, add_custom_build_setting, add_keys_to_info_plist, add_universal_links_to_project, app_ids_from_aasa_file, config, contents_of_aasa_file, domains_from_project, ensure_uri_scheme_in_info_plist, has_multiple_info_plists?, report_app_id_mismatch, reportable_app_id, target_from_project, team_and_bundle_from_app_id, update_info_plist_setting, update_team_and_bundle_ids, update_team_and_bundle_ids_from_aasa_file, uses_test_key?, validate_project_domains, validate_team_and_bundle_ids, validate_team_and_bundle_ids_from_aasa_files

Methods included from Methods

#clear, #confirm, #sh

Methods included from AndroidHelper

add_intent_filter_to_activity, add_intent_filters_to_android_manifest, add_keys_to_android_manifest, add_metadata_to_manifest, app_link_data_elements, find_activity, remove_existing_domains, uri_scheme_data_element

Class Attribute Details

.changesObject

An array of file paths (Strings) that were modified



10
11
12
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 10

def changes
  @changes
end

.errorsObject

An array of error messages (Strings) from validation



11
12
13
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 11

def errors
  @errors
end

Class Method Details

.add_change(change) ⇒ Object



16
17
18
19
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 16

def add_change(change)
  @changes ||= Set.new
  @changes << change.to_s
end

.download(url, dest) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 34

def download(url, dest)
  uri = URI(url)

  Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
    request = Net::HTTP::Get.new uri

    http.request request do |response|
      case response
      when Net::HTTPSuccess
        bytes_downloaded = 0
        dots_reported = 0
        # report a dot every 100 kB
        per_dot = 102_400

        File.open dest, 'w' do |io|
          response.read_body do |chunk|
            io.write chunk

            # print progress
            bytes_downloaded += chunk.length
            while (bytes_downloaded - per_dot * dots_reported) >= per_dot
              print "."
              dots_reported += 1
            end
            STDOUT.flush
          end
        end
        say "\n"
      when Net::HTTPRedirection
        download response['location'], dest
      else
        raise "Error downloading #{url}: #{response.code} #{response.message}"
      end
    end
  end
end

.fetch(url) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 21

def fetch(url)
  response = Net::HTTP.get_response URI(url)

  case response
  when Net::HTTPSuccess
    response.body
  when Net::HTTPRedirection
    fetch response['location']
  else
    raise "Error fetching #{url}: #{response.code} #{response.message}"
  end
end