qtc-sdk 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +18 -18
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Changelog.md +28 -23
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +22 -22
  8. data/README.md +42 -44
  9. data/Rakefile +1 -1
  10. data/bin/qtc-cli +13 -13
  11. data/lib/qtc-sdk.rb +1 -1
  12. data/lib/qtc/cli/commands.rb +15 -15
  13. data/lib/qtc/cli/common.rb +146 -146
  14. data/lib/qtc/cli/eds/base.rb +27 -27
  15. data/lib/qtc/cli/eds/commands.rb +20 -20
  16. data/lib/qtc/cli/eds/instances.rb +30 -30
  17. data/lib/qtc/cli/mar/apps.rb +116 -116
  18. data/lib/qtc/cli/mar/base.rb +60 -60
  19. data/lib/qtc/cli/mar/commands.rb +268 -266
  20. data/lib/qtc/cli/mar/debug.rb +94 -88
  21. data/lib/qtc/cli/mar/domains.rb +35 -35
  22. data/lib/qtc/cli/mar/env.rb +38 -38
  23. data/lib/qtc/cli/mar/repository.rb +24 -24
  24. data/lib/qtc/cli/mar/slugs.rb +80 -80
  25. data/lib/qtc/cli/mar/ssl_certificates.rb +40 -40
  26. data/lib/qtc/cli/mar/stack.rb +29 -29
  27. data/lib/qtc/cli/mdb/base.rb +47 -47
  28. data/lib/qtc/cli/mdb/commands.rb +43 -43
  29. data/lib/qtc/cli/mdb/instances.rb +79 -79
  30. data/lib/qtc/cli/platform/clouds.rb +33 -33
  31. data/lib/qtc/cli/platform/commands.rb +133 -132
  32. data/lib/qtc/cli/platform/datacenters.rb +23 -23
  33. data/lib/qtc/cli/platform/ssh_keys.rb +41 -41
  34. data/lib/qtc/cli/platform/user.rb +29 -25
  35. data/lib/qtc/cli/platform/vpn.rb +93 -93
  36. data/lib/qtc/client.rb +170 -170
  37. data/lib/qtc/eds/client.rb +116 -116
  38. data/lib/qtc/eds/collection.rb +124 -124
  39. data/lib/qtc/eds/user_collection.rb +13 -13
  40. data/lib/qtc/eds/usergroup_collection.rb +41 -41
  41. data/lib/qtc/errors.rb +13 -13
  42. data/lib/qtc/version.rb +3 -3
  43. data/qtc-sdk.gemspec +28 -28
  44. data/spec/spec_helper.rb +17 -0
  45. data/spec/unit/qtc/client_spec.rb +147 -147
  46. metadata +5 -3
