Class: BranchIOCLI::Helper::BranchHelper
- Inherits:
-
Object
- Object
- BranchIOCLI::Helper::BranchHelper
- 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
-
.changes ⇒ Object
An array of file paths (Strings) that were modified.
-
.errors ⇒ Object
An array of error messages (Strings) from validation.
Class Method Summary collapse
- .add_change(change) ⇒ Object
- .domains(apps) ⇒ Object
- .download(url, dest, size: nil) ⇒ Object
- .fetch(url, spin: true) ⇒ Object
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, branch_apps_from_project, branch_keys_from_project, config, contents_of_aasa_file, domains_from_project, ensure_uri_scheme_in_info_plist, has_multiple_info_plists?, info_plist, info_plist_path, project_valid?, report_app_id_mismatch, reportable_app_id, reset_aasa_cache, 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, uri_schemes_from_project, uses_test_key?, validate_project_domains, validate_team_and_bundle_ids, validate_team_and_bundle_ids_from_aasa_files
Methods included from Methods
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
.changes ⇒ Object
An array of file paths (Strings) that were modified
14 15 16 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 14 def changes @changes end |
.errors ⇒ Object
An array of error messages (Strings) from validation
15 16 17 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 15 def errors @errors end |
Class Method Details
.add_change(change) ⇒ Object
20 21 22 23 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 20 def add_change(change) @changes ||= Set.new @changes << change.to_s end |
.domains(apps) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 83 def domains(apps) apps.inject Set.new do |result, k, v| next result unless v result + v.domains end end |
.download(url, dest, size: nil) ⇒ Object
47 48 49 50 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 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 47 def download(url, dest, size: nil) 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 if size pastel = Pastel.new green = pastel.on_green " " yellow = pastel.on_yellow " " progress = TTY::ProgressBar.new "[:bar] :percent (:eta)", total: 50, complete: green, incomplete: yellow end File.open dest, 'w' do |io| response.read_body do |chunk| io.write chunk # print progress bytes_downloaded += chunk.length progress.ratio = bytes_downloaded.to_f / size.to_f if size end end progress.finish if size when Net::HTTPRedirection download response['location'], dest, size: size else raise "Error downloading #{url}: #{response.code} #{response.}" end end end end |
.fetch(url, spin: true) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/branch_io_cli/helper/branch_helper.rb', line 25 def fetch(url, spin: true) if spin @spinner = TTY::Spinner.new "[:spinner] GET #{url}.", format: :flip @spinner.auto_spin end response = Net::HTTP.get_response URI(url) case response when Net::HTTPSuccess @spinner.success "#{response.code} #{response.}" if @spinner @spinner = nil response.body when Net::HTTPRedirection fetch response['location'], spin: false else @spinner.error "#{response.code} #{response.}" if @spinner @spinner = nil raise "Error fetching #{url}: #{response.code} #{response.}" end end |