Class: SFRest::Collection
- Inherits:
-
Object
- Object
- SFRest::Collection
- Defined in:
- lib/sfrest/collection.rb
Overview
Find colletions, return their data.
Instance Method Summary collapse
-
#add_sites(id, sites) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "site_ids_added" => Array, "added" => Boolean, "message" => String }
adds site(s) to a site collection.
-
#collection_data_from_results(res, name, key) ⇒ Object
Extract the site data for ‘key’ based on the site result object.
-
#collection_list ⇒ Hash{'count' => Integer, 'sites' => Hash}
Gets the complete list of collections Makes multiple requests to the factory to get all the collections on the factory.
-
#create(name, sites, groups, internal_domain_prefix = nil) ⇒ Hash { "id" => Integer, "name" => String, "time" => "2016-11-25T13:18:44+00:00", "internal_domain" => String }
create a site collection.
-
#delete(id) ⇒ Hash{ "id" => Integer, "time" => "2016-10-28T09:25:26+00:00", "deleted" => Boolean, "message" => String }
deletes a site collection performs the same action as deleting in the UI.
-
#first_collection_id ⇒ Integer
gets the site id of the 1st one found using the api.
-
#get_collection_data(id) ⇒ Hash
Gets the site data for a specific id.
-
#get_collection_id(name) ⇒ Integer
gets the site ID for the site named sitename will page through all the sites available searching for the site.
-
#initialize(conn) ⇒ Collection
constructor
A new instance of Collection.
-
#remove_sites(id, sites) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "site_ids_removed" => Array, "removed" => Boolean, "message" => String }
removes site(s) from a site collection.
-
#set_primary_site(id, site) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "primary_site_id": Integer, "switched" => Boolean, "message" => String }
sets a site to be a primary site in a site collection.
Constructor Details
#initialize(conn) ⇒ Collection
Returns a new instance of Collection.
7 8 9 |
# File 'lib/sfrest/collection.rb', line 7 def initialize(conn) @conn = conn end |
Instance Method Details
#add_sites(id, sites) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "site_ids_added" => Array, "added" => Boolean, "message" => String }
adds site(s) to a site collection
124 125 126 127 128 129 |
# File 'lib/sfrest/collection.rb', line 124 def add_sites(id, sites) sites = Array(sites) payload = { 'site_ids' => sites }.to_json current_path = "/api/v1/collections/#{id}/add" @conn.post(current_path, payload) end |
#collection_data_from_results(res, name, key) ⇒ Object
Extract the site data for ‘key’ based on the site result object
36 37 38 39 40 41 42 |
# File 'lib/sfrest/collection.rb', line 36 def collection_data_from_results(res, name, key) collections = res['collections'] collections.each do |collection| return collection[key] if collection['name'] == name end nil end |
#collection_list ⇒ Hash{'count' => Integer, 'sites' => Hash}
Gets the complete list of collections Makes multiple requests to the factory to get all the collections on the factory
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sfrest/collection.rb', line 61 def collection_list page = 1 not_done = true count = 0 while not_done current_path = '/api/v1/collections?page='.dup << page.to_s res = @conn.get(current_path) if res['collections'] == [] not_done = false elsif !res['message'].nil? return { 'message' => res['message'] } elsif page == 1 count = res['count'] collections = res['collections'] else res['collections'].each do |collection| collections << collection end end page += 1 end { 'count' => count, 'collections' => collections } end |
#create(name, sites, groups, internal_domain_prefix = nil) ⇒ Hash { "id" => Integer, "name" => String, "time" => "2016-11-25T13:18:44+00:00", "internal_domain" => String }
create a site collection
94 95 96 97 98 99 100 101 |
# File 'lib/sfrest/collection.rb', line 94 def create(name, sites, groups, internal_domain_prefix = nil) sites = Array(sites) groups = Array(groups) current_path = '/api/v1/collections' payload = { 'name' => name, 'site_ids' => sites, 'group_ids' => groups, 'internal_domain_prefix' => internal_domain_prefix }.to_json @conn.post(current_path, payload) end |
#delete(id) ⇒ Hash{ "id" => Integer, "time" => "2016-10-28T09:25:26+00:00", "deleted" => Boolean, "message" => String }
deletes a site collection performs the same action as deleting in the UI
110 111 112 113 |
# File 'lib/sfrest/collection.rb', line 110 def delete(id) current_path = "/api/v1/collections/#{id}" @conn.delete(current_path) end |
#first_collection_id ⇒ Integer
gets the site id of the 1st one found using the api
53 54 55 56 |
# File 'lib/sfrest/collection.rb', line 53 def first_collection_id res = @conn.get('/api/v1/collections') res['collections'].first['id'] end |
#get_collection_data(id) ⇒ Hash
Gets the site data for a specific id
47 48 49 |
# File 'lib/sfrest/collection.rb', line 47 def get_collection_data(id) @conn.get("/api/v1/collections/#{id}") end |
#get_collection_id(name) ⇒ Integer
gets the site ID for the site named sitename will page through all the sites available searching for the site
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sfrest/collection.rb', line 15 def get_collection_id(name) pglimit = 100 res = @conn.get("/api/v1/collections&limit=#{pglimit}") count = res['count'].to_i id = collection_data_from_results(res, name, 'id') return id if id pages = (count / pglimit) + 1 2.upto(pages) do |i| res = @conn.get("/api/v1/collections&limit=#{pglimit}?page=#{i}") id = collection_data_from_results(res, name, 'id') return id if id end nil end |
#remove_sites(id, sites) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "site_ids_removed" => Array, "removed" => Boolean, "message" => String }
removes site(s) from a site collection
140 141 142 143 144 145 |
# File 'lib/sfrest/collection.rb', line 140 def remove_sites(id, sites) sites = Array(sites) payload = { 'site_ids' => sites }.to_json current_path = "/api/v1/collections/#{id}/remove" @conn.post(current_path, payload) end |
#set_primary_site(id, site) ⇒ Hash{ "id" => Integer, "name" => String, "time" => "2016-10-28T09:25:26+00:00", "primary_site_id": Integer, "switched" => Boolean, "message" => String }
sets a site to be a primary site in a site collection
156 157 158 159 160 |
# File 'lib/sfrest/collection.rb', line 156 def set_primary_site(id, site) payload = { 'site_id' => site }.to_json current_path = "/api/v1/collections/#{id}/set-primary" @conn.post(current_path, payload) end |