@@ -1,117 +1,117 @@
1
- require_relative 'collection'
2
- require_relative 'user_collection'
3
- require_relative 'usergroup_collection'
4
-
5
- module Qtc
6
- module Eds
7
- class Client
8
-
9
- DEFAULT_OPTIONS = {
10
- api_url: 'https://api.engin.io/v1'
11
- }
12
-
13
- ##
14
- # Initialize
15
- #
16
- # @param [String] backend_id
17
- # @param [Hash] options
18
- def initialize(backend_id, options = {})
19
- @options = DEFAULT_OPTIONS.merge(options)
20
- @backend_id = backend_id
21
- headers = {'Enginio-Backend-Id' => @backend_id}
22
- @client = Qtc::Client.new(@options[:api_url], headers)
23
- end
24
-
25
- ##
26
- # Get Qtc::Client instance
27
- #
28
- # @return [Qtc::Client]
29
- def http_client
30
- @client
31
- end
32
-
33
- ##
34
- # Get collection
35
- #
36
- # @param [String] name
37
- # @return [Qtc::Eds::Collection]
38
- def collection(name)
39
- Qtc::Eds::Collection.new(@client, "/objects/#{name}")
40
- end
41
-
42
- ##
43
- # Get user collection
44
- #
45
- # @return [Qtc::Eds::UserCollection]
46
- def users
47
- Qtc::Eds::UserCollection.new(@client)
48
- end
49
-
50
- ##
51
- # Get usergroup collection
52
- #
53
- # @return [Qtc::Eds::UsergroupCollection]
54
- def usergroups
55
- Qtc::Eds::UsergroupCollection.new(@client)
56
- end
57
-
58
- def current_user
59
- if @client.default_headers['Authorization']
60
- @client.get('/user')
61
- end
62
- end
63
-
64
- ##
65
- # Set access token
66
- #
67
- # @param [String] access_token
68
- def access_token=(access_token)
69
- if !access_token.nil?
70
- @client.default_headers['Authorization'] = "Bearer #{access_token}"
71
- else
72
- @client.default_headers.delete('Authorization')
73
- end
74
- end
75
-
76
- ##
77
- # Call block with given access token
78
- #
79
- # @param [String] access_token
80
- # @param []
81
- def with_access_token(access_token, &block)
82
- prev_auth = @client.default_headers['Authorization'].dup
83
- @client.default_headers['Authorization'] = "Bearer #{access_token}"
84
- result = call(&block)
85
- @client.default_headers['Authorization'] = prev_auth
86
- result
87
- ensure
88
- @client.default_headers['Authorization'] = prev_auth if prev_auth
89
- end
90
-
91
- ##
92
- # Create user access token
93
- #
94
- # @param [String] username
95
- # @param [String] password
96
- def create_user_token(username, password)
97
- body = {
98
- grant_type: 'password',
99
- username: username,
100
- password: password
101
- }
102
- @client.post('/auth/oauth2/token', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
103
- end
104
-
105
- ##
106
- # Revoke user access token
107
- #
108
- # @param [String] token
109
- def revoke_user_token(token)
110
- body = {
111
- token: token
112
- }
113
- @client.post('/auth/oauth2/revoke', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
114
- end
115
- end
116
- end
1
+ require_relative 'collection'
2
+ require_relative 'user_collection'
3
+ require_relative 'usergroup_collection'
4
+
5
+ module Qtc
6
+ module Eds
7
+ class Client
8
+
9
+ DEFAULT_OPTIONS = {
10
+ api_url: 'https://api.engin.io/v1'
11
+ }
12
+
13
+ ##
14
+ # Initialize
15
+ #
16
+ # @param [String] backend_id
17
+ # @param [Hash] options
18
+ def initialize(backend_id, options = {})
19
+ @options = DEFAULT_OPTIONS.merge(options)
20
+ @backend_id = backend_id
21
+ headers = {'Enginio-Backend-Id' => @backend_id}
22
+ @client = Qtc::Client.new(@options[:api_url], headers)
23
+ end
24
+
25
+ ##
26
+ # Get Qtc::Client instance
27
+ #
28
+ # @return [Qtc::Client]
29
+ def http_client
30
+ @client
31
+ end
32
+
33
+ ##
34
+ # Get collection
35
+ #
36
+ # @param [String] name
37
+ # @return [Qtc::Eds::Collection]
38
+ def collection(name)
39
+ Qtc::Eds::Collection.new(@client, "/objects/#{name}")
40
+ end
41
+
42
+ ##
43
+ # Get user collection
44
+ #
45
+ # @return [Qtc::Eds::UserCollection]
46
+ def users
47
+ Qtc::Eds::UserCollection.new(@client)
48
+ end
49
+
50
+ ##
51
+ # Get usergroup collection
52
+ #
53
+ # @return [Qtc::Eds::UsergroupCollection]
54
+ def usergroups
55
+ Qtc::Eds::UsergroupCollection.new(@client)
56
+ end
57
+
58
+ def current_user
59
+ if @client.default_headers['Authorization']
60
+ @client.get('/user')
61
+ end
62
+ end
63
+
64
+ ##
65
+ # Set access token
66
+ #
67
+ # @param [String] access_token
68
+ def access_token=(access_token)
69
+ if !access_token.nil?
70
+ @client.default_headers['Authorization'] = "Bearer #{access_token}"
71
+ else
72
+ @client.default_headers.delete('Authorization')
73
+ end
74
+ end
75
+
76
+ ##
77
+ # Call block with given access token
78
+ #
79
+ # @param [String] access_token
80
+ # @param []
81
+ def with_access_token(access_token, &block)
82
+ prev_auth = @client.default_headers['Authorization'].dup
83
+ @client.default_headers['Authorization'] = "Bearer #{access_token}"
84
+ result = call(&block)
85
+ @client.default_headers['Authorization'] = prev_auth
86
+ result
87
+ ensure
88
+ @client.default_headers['Authorization'] = prev_auth if prev_auth
89
+ end
90
+
91
+ ##
92
+ # Create user access token
93
+ #
94
+ # @param [String] username
95
+ # @param [String] password
96
+ def create_user_token(username, password)
97
+ body = {
98
+ grant_type: 'password',
99
+ username: username,
100
+ password: password
101
+ }
102
+ @client.post('/auth/oauth2/token', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
103
+ end
104
+
105
+ ##
106
+ # Revoke user access token
107
+ #
108
+ # @param [String] token
109
+ def revoke_user_token(token)
110
+ body = {
111
+ token: token
112
+ }
113
+ @client.post('/auth/oauth2/revoke', body, {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
114
+ end
115
+ end
116
+ end
117
117
  end
@@ -1,125 +1,125 @@
1
- module Qtc
2
- module Eds
3
- class Collection
4
-
5
- ##
6
- # Initialize EDS collection
7
- #
8
- # @param [Qtc::Client] client
9
- # @param [String] path
10
- def initialize(client, path)
11
- @client = client
12
- @path = path
13
- end
14
-
15
- ##
16
- # Insert a new object
17
- #
18
- # @param [Hash] object
19
- # @return [Hash]
20
- def insert(object)
21
- client.post(path, object)
22
- end
23
-
24
- ##
25
- # Update object
26
- #
27
- # @param [String] id
28
- # @param [Hash] object
29
- # @return [Hash]
30
- def update(id, object)
31
- client.put("#{path}/#{id}", object)
32
- end
33
-
34
- ##
35
- # Atomic operation
36
- #
37
- # @param [String] id
38
- # @param [Hash] operation
39
- # @return [Hash]
40
- def atomic_operation(id, operation)
41
- client.put("#{path}/#{id}/atomic", operation)
42
- end
43
-
44
- ##
45
- # Remove object
46
- #
47
- # @param [String]
48
- # @return [Hash]
49
- def remove(id)
50
- client.delete("#{path}/#{id}")
51
- end
52
-
53
- ##
54
- # Find object by id
55
- #
56
- # @param [String] id
57
- # @return [Hash]
58
- def find_one(id)
59
- client.get("#{path}/#{id}")
60
- end
61
-
62
- ##
63
- # Find objects
64
- #
65
- # @param [Hash] params
66
- # @return [Array<Hash>]
67
- def find(params = {})
68
- if params[:q] && params[:q].is_a?(Hash)
69
- params[:q] = params[:q].to_json
70
- end
71
- if params[:sort] && !params[:sort].is_a?(String)
72
- params[:sort] = params[:sort].to_json
73
- end
74
- response = client.get("#{path}", params)
75
- response['results']
76
- end
77
-
78
- ##
79
- # Set object permissions
80
- #
81
- # @param [String]
82
- def set_permissions(id, permissions)
83
- client.post("#{path}/#{id}/access", permissions)
84
- end
85
-
86
- ##
87
- # Add permissions
88
- #
89
- # @param [String] id
90
- # @param [Hash] permissions
91
- # @return [Hash]
92
- def add_permissions(id, permissions)
93
- client.put("#{path}/#{id}/access", permissions)
94
- end
95
-
96
- ##
97
- # Remove permissions
98
- #
99
- # @param [String] id
100
- # @param [Hash] permissions
101
- # @return [Hash]
102
- def remove_permissions(id, permissions)
103
- client.delete("#{path}/#{id}/access", permissions)
104
- end
105
-
106
- protected
107
-
108
- ##
109
- # Get client
110
- #
111
- # @return [Qtc::Client]
112
- def client
113
- @client
114
- end
115
-
116
- ##
117
- # Get path
118
- #
119
- # @return [String]
120
- def path
121
- @path
122
- end
123
- end
124
- end
1
+ module Qtc
2
+ module Eds
3
+ class Collection
4
+
5
+ ##
6
+ # Initialize EDS collection
7
+ #
8
+ # @param [Qtc::Client] client
9
+ # @param [String] path
10
+ def initialize(client, path)
11
+ @client = client
12
+ @path = path
13
+ end
14
+
15
+ ##
16
+ # Insert a new object
17
+ #
18
+ # @param [Hash] object
19
+ # @return [Hash]
20
+ def insert(object)
21
+ client.post(path, object)
22
+ end
23
+
24
+ ##
25
+ # Update object
26
+ #
27
+ # @param [String] id
28
+ # @param [Hash] object
29
+ # @return [Hash]
30
+ def update(id, object)
31
+ client.put("#{path}/#{id}", object)
32
+ end
33
+
34
+ ##
35
+ # Atomic operation
36
+ #
37
+ # @param [String] id
38
+ # @param [Hash] operation
39
+ # @return [Hash]
40
+ def atomic_operation(id, operation)
41
+ client.put("#{path}/#{id}/atomic", operation)
42
+ end
43
+
44
+ ##
45
+ # Remove object
46
+ #
47
+ # @param [String]
48
+ # @return [Hash]
49
+ def remove(id)
50
+ client.delete("#{path}/#{id}")
51
+ end
52
+
53
+ ##
54
+ # Find object by id
55
+ #
56
+ # @param [String] id
57
+ # @return [Hash]
58
+ def find_one(id)
59
+ client.get("#{path}/#{id}")
60
+ end
61
+
62
+ ##
63
+ # Find objects
64
+ #
65
+ # @param [Hash] params
66
+ # @return [Array<Hash>]
67
+ def find(params = {})
68
+ if params[:q] && params[:q].is_a?(Hash)
69
+ params[:q] = params[:q].to_json
70
+ end
71
+ if params[:sort] && !params[:sort].is_a?(String)
72
+ params[:sort] = params[:sort].to_json
73
+ end
74
+ response = client.get("#{path}", params)
75
+ response['results']
76
+ end
77
+
78
+ ##
79
+ # Set object permissions
80
+ #
81
+ # @param [String]
82
+ def set_permissions(id, permissions)
83
+ client.post("#{path}/#{id}/access", permissions)
84
+ end
85
+
86
+ ##
87
+ # Add permissions
88
+ #
89
+ # @param [String] id
90
+ # @param [Hash] permissions
91
+ # @return [Hash]
92
+ def add_permissions(id, permissions)
93
+ client.put("#{path}/#{id}/access", permissions)
94
+ end
95
+
96
+ ##
97
+ # Remove permissions
98
+ #
99
+ # @param [String] id
100
+ # @param [Hash] permissions
101
+ # @return [Hash]
102
+ def remove_permissions(id, permissions)
103
+ client.delete("#{path}/#{id}/access", permissions)
104
+ end
105
+
106
+ protected
107
+
108
+ ##
109
+ # Get client
110
+ #
111
+ # @return [Qtc::Client]
112
+ def client
113
+ @client
114
+ end
115
+
116
+ ##
117
+ # Get path
118
+ #
119
+ # @return [String]
120
+ def path
121
+ @path
122
+ end
123
+ end
124
+ end
125
125
  end