lib/engineyard/model/deployment.rb in engineyard-1.3.10 vs lib/engineyard/model/deployment.rb in engineyard-1.3.11

- old
+ new

@@ -1,47 +1,58 @@ require 'escape' module EY module Model - class Deployment < ApiStruct.new(:id, :app, :created_at, :environment, :finished_at, :migration_command, :output, :ref, :successful) - def self.started(environment, app, ref, migration_command) - from_hash({ - :app => app, - :environment => environment, - :migration_command => migration_command, - :ref => ref, - :created_at => Time.now.utc, + class Deployment < ApiStruct.new(:id, :app, :created_at, :commit, :environment, :finished_at, :migrate_command, :output, :ref, :resolved_ref, :successful) + def self.started(environment, app, ref, migrate_command) + deployment = from_hash({ + :app => app, + :environment => environment, + :migrate_command => migrate_command, + :ref => ref, }) + deployment.start + deployment end + def start + post_to_api({ + :migrate => !!migrate_command, + :migrate_command => migrate_command, + :output => output, + :ref => ref, + }) + end + def finished(successful, output) self.successful = successful self.output = output - self.finished_at = Time.now.utc - post_to_appcloud! + put_to_api({:successful => successful, :output => output}) end private - def post_to_appcloud! - api.request(api_uri, :method => :post, :params => params) - EY.ui.info "Deployment recorded in AppCloud" + def post_to_api(params) + update_with_response api.request(collection_uri, :method => :post, :params => {:deployment => params}) end - def params - {:deployment => { - :created_at => created_at, - :finished_at => finished_at, - :migrate => !!migration_command, - :migrate_command => migration_command, - :output => output, - :ref => ref, - :successful => successful, - }} + def put_to_api(params) + update_with_response api.request(member_uri("/finished"), :method => :put, :params => {:deployment => params}) end - def api_uri + def update_with_response(response) + data = response['deployment'] + data.each do |key,val| + self[key] = val if members.include?(key) + end + end + + def collection_uri "/apps/#{app.id}/environments/#{environment.id}/deployments" + end + + def member_uri(path = nil) + "/apps/#{app.id}/environments/#{environment.id}/deployments/#{id}#{path}" end def api app.api end