scalr_api_v2 0.1.1 → 0.2.0

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: bfaa11e42bd9e4ffd2b715cf1abbef70f4b0395c
4
- data.tar.gz: cdbca4d590cc172a600fb582d6731eab9199974d
3
+ metadata.gz: 88fb75c5f8f55a72130481651889c0ab9c56823d
4
+ data.tar.gz: 937534bc0d5823556136a50e7c41300b4c3d10e6
5
5
  SHA512:
6
- metadata.gz: bc3f4781eeb9d7050d58a2b187763f4cd09635af7353484a7ddd2ac9a8c59f80b2efc47f3201c0adb54731d9e30e8892d9f79daf2636d0af875bc45a22d0a76f
7
- data.tar.gz: ef9e6679d121005e3b56d3713c1cf65a877d8a44bd429441b0de5728ca8916ff8beee7b06394eb21f63d8c0467efd640c47307ddf5dce70e9a1e8b038150ad92
6
+ metadata.gz: 293b1980f69372cae7726c239909a8929e85d5bd9e576d5191b1c501e3c77a1f4356a78b96b4abbd3659f242fde4876ff33296958b80464cf68535f3b96037df
7
+ data.tar.gz: a413e910a14eb2b0aa9014267d10774742418a94636f8cfb65c13bbe8621d6293406bce661e2cbd2f5d3fe606a22cfa098c9dec09bc4d5a1c7857951a7e4e3de
data/.rubocop.yml CHANGED
@@ -23,10 +23,10 @@ Metrics/LineLength:
23
23
  # Offense count: 1
24
24
  # Configuration parameters: CountComments.
25
25
  Metrics/MethodLength:
26
- Max: 60
26
+ Max: 100
27
27
 
28
28
  Metrics/BlockLength:
29
- Max: 60
29
+ Max: 100
30
30
 
31
31
  # Offense count: 1
