sfrest 0.0.19 → 0.0.20

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
  SHA256:
3
- metadata.gz: 97d57d6198ba83bf3677c3821c165785970eb76900e7fa551f6254b5e3e8c1ae
4
- data.tar.gz: e7d0e0b759510dda5c05a11e5fd52736895d8ccde760b61adf948a97a43290e2
3
+ metadata.gz: '09110b9e469ba6a0f45ad9b28828acb55d46b5809b80283a722c626f2374b81e'
4
+ data.tar.gz: 4ab3d5fefe519216e45a6fa175d44b3f1d6f0d978ec2ec3e7475ca6da59f182b
5
5
  SHA512:
6
- metadata.gz: d7139a0cd1c942c760f71000cdd14a56fd782c285bdbdaf07510510f8d9d45d49b7bfaefb0fa3aebcf24c083e60260311d980b1a71a44361e428c7d2d3cf5ccd
7
- data.tar.gz: 33e9836ef34538be4327cb613a7fced426675de41056fa1ecea69f87a8a08b3eee8f62039a4e065deb87bb731a8125914a66c6e0cddf322f55cbcdb4bd38e96c
6
+ metadata.gz: ba5deeabee76e8d7e871a0f4fd025b994ae0117093e5fa5359133531440282a9ea7cd615413b1981f1d0d74d706ced48c5615f1b117177ecfa5213cea5f46f4b
7
+ data.tar.gz: 8a26d194101fcfa0628f314140a04190231f4a0236531cf58b96bc8fdcc761a69717f635a514cd2c32432d8fd4ba7943e50cb4487e6faac21965a3341207578a
data/lib/sfrest/error.rb CHANGED
@@ -26,7 +26,6 @@ module SFRest
26
26
  # If the return cannot be parsed into something useful
27
27
  class InvalidResponse < SFRest::SFError; end
28
28
 
29
- # If you call an unsuported version
30
- #
29
+ # If you call an unsupported version
31
30
  class InvalidApiVersion < SFRest::SFError; end
32
31
  end
data/lib/sfrest/update.rb CHANGED
@@ -30,6 +30,9 @@ module SFRest
30
30
 
31
31
  # Starts an update.
32
32
  def start_update(ref)
33
+ if update_version == 'v2'
34
+ raise InvalidApiVersion, 'There is more than one codebase use sfrest.update.update directly.'
35
+ end
33
36
  update_data = { scope: 'sites', sites_type: 'code, db', sites_ref: ref }
34
37
  update(update_data)
35
38
  end
@@ -44,11 +47,19 @@ module SFRest
44
47
  # This method does not filter or validate so that it can be used for
45
48
  # negative cases. (missing data)
46
49
  def update(datum)
47
- current_path = '/api/v1/update'
50
+ validate_request datum
51
+ current_path = "/api/#{update_version}/update"
48
52
  payload = datum.to_json
49
53
  @conn.post(current_path, payload)
50
54
  end
51
55
 
56
+ def validate_request(datum)
57
+ v1_keys = %i[scope sites_ref factory_ref sites_type factory_type db_update_arguments]
58
+ v2_keys = %i[sites factory]
59
+ key_overlap = binding.local_variable_get("#{update_version}_keys") & datum.keys
60
+ raise InvalidDataError, "An invalid stucture was passed to the #{update_version} endpoint" if key_overlap.empty?
61
+ end
62
+
52
63
  # Gets the list of updates.
53
64
  def update_list
54
65
  current_path = '/api/v1/update'
@@ -74,5 +85,10 @@ module SFRest
74
85
  payload = { 'pause' => false }.to_json
75
86
  @conn.post(current_path, payload)
76
87
  end
88
+
89
+ # Determines the api version to use for updates.
90
+ def update_version
91
+ @conn.codebase.list['stacks'].size > 1 ? 'v2' : 'v1'
92
+ end
77
93
  end
78
94
  end
@@ -1,4 +1,4 @@
1
1
  module SFRest
2
2
  # Just tracks the version of sfrest.
3
- VERSION = '0.0.19'.freeze
3
+ VERSION = '0.0.20'.freeze
4
4
  end
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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - ACSF Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-28 00:00:00.000000000 Z
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon