varager 0.0.1 → 0.1.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: f1ff884688f9832aa7ede51d9310522c5a5e82dd
4
- data.tar.gz: cf580f910d35ddcb7c5f80a7797952007086e2ae
3
+ metadata.gz: 343db2b78b491e160f73fefd1400a203bc91b9c0
4
+ data.tar.gz: 58aee4dfd41b33c3ac43ad5860c1226b6e5d97aa
5
5
  SHA512:
6
- metadata.gz: de338f460c496885853b7b5fb9ff6fd95c4d434eee4e724f4298ffc8c955cfe3393e7bcbd8f0cd7eb3e589f5feb983e95f973bc3f24e566cb61a80a5d230ae84
7
- data.tar.gz: 246d714704e113d108de5d86f6bdcde7791de6a82c571ebe014d2c95c688cfeaf5671342ce6d1a8670d899be45274da94be1d9b2fdea48a2775ad39f9c4faca2
6
+ metadata.gz: 1c3f2427258383e169a31852f41909f43bd12c35ae3bb05d960b725a7889844d1164b9ae8ae1eba2e21e41a84b00384b344e78c89e5e117d5ba518c9324e472b
7
+ data.tar.gz: 1be20b43f83652ce9a89cc1ac88abcdb7f3ab130238c7745407cadc4678b7263fd49b7115d515fdbba28fa11b17faf5e2a18767701f6533bce9575c620f5eafd
data/README.md CHANGED
@@ -1,2 +1,59 @@
1
- AppNexus Client
2
- ==================
1
+ Varager ruby wrapper
2
+ =======================
3
+ # Installation
4
+ ```bash
5
+ gem install varager
6
+ ```
7
+
8
+ # Configuration
9
+ ```ruby
10
+ # Server endpoint
11
+ Varager.site = "http://localhost:3000"
12
+
13
+ # Creds
14
+ Varager.user = "ant@gmail.com"
15
+ Varager.password = "totolala"
16
+
17
+ # Loggers
18
+ Varager.logger = Logger.new(STDOUT)
19
+ OpenAPI.logger = Varager.logger
20
+ ```
21
+
22
+ # Usage
23
+ Auth is done once on the first call
24
+
25
+ ## Environments
26
+ ### List
27
+ ```ruby
28
+ # Get all envs
29
+ envs = Varager.list_envs
30
+ #=> #<Varager::Model::Envs>>
31
+ first_env = envs.environments[0]
32
+ #=> #<Varager::Model::Env>>
33
+ ```
34
+ ### Get
35
+ ```ruby
36
+ # 1. From http_client
37
+ env = Varager.get_env(params: {id: env_id})
38
+ #=> #<Varager::Model::Env>>
39
+ ```
40
+ ### Delete
41
+ ```ruby
42
+ # 1. From http_client
43
+ env = Varager.get_env(params: {id: env_id})
44
+ #=> #<Varager::Model::Env>>
45
+
46
+ # 2. From model
47
+ env.delete!
48
+ ```
49
+
50
+ ## Add variables to an environment
51
+ ```ruby
52
+ # 1. From http_client
53
+ env = Varager.add_vars(params: {id: env_id}, body: {config: {var1: value, var2: value2}}.to_json)
54
+ #=> #<Varager::Model::Env>>
55
+
56
+ # 2. From model
57
+ env.add_var(key, value)
58
+ env.add_vars({key1: value, key2: value2})
59
+ ```
@@ -2,8 +2,9 @@ module Varager
2
2
  class AuthToken < OpenAPI::AuthToken
3
3
 
4
4
  def initialize
5
- super ({"header" => "Authorization",
6
- "header_format" => "%s"})
5
+ super ({"expires_in" => 3600,
6
+ "header" => "Authorization",
7
+ "header_format" => "%s"})
7
8
  end
8
9
 
9
10
  def new_auth_token()
@@ -2,6 +2,7 @@ $:.unshift(File.dirname(__FILE__))
2
2
 
