Sha256: 1d25f4da963cc7a665f4bc9369ad64fc128ffeb07824c4351ab02602fafe6fac

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'rubygems'
require 'json'

module Relish
  module Command
    class Projects < Base
      
      def default; list end
      
      def list
        response = resource['projects'].get(
          :params => {:api_token => api_token}, :accept => :json
        )
        puts format(response)
      rescue RestClient::Exception => exception
        warn exception.response
        exit exception.http_code
      end
      
      def add
        puts resource['projects'].post(:handle => @param)
      rescue RestClient::Exception => exception
        warn exception.response
        exit 1
      end
      
      def remove
        puts resource["projects/#{@param}"].delete
      rescue RestClient::Exception => exception
        warn exception.response
        exit 1
      end
      
    private
      def format(response)
        json = JSON.parse(response)
        json.map do |hash| 
          result = hash['project']['full_handle']
          result << " (private)" if hash['project']['private']
          result
        end.join("\n")
      end
            
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relish-0.0.8 lib/relish/commands/projects.rb