Class: PhoneGap::Build::App

Inherits:
RestResource show all
Defined in:
lib/phone_gap/build/app.rb

Constant Summary collapse

PATH =
'/apps'

Instance Attribute Summary collapse

Attributes inherited from RestResource

#errors, #id, #poll_interval, #poll_time_limit

Instance Method Summary collapse

Methods inherited from RestResource

#as_json, #create, #destroy, #initialize, #save, #update

Methods included from Creatable

#creatable_attributes, included, #updatable_attributes

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PhoneGap::Build::RestResource

Instance Attribute Details

#create_methodObject

Returns the value of attribute create_method.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def create_method
  @create_method
end

#debugObject

Returns the value of attribute debug.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def debug
  @debug
end

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def description
  @description
end

#fileObject

Returns the value of attribute file.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def file
  @file
end

#hydratesObject

Returns the value of attribute hydrates.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def hydrates
  @hydrates
end

#keysObject

Returns the value of attribute keys.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def keys
  @keys
end

#packageObject

Returns the value of attribute package.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def package
  @package
end

#phonegap_versionObject

Returns the value of attribute phonegap_version.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def phonegap_version
  @phonegap_version
end

#privateObject

Returns the value of attribute private.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def private
  @private
end

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def status
  @status
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def title
  @title
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/phone_gap/build/app.rb', line 10

def version
  @version
end

Instance Method Details

#buildObject



27
28
29
# File 'lib/phone_gap/build/app.rb', line 27

def build
  ApiRequest.new.post("#{PATH}/#{id}/build")
end

#build_complete?(params = {}) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/phone_gap/build/app.rb', line 32

def build_complete?(params = {})
  complete = false
  error = false
  start_time = Time.now
  time_limit = start_time + (params[:poll_time_limit] || poll_time_limit)
  while !complete && (Time.now < time_limit) && !error
    response = ApiRequest.new.get("#{PATH}/#{id}")
    if response.success?
      json_object = JSON.parse(response.body)
      complete = json_object['status'].all? { |platform, status| %w(complete skip).include?(status) }
      error = json_object['status'].any? { |platform, status| status == 'error' }
    end
    sleep (params[:poll_interval] || poll_interval) unless complete or error
  end
  raise BuildError.new('An error occurred building at least one of the apps.') if error
  raise BuildError.new('Builds did not complete within the allotted time.') if !error && !complete
  populate_from_json(json_object)
  complete
end

#download(params = {}) ⇒ Object



52
53
54
55
56
57
# File 'lib/phone_gap/build/app.rb', line 52

def download(params = {})
  platforms_to_download = params[:platforms] ? params[:platforms] : built_platforms
  platforms_to_download.each do |platform|
    PhoneGap::Build::PackageDownloader.new.download(id, platform, params[:save_to])
  end
end

#post_optionsObject



17
18
19
20
21
22
23
24
25
# File 'lib/phone_gap/build/app.rb', line 17

def post_options
  if file
    data_attributes = creatable_attributes
    data_attributes.delete('@file')
    {query: {file: file, data: as_json(only: data_attributes, remove_nils: true)}, detect_mime_type: true}
  else
    {query: {data: as_json(only: creatable_attributes, remove_nils: true)}}
  end
end