Class: Networking

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

Instance Method Summary collapse

Constructor Details

#initialize(config, is_retry_enabled) ⇒ Networking

Returns a new instance of Networking.



5
6
7
8
# File 'lib/networking.rb', line 5

def initialize(config, is_retry_enabled)
  @config = config
  @is_retry_enabled = is_retry_enabled
end

Instance Method Details

#download_framework_archive(carthage_dependency, framework, platform) ⇒ Object

Returns Hash with CarthageArchive and checksum or nil.

Returns:

  • Hash with CarthageArchive and checksum or nil



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/networking.rb', line 67

def download_framework_archive(carthage_dependency, framework, platform)
  url = new_framework_url(carthage_dependency, framework.name, platform)
  archive = perform_network_request do
    $LOG.debug("Downloading framework from #{url}")
    RestClient.get(url) do |response, request, result|
      if response.code == 200
        archive = framework.make_archive(platform)
        File.write(archive.archive_path, response.to_s)
        { :archive => archive, :checksum => response.headers[ARCHIVE_CHECKSUM_HEADER_REST_CLIENT] }
      else
        nil
      end
    end
  end
  archive
end

#download_version_file(carthage_dependency, platforms) ⇒ Object

Returns VersionFile or nil.

Returns:

  • VersionFile or nil



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/networking.rb', line 30

def download_version_file(carthage_dependency, platforms)
  url = new_version_file_url(carthage_dependency)
  params = {}
  unless platforms.nil?
    params[:platform] = platforms.map(&:to_s).join(",")
  end

  version_file = perform_network_request do
    $LOG.debug("Downloading version file from #{url}, params: #{params}")
    RestClient.get(url, { params: params }) do |response, request, result|
      if response.code == 200
        File.write(carthage_dependency.version_filename, response.to_s)
        VersionFile.new(carthage_dependency.version_filename)
      else
        nil
      end
    end
  end
  version_file
end

#get_server_versionObject

Version



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/networking.rb', line 12

def get_server_version
  url = new_version_url
  $LOG.debug("Fetching server version from #{url}")
  server_version = perform_network_request do
    RestClient.get(url) do |response, request, result|
      if response.code == 200
        response.strip
      else
        raise AppError.new, "Failed to read server version from #{url}, response:\n  #{response[0...300]}"
      end
    end
  end
  server_version
end

#upload_framework_archive(zipfile_name, carthage_dependency, framework_name, platform, checksum) ⇒ Object

Raises:

  • AppError when upload fails



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/networking.rb', line 85

def upload_framework_archive(zipfile_name, carthage_dependency, framework_name, platform, checksum)
  url = new_framework_url(carthage_dependency, framework_name, platform)
  params = { :framework_file => File.new(zipfile_name) }
  headers = { ARCHIVE_CHECKSUM_HEADER_REST_CLIENT => checksum }
  perform_network_request do
    $LOG.debug("Uploading framework to #{url}, headers: #{headers}")
    RestClient.post(url, params, headers) do |response, request, result|
      unless response.code == 200
        raise AppError.new, "Framework upload #{zipfile_name} failed, response:\n  #{response[0..300]}"
      end
    end
  end
end

#upload_version_file(carthage_dependency) ⇒ Object

Raises:

  • AppError on upload failure



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/networking.rb', line 52

def upload_version_file(carthage_dependency)
  url = new_version_file_url(carthage_dependency)
  perform_network_request do
    $LOG.debug("Uploading #{carthage_dependency.version_filename}")
    RestClient.post(url, :version_file => File.new(carthage_dependency.version_filepath)) do |response, request, result|
      unless response.code == 200
        raise AppError.new, "Version file upload #{carthage_dependency.version_filename} failed, response:\n  #{response[0..300]}"
      end
    end
  end
end