Sha256: c01dbe593f120312ff2a34b5843c28647c508ce66dc6c4b37c08b7df909f2884

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module Squall
  # OnApp Role
  class Role < Base
    # Return a list of Roles
    def list
      response = request(:get, '/roles.json')
      response.collect { |role| role['role']}
    end

    # Returns a Hash of the given Role
    def show(id)
      response = request(:get, "/roles/#{id}.json")
      response.first[1]
    end

    # Edit a Role
    #
    # ==== Options
    #
    # * +options+ - Params for editing the Role
    # ==== Example
    #
    #   edit :label => 'myrole', :permission => [1,3]
    #   edit :label => 'myrole', :permission => 1
    def edit(id, options = {})
      params.accepts(:label, :permission).validate!(options)
      response = request(:put, "/roles/#{id}.json", default_params(options))
    end

    # Delete a Role
    def delete(id)
      request(:delete, "/roles/#{id}.json")
    end

    # Returns a list of permissions available
    def permissions
      response = request(:get, '/permissions.json')
      response.collect { |perm| perm['permission'] }
    end

    # Create a new Role
    #
    # ==== Options
    #
    # * +options+ - Params for creating the Role
    #
    # ==== Example
    #
    #   create :label => 'mypriv', :identifier => 'magic'
    def create(options = {})
      params.required(:label, :identifier).validate!(options)
      response = request(:post, '/roles.json', default_params(options))
      response.first[1]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
squall-1.0.2 lib/squall/role.rb
squall-1.0.1 lib/squall/role.rb
squall-1.0.0 lib/squall/role.rb