Class: API

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

Instance Method Summary collapse

Constructor Details

#initialize(shell, config, networking, options) ⇒ API

Returns a new instance of API.



2
3
4
5
6
7
8
# File 'lib/api.rb', line 2

def initialize(shell, config, networking, options)
  @shell = shell
  @config = config
  @networking = networking
  @options = options
  @unpack_mutex = Mutex.new
end

Instance Method Details

#create_and_upload_archive(carthage_dependency, framework, platform) ⇒ Object

Returns zip archive size in Bytes.

Returns:

  • zip archive size in Bytes



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/api.rb', line 50

def create_and_upload_archive(carthage_dependency, framework, platform)
  archive = framework.make_archive(platform)
  archive.compress_archive(@shell)
  archive_size = archive.archive_size
  begin
    checksum = crc32(archive.archive_path)
    @networking.upload_framework_archive(archive.archive_path, carthage_dependency, framework.name, platform, checksum)
  ensure
    archive.delete_archive
  end
  archive_size
end

#download_and_unpack_archive(carthage_dependency, framework, platform) ⇒ Object

Returns zip archive size in Bytes.

Returns:

  • zip archive size in Bytes

Raises:

  • AppError if download or checksum validation fails



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/api.rb', line 65

def download_and_unpack_archive(carthage_dependency, framework, platform)
  result = @networking.download_framework_archive(carthage_dependency, framework, platform)
  if result.nil?
    raise AppError.new, "Failed to download framework #{carthage_dependency}#{framework.name} (#{platform}). Please `upload` the framework first."
  end

  archive = result[:archive]
  remote_checksum = result[:checksum]
  local_checksum = crc32(archive.archive_path)

  if local_checksum != remote_checksum
    raise AppError.new, checksum_error_message(archive.archive_path, remote_checksum, local_checksum)
  end

  archive_size = archive.archive_size
  begin
    $LOG.debug("Downloaded #{archive.archive_path}")
    # Can't unpack multiple archives concurrently.
    @unpack_mutex.synchronize do
      archive.unpack_archive(@shell)
    end
  ensure
    archive.delete_archive
  end
  archive_size
end

#verify_build_dir_matches_cartfile_resolvedObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/api.rb', line 17

def verify_build_dir_matches_cartfile_resolved
  errors = []
  for carthage_dependency in @config.carthage_resolved_dependencies
    begin
      version_file = carthage_dependency.new_version_file
      carthage_dependency.verify_version_in_version_file(version_file)
    rescue VersionFileDoesNotExistError => e
      errors << OutdatedFrameworkBuildError.new(
        carthage_dependency.guessed_framework_basename,
        "-",
        carthage_dependency.version
      )
    rescue OutdatedFrameworkBuildError => e
      errors << e
    end
  end
  if errors.count > 0
    raise FrameworkValidationError.new(errors)
  end
end

#verify_server_versionObject



10
11
12
13
14
15
# File 'lib/api.rb', line 10

def verify_server_version
  server_version = @networking.get_server_version
  unless server_version == VERSION
    raise ServerVersionMismatchError.new, version_mismatch_message(server_version)
  end
end

#version_file_matches_server?(carthage_dependency, version_file, platforms) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
# File 'lib/api.rb', line 38

def version_file_matches_server?(carthage_dependency, version_file, platforms)
  if @options[:force]
    false
  else
    server_version_file = @networking.download_version_file(carthage_dependency, platforms)
    result = version_file.same_content?(server_version_file)
    server_version_file.remove unless server_version_file.nil?
    result
  end
end