Sha256: c6e0a50298b47bb094fd4b5b80d47b47765a5821fa80f3eb0b77ebd1862f2389

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'net/http'
require 'uri'
require 'multi_json'
require 'instapusher'

module Instapusher
  class Commands
    DEFAULT_HOSTNAME = 'instapusher.com'

    def self.deploy(project_name=nil, branch_name=nil)

      hostname = ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
      hostname = "localhost:3000" if ENV['LOCAL']

      url          = "http://#{hostname}/heroku.json"
      git          = Git.new
      branch_name  ||= git.current_branch
      project_name ||= git.project_name

      api_key = Instapusher::Configuration.api_key || ""
      if api_key.to_s.length == 0
        puts "Please enter instapusher api_key at ~/.instapusher "
      end

      options = { project: project_name,
                  branch:  branch_name,
                  local:   ENV['LOCAL'],
                  api_key: api_key }

      response = Net::HTTP.post_form URI.parse(url), options
      response_body  = MultiJson.load(response.body)
      job_status_url = response_body['status'] || response_body['job_status_url']

      if job_status_url && job_status_url != ""
        puts 'The appliction will be deployed to: ' + response_body['heroku_url']
        puts 'Monitor the job status at: ' + job_status_url
        cmd = "open #{job_status_url}"
        `#{cmd}`
      else
        puts response_body['error']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instapusher-0.0.7 lib/instapusher/commands.rb