Class: SauceWhisk::Accounts

Inherits:
Object
  • Object
show all
Extended by:
RestRequestBuilder
Defined in:
lib/sauce_whisk/accounts.rb

Class Method Summary collapse

Methods included from RestRequestBuilder

auth_details, delete, fully_qualified_resource, get, make_request, post, put, request_from_rest_client

Class Method Details

.concurrency_for(job_id = ENV["SAUCE_USERNAME"], type = :both) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sauce_whisk/accounts.rb', line 19

def self.concurrency_for(job_id = ENV["SAUCE_USERNAME"], type = :both)
  concurrencies = JSON.parse (get "#{job_id}/limits"), :symbolize_names => true
  case type
    when :mac
      return concurrencies[:mac_concurrency]
    when :total
      return concurrencies[:concurrency]
    else
      return {:mac_concurrency => concurrencies[:mac_concurrency],
              :total_concurrency => concurrencies[:concurrency]
      }
  end
end

.create_subaccount(parent, name, username, email, password) ⇒ Object

TODO what happens if not a valid parent?



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sauce_whisk/accounts.rb', line 34

def self.create_subaccount(parent, name, username, email, password)
  payload = {
    :username => username,
    :password => password,
    :name => name,
    :email => email
  }
  begin
    response = post :resource => "users/#{parent.username}", :payload => payload
  rescue RestClient::BadRequest => e
    decoded_body = JSON.parse e.http_body, :symbolize_names => true
    raise SubAccountCreationError, decoded_body[:errors]
  rescue RestClient::ResourceNotFound => e
    raise InvalidAccountError, "Parent account #{parent.username} does not exist"
  end

  new_subaccount = SubAccount.new parent, JSON.parse(response)
end

.fetch(user_id = ENV["SAUCE_USERNAME"], get_concurrency = true) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/sauce_whisk/accounts.rb', line 9

def self.fetch(user_id = ENV["SAUCE_USERNAME"], get_concurrency = true)
  user_parameters = JSON.parse (get "users/#{user_id}"), :symbolize_names => true
  concurrencies = get_concurrency ? concurrency_for(user_id) : {}

   = user_parameters.merge concurrencies
  return Account.new()
rescue RestClient::ResourceNotFound
  raise InvalidAccountError, "Account #{user_id} does not exist"
end