32
32
  # Configuration parameters: MinBodyLength.
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ == 0.2.0
2
+
3
+ * Added account/user logic based on SCALR_ENV_ID being set. Defaults to 'account' mode if nil
4
+ * Added Tests
5
+
6
+ == 0.1.1
7
+
8
+ * Initial version
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://travis-ci.org/autotraderuk/scalr_api_v2.svg?branch=master)](https://travis-ci.org/autotraderuk/scalr_api_v2)
1
+ [![Build Status](https://travis-ci.org/autotraderuk/scalr_api_v2.svg?branch=master)](https://travis-ci.org/autotraderuk/scalr_api_v2) [![Gem Version](https://badge.fury.io/rb/scalr_api_v2.svg)](https://badge.fury.io/rb/scalr_api_v2)
2
2
  # ScalrApiV2
3
3
 
4
4
  Ruby gem to allow you to develop against V2 of the [SCALR API](https://api-explorer.scalr.com)
@@ -26,7 +26,7 @@ Set the below environment variables:
26
26
  export SCALR_API_KEY=your-api-key
27
27
  export SCALR_API_SECRET=your-api-secret
28
28
  export SCALR_URL=scalr-api-url
29
- export SCALR_ENV_ID=id-of-desired-environment
29
+ export SCALR_ENV_ID=id-of-desired-environment (optional determines if request is sent as user or account i.e 'GET /api/v1beta0/account/scripts/' or 'GET /api/v1beta0/user/envId/scripts/'. defaults to account mode.)
30
30
 
31
31
  ### in your code
32
32
 
@@ -3,17 +3,27 @@ module ScalrApiV2
3
3
  class Config
4
4
  def initialize; end
5
5
 
6
+ def mode_path(env_id)
7
+ mode = if env_id.nil?
8
+ 'account'
9
+ else
10
+ Integer(env_id) >= 0 ? 'user' : 'account'
11
+ end
12
+ return mode == 'account' ? 'account' : "user/#{env_id}"
13
+ end
14
+
6
15
  def config
7
16
  config = {}
8
17
 
9
- if ENV['SCALR_URL'].nil? || ENV['SCALR_KEY_ID'].nil? || ENV['SCALR_KEY_SECRET'].nil? || ENV['SCALR_ENV_ID'].nil?
10
- config['error'] = 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET, SCALR_ENV_ID'
11
- raise 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET, SCALR_ENV_ID'
18
+ if ENV['SCALR_URL'].nil? || ENV['SCALR_KEY_ID'].nil? || ENV['SCALR_KEY_SECRET'].nil?
19
+ config['error'] = 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET'
20
+ raise 'Missing Environment variables, please configure SCALR_URL, SCALR_KEY_ID, SCALR_KEY_SECRET'
12
21
  else
13
22
  config['url'] = ENV['SCALR_URL']
14
23
  config['key_id'] = ENV['SCALR_KEY_ID']
15
24
  config['key_secret'] = ENV['SCALR_KEY_SECRET']
16
- config['env_id'] = ENV['SCALR_ENV_ID']
25
+ config['env_id'] = ENV['SCALR_ENV_ID'].nil? ? nil : ENV['SCALR_ENV_ID']
26
+ config['mode_path'] = mode_path(config['env_id'])
17
27
  end
18
28
  return config
19
29
  end
@@ -11,7 +11,7 @@ module ScalrApiV2
11
11
 
12
12
  # List all scripts
13
13
  def list
14
- list = @scalr.list(format('/api/v1beta0/user/%s/farms/', @config['env_id']))
14
+ list = @scalr.list(format('/api/v1beta0/%s/farms/', @config['mode_path']))
15
15
  return list
16
16
  end
17
17
 
@@ -18,43 +18,43 @@ module ScalrApiV2
18
18
 
19
19
  # List all scripts
20
20
  def list
21
- list = @scalr.list(format('/api/v1beta0/user/%s/scripts/', @config['env_id']))
21
+ list = @scalr.list(format('/api/v1beta0/%s/scripts/', @config['mode_path']))
22
22
  return list
23
23
  end
24
24
 
25
25
  # List all script versions
26
26
  def versions(script_id = 1)
27
- list = @scalr.list(format('/api/v1beta0/user/%s/scripts/%s/script-versions/', @config['env_id'], script_id))
27
+ list = @scalr.list(format('/api/v1beta0/%s/scripts/%s/script-versions/', @config['mode_path'], script_id))
28
28
  return list
29
29
  end
30
30
 
31
31
  # Create script accepts script_object as hash and generates JSON before making SCALR api call
32
32
  def create(script_object)
33
- item = @scalr.create(format('/api/v1beta0/user/%s/scripts/', @config['env_id']), JSON.generate(script_object))
33
+ item = @scalr.create(format('/api/v1beta0/%s/scripts/', @config['mode_path']), JSON.generate(script_object))
34
34
  return item
35
35
  end
36
36
 
37
37
  # Create script version
38
38
  def create_version(script_id, script_object)
39
- item = @scalr.create(format('/api/v1beta0/user/%s/scripts/%s/script-versions/', @config['env_id'], script_id), JSON.generate(script_object))
39
+ item = @scalr.create(format('/api/v1beta0/%s/scripts/%s/script-versions/', @config['mode_path'], script_id), JSON.generate(script_object))
40
40
  return item
41
41
  end
42
42
 
43
43
  # Update script version
44
44
  def update_version(script_id, script_version, script_object)
45
- item = @scalr.patch(format('/api/v1beta0/user/%s/scripts/%s/script-versions/%s/', @config['env_id'], script_id, script_version), JSON.generate(script_object))
45
+ item = @scalr.patch(format('/api/v1beta0/%s/scripts/%s/script-versions/%s/', @config['mode_path'], script_id, script_version), JSON.generate(script_object))
46
46
  return item
47
47
  end
48
48
 
49
49
  # execute version
50
50
  def execute(script_id, script_execution_object)
51
- item = @scalr.post(format('/api/v1beta0/user/%s/scripts/%s/actions/execute', @config['env_id'], script_id), JSON.generate(script_execution_object))
51
+ item = @scalr.post(format('/api/v1beta0/%s/scripts/%s/actions/execute', @config['mode_path'], script_id), JSON.generate(script_execution_object))
52
52
  return item
53
53
  end
54
54
 
55
55
  # execute script version
56
56
  def execute_version(script_id, script_version, script_execution_object)
57
- item = @scalr.post(format('/api/v1beta0/user/%s/scripts/%s/script-versions/%s/actions/execute', @config['env_id'], script_id, script_version), JSON.generate(script_execution_object))
57
+ item = @scalr.post(format('/api/v1beta0/%s/scripts/%s/script-versions/%s/actions/execute', @config['mode_path'], script_id, script_version), JSON.generate(script_execution_object))
58
58
  return item
59
59
  end
60
60
  end
@@ -11,7 +11,7 @@ module ScalrApiV2
11
11
 
12
12
  # List all scripts
13
13
  def list
14
- list = @scalr.list(format('/api/v1beta0/user/%s/servers/', @config['env_id']))
14
+ list = @scalr.list(format('/api/v1beta0/%s/servers/', @config['mode_path']))
15
15
  return list
16
16
  end
17
17
 
@@ -1,4 +1,4 @@
1
1
  # ScalrApiV2::VERSION
2
2
  module ScalrApiV2
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scalr_api_v2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - david.meekin
@@ -205,6 +205,7 @@ files:
205
205
  - .rspec
206
206
  - .rubocop.yml
207
207
  - .travis.yml
208
+ - CHANGELOG
208
209
  - CODE_OF_CONDUCT.md
209
210
  - Gemfile
210
211
  - LICENSE.txt