Class: SFRest::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrest/profile.rb

Overview

Work with installation profiles.

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Profile

Returns a new instance of Profile.

Parameters:



7
8
9
# File 'lib/sfrest/profile.rb', line 7

def initialize(conn)
  @conn = conn
end

Instance Method Details

#disable(name, stack_id: nil) ⇒ Object

Disables an installation profile.

Parameters:

  • name (String)
  • stack_id (Integer) (defaults to: nil)

    Required if the factory is multistack.



52
53
54
55
56
# File 'lib/sfrest/profile.rb', line 52

def disable(name, stack_id: nil)
  target_url = "/api/v1/profiles/#{name}/disable"
  target_url += "?stack_id=#{stack_id}" unless stack_id.nil?
  @conn.post(target_url, '{}')
end

#enable(name, stack_id: nil) ⇒ Object

Enables an installation profile.

Parameters:

  • name (String)
  • stack_id (Integer) (defaults to: nil)

    Required if the factory is multistack.



42
43
44
45
46
# File 'lib/sfrest/profile.rb', line 42

def enable(name, stack_id: nil)
  target_url = "/api/v1/profiles/#{name}/enable"
  target_url += "?stack_id=#{stack_id}" unless stack_id.nil?
  @conn.post(target_url, '{}')
end

#profile_list(**params) ⇒ Hash

Gets a list of installation profiles.

}

Parameters:

  • params (Hash)

    Given as URL parameters.

Options Hash (**params):

  • :stack_id (Integer)

    A stack id to filter by.

  • :is_enabled (Boolean)

    True to filter by enabled profiles. False to filter by disabled profiles.

Returns:

  • (Hash)

    Profile info formatted like so: { ‘profiles’ => [

    'name' => 'testing',
    'description' => 'Some description',
    'stack_id' => 1,
    'rest_api_default' => false,
    'enabled' => true
    

    ], ‘count’ => 1, ‘time’ => ‘2021-03-12T02:26:34+00:00’



28
29
30
31
32
33
34
35
36
# File 'lib/sfrest/profile.rb', line 28

def profile_list(**params)
  target_url = '/api/v1/profiles'
  # Generate a string like "stack_id=3&is_enabled=true"
  url_params = params.each.map { |k, v| "#{k}=#{v}" }.join('&')
  target_url += "?#{url_params}" unless url_params.empty?

  # Output is already well-formed, so return it.
  @conn.get(target_url)
end

#set_default(name, stack_id: nil) ⇒ Object

Sets the default installation profile for use with other REST endpoints.

Parameters:

  • name (String)
  • stack_id (Integer) (defaults to: nil)

    Required if the factory is multistack.



62
63
64
65
66
# File 'lib/sfrest/profile.rb', line 62

def set_default(name, stack_id: nil)
  target_url = "/api/v1/profiles/#{name}/set_default"
  target_url += "?stack_id=#{stack_id}" unless stack_id.nil?
  @conn.post(target_url, '{}')
end