Sha256: ca2a766594ee9246ce1860470396b847df484d3fc83f2e0c6b1463d2fb0e6116

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

# coding: utf-8

module Status
  class NotFoundException < Exception
    def initialize
      puts "Not found"
      puts "Make sure #{ENV['HOME']}/.status.conf is set up correctly"
      abort("exit")
    end
  end
end

module Status
  class GithubRequest
    attr_reader :url, :options
    def initialize
      @url = "https://api.github.com"
      @options = {}
    end
  end
end

module Status
  class CiRequest
    attr_reader :url, :options
    def initialize
      @url = Status.ci_url
      @options = {:user => Status.ci_user, :password => Status.ci_password}
    end
  end
end


module Status
  class Request
    attr_reader :conn
    def initialize(type=:github)
      @klass = {:github => GithubRequest, :ci => CiRequest}[type]
      @klass = @klass.new
      @site = RestClient::Resource.new(@klass.url, @klass.options, :headers => { :accept => :json, :content_type => :json })
    end

    def get(path)
      begin
        MultiJson.decode @site[path].get
      rescue
        raise NotFoundException.new
      end
    end

    def post(path, data)
      begin
        MultiJson.decode @site[path].post(MultiJson.encode(data))
      rescue
        raise NotFoundException.new
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
update_status-0.1.3 lib/status/request.rb
update_status-0.1.2 lib/status/request.rb
update_status-0.1.1 lib/status/request.rb