sfrest 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sfrest/collections.rb +82 -0
- data/lib/sfrest/connection.rb +1 -0
- data/lib/sfrest/version.rb +1 -1
- data/lib/sfrest.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 503e0513bc735d120e86fa1c89bf6f5679af9b47
|
4
|
+
data.tar.gz: 217003f9137d9c8e9ef375183c155d7f09dc9d15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e0052781a7ceb063ffc24b081d5f8d838d974bfcfbdc7a1d1b5a0e48bfd1f37cf710f9348f586f705606ac271b346a94886868d9b6384e7cd7ebddc911ba86f
|
7
|
+
data.tar.gz: 41ac61ab6a027c9fe7ce8a8a82b7ffa20e9de0272993fda29f3d79e5d870f70482a3d089092c87e8d6aa55714439262e66e88ce94c400fd7a76fab224a4601f4
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module SFRest
|
2
|
+
# Find colletions, return their data.
|
3
|
+
class Collections
|
4
|
+
# @param [SFRest::Connection] conn
|
5
|
+
def initialize(conn)
|
6
|
+
@conn = conn
|
7
|
+
end
|
8
|
+
|
9
|
+
# gets the site ID for the site named sitename
|
10
|
+
# will page through all the sites available searching for the site
|
11
|
+
# @param [String] name the name of the site
|
12
|
+
# @return [Integer] the id of sitename
|
13
|
+
def get_collection_id(name)
|
14
|
+
pglimit = 100
|
15
|
+
res = @conn.get('/api/v1/collections&limit=' + pglimit.to_s)
|
16
|
+
count = res['count'].to_i
|
17
|
+
id = collection_data_from_results(res, name, 'id')
|
18
|
+
return id if id
|
19
|
+
pages = (count / pglimit) + 1
|
20
|
+
2.upto(pages) do |i|
|
21
|
+
res = @conn.get('/api/v1/collections&limit=' + pglimit.to_s + '?page=' + i.to_s)
|
22
|
+
id = collection_data_from_results(res, name, 'id')
|
23
|
+
return id if id
|
24
|
+
end
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# Extract the site data for 'key' based on the site result object
|
29
|
+
# @param [Hash] res result from a request to /collections
|
30
|
+
# @param [String] name
|
31
|
+
# @param [String] key one of the user data returned (id, name, domain...)
|
32
|
+
# @return [Object] Integer, String, Array, Hash depending on the collection data
|
33
|
+
def collection_data_from_results(res, name, key)
|
34
|
+
collections = res['collections']
|
35
|
+
collections.each do |collection|
|
36
|
+
return collection[key] if collection['name'] == name
|
37
|
+
end
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# Gets the site data for a specific id
|
42
|
+
# @param [Integer] id the site id
|
43
|
+
# @return [Hash]
|
44
|
+
def get_collection_data(id)
|
45
|
+
@conn.get('/api/v1/collections/' + id.to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
# gets the site id of the 1st one found using the api
|
49
|
+
# @return [Integer] the site id
|
50
|
+
def first_collection_id
|
51
|
+
res = @conn.get('/api/v1/collections')
|
52
|
+
res['collections'].first['id']
|
53
|
+
end
|
54
|
+
|
55
|
+
# Gets the complete list of collections
|
56
|
+
# Makes multiple requests to the factory to get all the collections on the factory
|
57
|
+
# @return [Hash{'count' => Integer, 'sites' => Hash}]
|
58
|
+
def collection_list
|
59
|
+
page = 1
|
60
|
+
not_done = true
|
61
|
+
count = 0
|
62
|
+
while not_done
|
63
|
+
current_path = '/api/v1/collections?page=' << page.to_s
|
64
|
+
res = @conn.get(current_path)
|
65
|
+
if res['collections'] == []
|
66
|
+
not_done = false
|
67
|
+
elsif !res['message'].nil?
|
68
|
+
return { 'message' => res['message'] }
|
69
|
+
elsif page == 1
|
70
|
+
count = res['count']
|
71
|
+
collections = res['collections']
|
72
|
+
else
|
73
|
+
res['collections'].each do |collection|
|
74
|
+
collections << collection
|
75
|
+
end
|
76
|
+
end
|
77
|
+
page += 1
|
78
|
+
end
|
79
|
+
{ 'count' => count, 'collections' => collections }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/sfrest/connection.rb
CHANGED
data/lib/sfrest/version.rb
CHANGED
data/lib/sfrest.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ACSF Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/sfrest.rb
|
90
90
|
- lib/sfrest/audit.rb
|
91
91
|
- lib/sfrest/backup.rb
|
92
|
+
- lib/sfrest/collections.rb
|
92
93
|
- lib/sfrest/connection.rb
|
93
94
|
- lib/sfrest/domains.rb
|
94
95
|
- lib/sfrest/error.rb
|
@@ -124,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
127
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.6.
|
128
|
+
rubygems_version: 2.6.11
|
128
129
|
signing_key:
|
129
130
|
specification_version: 4
|
130
131
|
summary: Acquia Site Factory Rest API.
|