Class: SFRest::Domains

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

Overview

Find Staging envs and stage a set of sites

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Domains

Returns a new instance of Domains.

Parameters:



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

def initialize(conn)
  @conn = conn
end

Instance Method Details

#add(node_id, domain_name) ⇒ Hash

Add a domain

Parameters:

  • node_id (Integer)

    The id of the node to which add a domain

  • domain_name (String)

    domain to add. e.g. www.example.com

Returns:

  • (Hash)

    { “node_type”: “site_collection”, “domain”: “www.example.com”, “added”: true, “messages”: [ “Your domain name was successfully added to the site collection.”] }



60
61
62
63
# File 'lib/sfrest/domains.rb', line 60

def add(node_id, domain_name)
  payload = { 'domain_name' => domain_name }.to_json
  @conn.post("/api/v1/domains/#{node_id}/add", payload)
end

#custom_domains(node_id) ⇒ Array

Get the custom domains on a node

Parameters:

  • node_id (Integer)

    The id of the node.

Returns:

  • (Array)

    custom(removable) domains on a node



40
41
42
# File 'lib/sfrest/domains.rb', line 40

def custom_domains(node_id)
  get(node_id)['domains']['custom_domains']
end

#get(node_id) ⇒ Hash

Get the domains information on a node

Parameters:

  • node_id (Integer)

    The id of the node.

Returns:

  • (Hash)

    { “node_id” => 4966, “node_type” => “site”, “time” => “2016-11-18T20:09:55+00:00”, “domains” => { “protected_domains” =>[ “it252garden4.utest.sfdev.acquia-test.co” ], “custom_domains” => [ “it252coll3.utest.sfdev.acquia-test.co”, “sc1.nikgregory.us” ] } }



18
19
20
21
# File 'lib/sfrest/domains.rb', line 18

def get(node_id)
  current_path = "/api/v1/domains/#{node_id}"
  @conn.get(current_path)
end

#get_all(**opts) ⇒ Hash

Get all domains of all sites known to site factory.

Parameters:

  • opts (Hash)
    • ‘limit’ and ‘page’ are supported for pagination.

Returns:

  • (Hash)

    { “count”: 111, “domains”: [

    {'nid' => 2, 'domain' => 'foobar.com', 'type' => 'simple', 'readonly' => true},
    {'nid' => 6, 'domain' => 'zoofoo.com', 'type' => 'customerStandard', 'readonly' => false}
    

    ]}



31
32
33
34
# File 'lib/sfrest/domains.rb', line 31

def get_all(**opts)
  current_path = "/api/v1/domains?#{URI.encode_www_form(opts)}"
  @conn.get(current_path)
end

#protected_domains(node_id) ⇒ Array

Get the protetect domains on a node

Parameters:

  • node_id (Integer)

    The id of the node.

Returns:

  • (Array)

    protected (non-removable) domains on a node



48
49
50
# File 'lib/sfrest/domains.rb', line 48

def protected_domains(node_id)
  get(node_id)['domains']['protected_domains']
end

#remove(node_id, domain_name) ⇒ Hash

Remove a domain

Parameters:

  • node_id (Integer)

    The id of the node to which remove a domain

  • domain_name (String)

    domain to remove. e.g. www.example.com

Returns:

  • (Hash)

    { “node_type”: “site_collection”, “domain”: “www.example.com”, “removed”: true, “messages”: [ “Your domain name was successfully removed from the site collection.” ] }



73
74
75
76
# File 'lib/sfrest/domains.rb', line 73

def remove(node_id, domain_name)
  payload = { 'domain_name' => domain_name }.to_json
  @conn.post("/api/v1/domains/#{node_id}/remove", payload)
end

#status(domain_name) ⇒ Hash

Get domain status

Parameters:

Returns:

  • (Hash)

    { “message” => “The domain is associated with the node.”, “is_domain_associated” => TRUE, “node_id” => 123, “node_type” => “site”, “time” => “2016-10-28T09:25:26+00:00”, “stack_id” => 1, “domains” => array(

    "protected_domains" => array('site.example.sfdev.acquia-test.co'),
     "custom_domains" => array('www.abc.com/def', 'www.xyz.com'),
    

    ) }



91
92
93
# File 'lib/sfrest/domains.rb', line 91

def status(domain_name)
  @conn.get("/api/v1/domains/status/#{domain_name}")
end