3
3
  module Varager
4
4
  module Handlers
5
- autoload :AppResponse, "handlers/app_response"
5
+ autoload :Model, "handlers/json"
6
+ autoload :Array, "handlers/json"
6
7
  end
7
8
  end
@@ -0,0 +1,50 @@
1
+ module Varager
2
+ module Handlers
3
+ class Model < OpenAPI::Handler
4
+ class << self
5
+ def method_missing(method_symbol, *arguments) #:nodoc:
6
+ method_name = method_symbol.to_s
7
+ return self.send :const_model, method_name, *arguments
8
+ end
9
+
10
+ private
11
+
12
+ def const_model(snake_name, response, options)
13
+ klass_name = snake_name.camelize
14
+ hash = JSON.parse(response.raw)
15
+ klass = Varager::Model.const_get(klass_name)
16
+ if klass.respond_to?(:json_root)
17
+ hash = hash[klass.json_root]
18
+ end
19
+ resp = klass.new(hash)
20
+ return OpenAPI::Handlers::Response.wrap(resp, response)
21
+ end
22
+ end
23
+ end
24
+
25
+ class Array < OpenAPI::Handler
26
+ class << self
27
+ def method_missing(method_symbol, *arguments) #:nodoc:
28
+ method_name = method_symbol.to_s
29
+ return self.send :const_model, method_name, *arguments
30
+ end
31
+
32
+ private
33
+
34
+ def const_model(snake_name, response, options)
35
+ klass_name = snake_name.camelize
36
+ array = JSON.parse(response.raw)
37
+ klass = Varager::Model.const_get(klass_name)
38
+ resp = []
39
+ array.each do |item|
40
+ if klass.respond_to?(:json_root)
41
+ hash = hash[klass.json_root]
42
+ end
43
+ resp << klass.new(item)
44
+ end
45
+ return OpenAPI::Handlers::Response.wrap(resp, response)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -5,43 +5,42 @@ module Varager
5
5
  include Virtus.model
6
6
  attribute :id, Integer
7
7
  attribute :name, :String
8
- attribute :config, Hash
8
+ attribute :vars, Hash
9
9
  attribute :created_at, Date
10
10
  attribute :updated_at, Date
11
11
 
12
-
13
-
14
- # def save!
15
- # Varager.add_env(self.to_json)
16
- # end
17
12
  def conf_shell(with_export=false)
18
- config.each {|k,v| puts "#{with_export ? 'export ' : ''}#{k}='#{v}'"}
13
+ vars.each {|k,v| puts "#{with_export ? 'export ' : ''}#{k}='#{v}'"}
19
14
  end
20
15
 
21
16
  def conf_yaml
22
- config.each {|k,v| puts "#{k}: '#{v}'"}
17
+ vars.each {|k,v| puts "#{k}: '#{v}'"}
23
18
  end
24
19
 
25
20
  def conf_k8s(indent=10)
26
21
  space = "#{" " * indent}"
27
- config.each {|k,v| puts "#{space}- name: #{k}\n#{space} value:'#{v}'"}
22
+ vars.each {|k,v| puts "#{space}- name: #{k}\n#{space} value:'#{v}'"}
28
23
  end
29
24
 
30
25
  def conf_json
31
- config.to_json
26
+ vars.to_json
27
+ end
28
+
29
+ def users
30
+ Varager.list_env_users(params: {environment_id: self.id})
32
31
  end
33
32
 
34
33
  def add_var(key, value)
35
- Varager.add_vars(params: {id: self.name}, body: {config: {key => value}}.to_json)
34
+ Varager.add_vars(params: {id: self.name}, body: {vars: {key => value}}.to_json)
36
35
  end
37
36
 
38
37
  def add_vars(dict)
39
- Varager.add_vars(params: {id: self.name}, body: {config: dict}.to_json)
38
+ Varager.add_vars(params: {id: self.name}, body: {vars: dict}.to_json)
40
39
  end
