Class: Fastly::User

Inherits:
Base
  • Object
show all
Defined in:
lib/fastly/user.rb

Overview

A representation of a User in Fastly

Constant Summary collapse

PRIORITIES =

:nodoc:

{
  :admin      => 1,
  :owner      => 10,
  :superuser  => 10,
  :user       => 20,
  :engineer   => 30,
  :billing    => 30
}

Instance Attribute Summary collapse

Attributes inherited from Base

#fetcher

Instance Method Summary collapse

Methods inherited from Base

#as_hash, #delete!, delete_path, get_path, #initialize, list_path, path, post_path, put_path, #require_api_key!, #save!

Constructor Details

This class inherits a constructor from Fastly::Base

Instance Attribute Details

#customer_idObject

Returns the value of attribute customer_id.



4
5
6
# File 'lib/fastly/user.rb', line 4

def customer_id
  @customer_id
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/fastly/user.rb', line 4

def id
  @id
end

#loginObject

Returns the value of attribute login.



4
5
6
# File 'lib/fastly/user.rb', line 4

def 
  @login
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/fastly/user.rb', line 4

def name
  @name
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/fastly/user.rb', line 4

def password
  @password
end

#roleObject

Returns the value of attribute role.



4
5
6
# File 'lib/fastly/user.rb', line 4

def role
  @role
end

Instance Method Details

#can_do?(test_role) ⇒ Boolean

Does this User have sufficient permissions to perform the given role

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
# File 'lib/fastly/user.rb', line 49

def can_do?(test_role)
  test_priority = PRIORITIES[test_role.to_sym] || 1000
  my_priority = PRIORITIES[role.to_sym] || 1000

  if test_priority == my_priority
    test_role.to_s == :owner ? owner? : test_role.to_sym == role.to_sym
  else
    my_priority < test_priority
  end
end

#customerObject

Get the Customer object this user belongs to



29
30
31
# File 'lib/fastly/user.rb', line 29

def customer
  @customer ||= fetcher.get(Customer, customer_id)
end

#owner?Boolean

Whether or not this User is the owner of the Customer they belong to

Returns:

  • (Boolean)


34
35
36
# File 'lib/fastly/user.rb', line 34

def owner?
  customer.owner_id == id
end