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_carthage, add_cocoapods, add_direct, add_keys_to_info_plist, add_system_frameworks, add_universal_links_to_project, app_ids_from_aasa_file, contents_of_aasa_file, domains_from_project, ensure_uri_scheme_in_info_plist, expanded_build_setting, patch_app_delegate_objc, patch_app_delegate_swift, patch_cartfile, patch_open_url_method_objc, patch_open_url_method_swift, patch_podfile, patch_source, target_from_project, team_and_bundle_from_app_id, update_cartfile, update_info_plist_setting, update_podfile, update_team_and_bundle_ids, update_team_and_bundle_ids_from_aasa_file, validate_project_domains, validate_team_and_bundle_ids, validate_team_and_bundle_ids_from_aasa_files

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



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

def changes
  @changes
end

.errorsObject

An array of error messages (Strings) from validation



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

def errors
  @errors
end

Class Method Details

.add_change(change) ⇒ Object



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

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

.apply_patch(options) ⇒ Object

Shim around PatternPatch for now



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 23

def apply_patch(options)
  modified = File.open(options[:files]) do |file|
    PatternPatch::Utilities.apply_patch file.read,
                                        options[:regexp],
                                        options[:text],
                                        options[:global],
                                        options[:mode],
                                        options[:offset] || 0
  end

  File.open(options[:files], "w") do |file|
    file.write modified
  end
end

.download(url, dest) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 51

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

.ensure_directory(path) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 88

def ensure_directory(path)
  return if path == "/" || path == "."
  parent = File.dirname path
  ensure_directory parent
  return if Dir.exist? path
  Dir.mkdir path
end

.fetch(url) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 38

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