sfrest 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22a23bb499156611238ac336d4e07e0d54a3e6aa
4
- data.tar.gz: b1c3251938898986d6fa5862e23a028b28beef05
3
+ metadata.gz: 503e0513bc735d120e86fa1c89bf6f5679af9b47
4
+ data.tar.gz: 217003f9137d9c8e9ef375183c155d7f09dc9d15
5
5
  SHA512:
6
- metadata.gz: 47ceb7b2c2ccda1e4b2ccac64dfe1b2d311542cbb033d6068dcfbfd56cae18d6d1d20122b6176185379833fff777837310ab195c377f6dac737ab320ea09e9a6
7
- data.tar.gz: 585e87cf5b7945ae2af4183e63c85ce8115c29a6f796cddbd90c4dba83baddb6322b371fce3f4d35698bce8622a3de456f2f0a4c6581d6908c8e424995ad49f5
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
@@ -151,6 +151,7 @@ module SFRest
151
151
  # NOTE: accessor == Class_name.to_lower
152
152
  REST_METHODS = %w(audit
153
153
  backup
154
+ collections
154
155
  domains
155
156
  group
156
157
  role
@@ -1,4 +1,4 @@
1
1
  module SFRest
2
2
  # Just tracks the version of sfrest.
3
- VERSION = '0.0.10'.freeze
3
+ VERSION = '0.0.11'.freeze
4
4
  end
data/lib/sfrest.rb CHANGED
@@ -8,6 +8,7 @@ require 'json'
8
8
 
9
9
  require 'sfrest/audit'
10
10
  require 'sfrest/backup'
11
+ require 'sfrest/collections'
11
12
  require 'sfrest/connection'
12
13
  require 'sfrest/domains'
13
14
  require 'sfrest/error'
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.10
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: 2016-12-29 00:00:00.000000000 Z
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.10
128
+ rubygems_version: 2.6.11
128
129
  signing_key:
129
130
  specification_version: 4
130
131
  summary: Acquia Site Factory Rest API.