41
40
 
42
- def self.json_root
43
- @json_root = "environment"
44
- end
41
+ # def self.json_root
42
+ # @json_root = "environment"
43
+ # end
45
44
 
46
45
  end
47
46
 
@@ -5,22 +5,23 @@ module Varager
5
5
  def generate(client=Varager)
6
6
  OpenAPI::Route.draw(client) do
7
7
  ## AUTH
8
- match "users/sign_in", "varager/handlers/app_response#response", :auth, via: :post, :options => {:skip_auth => true}
8
+ match "users/sign_in", "varager/handlers/model#response", :auth, via: :post, :options => {:skip_auth => true}
9
9
 
10
10
  ## ENVS
11
- match "api/environments", "varager/handlers/app_response#envs", :list_envs, via: :get
12
- match "api/environments/:id", "varager/handlers/app_response#env", :get_env, via: :get
13
- match "api/environments/:id", "varager/handlers/app_response#env", :delete_env, via: :delete
14
- match "api/environments/:id", "varager/handlers/app_response#env", :add_vars, via: :put
11
+ match "environments", "varager/handlers/array#env", :list_envs, via: :get
12
+ match "environments/:id", "varager/handlers/model#env", :get_env, via: :get
13
+ match "environments/:id", "varager/handlers/model#env", :delete_env, via: :delete
14
+ match "environments/:id/addvars", "varager/handlers/model#env", :add_vars, via: :post
15
15
 
16
16
  ## USERS
17
- match "api/users", "varager/handlers/app_response#response", :list_users, via: :get
17
+ match "environments/:environment_id/users", "varager/handlers/array#response", :list_env_users, via: :get
18
+ match "users", "varager/handlers/array#response", :list_users, via: :get
18
19
 
19
20
  # CRUD CALLS
20
- match "GET", "varager/handlers/app_response#response", :GET, via: :get
21
- match "DELETE", "varager/handlers/app_response#response", :DELETE, via: :get
22
- match "PUT", "varager/handlers/app_response#response", :PUT, via: :get
23
- match "POST", "varager/handlers/app_response#response", :POST, via: :post
21
+ match "GET", "varager/handlers/model#response", :GET, via: :get
22
+ match "DELETE", "varager/handlers/model#response", :DELETE, via: :get
23
+ match "PUT", "varager/handlers/model#response", :PUT, via: :get
24
+ match "POST", "varager/handlers/model#response", :POST, via: :post
24
25
  end
25
26
  end
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module Varager
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: varager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Legrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-21 00:00:00.000000000 Z
11
+ date: 2016-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openapi
@@ -95,7 +95,7 @@ files:
95
95
  - lib/varager/auth_token.rb
96
96
  - lib/varager/client.rb
97
97
  - lib/varager/handlers.rb
98
- - lib/varager/handlers/app_response.rb
98
+ - lib/varager/handlers/json.rb
99
99
  - lib/varager/models.rb
100
100
  - lib/varager/models/env.rb
101
101
  - lib/varager/models/response.rb
@@ -1,26 +0,0 @@
1
- module Varager
2
- module Handlers
3
- class AppResponse < OpenAPI::Handler
4
- class << self
5
- def method_missing(method_symbol, *arguments) #:nodoc:
6
- method_name = method_symbol.to_s
7
- return self.send :const_model, method_name, *arguments
8
- end
9
-
10
- private
11
-
12
- def const_model(snake_name, response, options)
13
- klass_name = snake_name.camelize
14
- hash = JSON.parse(response.raw)
15
- klass = Varager::Model.const_get(klass_name)
16
- if klass.respond_to?(:json_root)
17
- hash = hash[klass.json_root]
18
- end
19
- resp = klass.new(hash)
20
- return OpenAPI::Handlers::Response.wrap(resp, response)
21
- end
22
-
23
- end
24
- end
25
- end
26
- end