Sha256: 5308c1a2c9d401c16df873d46bbad8ee05a6e56b9592e881445a683fc8831421

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

class Logman
  class BucketAPI < ConsoleBase
    
    get '/api/buckets',:auth=>:user do
      json @user.buckets
    end
    
    get '/api/buckets/:id',:auth=>:user do
      json @user.buckets.find(params[:id])
    end
    
    post '/api/buckets', :auth=> :admin do
      json = JSON.parse(request.body.read) 
      bucket = Bucket.new(json)
      
      if bucket.save
        json bucket
      else
        status 422
        bucket.errors.to_json
      end
    end
    
    put '/api/buckets/:id', :auth=> :admin do
      if params[:generateToken].blank? == false
        bucket = Bucket.find(params[:id])
        bucket.new_token if bucket
        bucket.save
        return json bucket
      end
      
      json = JSON.parse(request.body.read) 
      bucket = Bucket.find(params[:id])
      
      if bucket.update_attributes(json)
        json bucket
      else
        status 422
        bucket.errors.to_json
      end
    end
    
    delete '/api/buckets/:id', :auth=>:admin do
      bucket = Bucket.find(params[:id])
      bucket.destroy if bucket
      status 200
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
logman-0.1.0 lib/console/bucket_api.rb
logman-0.1.0.alpha lib/console/bucket_api.rb