Sha256: 6bc12f2910639d072b8d95f92ff7c8f464331c1b4652ebaec006bef9eddea53b

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'yaml'
require 'thor'
require 'pp'

module Akamai
  class Command < Thor

    include Thor::Actions

    desc "purge URLS", "purge urls from Akamai"
    option :debug, :type => :boolean
    def purge(*urls)
      client = Akamai::Connection.new(config)
      client.purge_and_progress(*urls, &printter) 
      puts
    end

    desc "show ID", "show progress of a purge"
    option :debug, :type => :boolean
    def show(id)
      client = Akamai::Connection.new(config)
      client.progress_until_done("/ccu/v2/purges/#{id}", &printter)
      puts
    end

    private

    def config
      begin
        config_path = "#{Dir.home}/.akamai.yml"
        config_file = open(config_path)
        config = YAML.load(config_file)
      rescue
        config = nil
      end

      unless config
        say "Configuration is empty. Please check your '~/.akamai.yml'", :red
        exit -1
      end

      config
    end

    def printter
      Proc.new do |response|
        if options[:debug]
          puts
          pp response
        else
          print "         \r#{response["purgeId"]} => #{response["purgeStatus"]}"
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
akamairb-0.0.2 lib/akamairb/command.rb
akamairb-0.0.1 lib/akamairb/command.rb