deployment-tracker-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ module DeploymentTrackerClient
2
+ #
3
+ class ErrorResponse < BaseObject
4
+ attr_accessor :error
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ #
10
+ :'error' => :'Error'
11
+
12
+ }
13
+ end
14
+
15
+ # attribute type
16
+ def self.swagger_types
17
+ {
18
+ :'error' => :'string'
19
+
20
+ }
21
+ end
22
+
23
+ def initialize(attributes = {})
24
+ return if !attributes.is_a?(Hash) || attributes.empty?
25
+
26
+ # convert string to symbol for hash key
27
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
28
+
29
+
30
+ if attributes[:'Error']
31
+ @error = attributes[:'Error']
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ module DeploymentTrackerClient
2
+ #
3
+ class LogMessage < BaseObject
4
+ attr_accessor :message
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ # The message to log
10
+ :'message' => :'message'
11
+
12
+ }
13
+ end
14
+
15
+ # attribute type
16
+ def self.swagger_types
17
+ {
18
+ :'message' => :'string'
19
+
20
+ }
21
+ end
22
+
23
+ def initialize(attributes = {})
24
+ return if !attributes.is_a?(Hash) || attributes.empty?
25
+
26
+ # convert string to symbol for hash key
27
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
28
+
29
+
30
+ if attributes[:'message']
31
+ @message = attributes[:'message']
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ module DeploymentTrackerClient
2
+ #
3
+ class ObjectResponse < BaseObject
4
+ attr_accessor :message
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ #
10
+ :'message' => :'message'
11
+
12
+ }
13
+ end
14
+
15
+ # attribute type
16
+ def self.swagger_types
17
+ {
18
+ :'message' => :'object'
19
+
20
+ }
21
+ end
22
+
23
+ def initialize(attributes = {})
24
+ return if !attributes.is_a?(Hash) || attributes.empty?
25
+
26
+ # convert string to symbol for hash key
27
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
28
+
29
+
30
+ if attributes[:'message']
31
+ @message = attributes[:'message']
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,68 @@
1
+ module DeploymentTrackerClient
2
+ #
3
+ class Server < BaseObject
4
+ attr_accessor :deployment_id, :hostname, :ip_address, :result, :elapsed_seconds
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ # Unique Identifier (UUID) of the deployment starting
10
+ :'deployment_id' => :'deployment_id',
11
+
12
+ # Fully qualified domain name of the server
13
+ :'hostname' => :'hostname',
14
+
15
+ # IP Address of the server
16
+ :'ip_address' => :'ip_address',
17
+
18
+ # The result of running the deployment on the server
19
+ :'result' => :'result',
20
+
21
+ # The elapsed time of the deployment, in seconds
22
+ :'elapsed_seconds' => :'elapsed_seconds'
23
+
24
+ }
25
+ end
26
+
27
+ # attribute type
28
+ def self.swagger_types
29
+ {
30
+ :'deployment_id' => :'string',
31
+ :'hostname' => :'string',
32
+ :'ip_address' => :'string',
33
+ :'result' => :'string',
34
+ :'elapsed_seconds' => :'int'
35
+
36
+ }
37
+ end
38
+
39
+ def initialize(attributes = {})
40
+ return if !attributes.is_a?(Hash) || attributes.empty?
41
+
42
+ # convert string to symbol for hash key
43
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
44
+
45
+
46
+ if attributes[:'deployment_id']
47
+ @deployment_id = attributes[:'deployment_id']
48
+ end
49
+
50
+ if attributes[:'hostname']
51
+ @hostname = attributes[:'hostname']
52
+ end
53
+
54
+ if attributes[:'ip_address']
55
+ @ip_address = attributes[:'ip_address']
56
+ end
57
+
58
+ if attributes[:'result']
59
+ @result = attributes[:'result']
60
+ end
61
+
62
+ if attributes[:'elapsed_seconds']
63
+ @elapsed_seconds = attributes[:'elapsed_seconds']
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module DeploymentTrackerClient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,13 @@
1
+ require "deployment-tracker-client/version"
2
+ require_relative "swagger_client"
3
+
4
+ # Models
5
+ require "deployment-tracker-client/models/base_object"
6
+ require "deployment-tracker-client/models/object_response"
7
+ require "deployment-tracker-client/models/error_response"
8
+ require "deployment-tracker-client/models/deployment"
9
+ require "deployment-tracker-client/models/server"
10
+ require "deployment-tracker-client/models/log_message"
11
+
12
+ # APIs
13
+ require "deployment-tracker-client/api/default_api"
@@ -0,0 +1,90 @@
1
+ # module Swagger
2
+ class Object
3
+
4
+ unless Object.method_defined? :blank?
5
+ def blank?
6
+ respond_to?(:empty?) ? empty? : !self
7
+ end
8
+ end
9
+
10
+ unless Object.method_defined? :present?
11
+ def present?
12
+ !blank?
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+ class String
19
+
20
+ unless String.method_defined? :underscore
21
+ def underscore
22
+ self.gsub(/::/, '/').
23
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
24
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
25
+ tr("-", "_").
26
+ downcase
27
+ end
28
+ end
29
+
30
+ unless String.method_defined? :camelize
31
+ def camelize(first_letter_in_uppercase = true)
32
+ if first_letter_in_uppercase != :lower
33
+ self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
34
+ else
35
+ self.to_s[0].chr.downcase + camelize(self)[1..-1]
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ class Hash
43
+
44
+ unless Hash.method_defined? :stringify_keys
45
+ def stringify_keys
46
+ inject({}) do |options, (key, value)|
47
+ options[key.to_s] = value
48
+ options
49
+ end
50
+ end
51
+ end
52
+
53
+ unless Hash.method_defined? :stringify_keys!
54
+ def stringify_keys!
55
+ self.replace(self.stringify_keys)
56
+ end
57
+ end
58
+
59
+ unless Hash.method_defined? :symbolize_keys
60
+ def symbolize_keys
61
+ inject({}) do |options, (key, value)|
62
+ options[(key.to_sym rescue key) || key] = value
63
+ options
64
+ end
65
+ end
66
+ end
67
+
68
+ unless Hash.method_defined? :symbolize_keys!
69
+ def symbolize_keys!
70
+ self.replace(self.symbolize_keys)
71
+ end
72
+ end
73
+
74
+ unless Hash.method_defined? :symbolize_and_underscore_keys
75
+ def symbolize_and_underscore_keys
76
+ inject({}) do |options, (key, value)|
77
+ options[(key.to_s.underscore.to_sym rescue key) || key] = value
78
+ options
79
+ end
80
+ end
81
+ end
82
+
83
+ unless Hash.method_defined? :symbolize_and_underscore_keys!
84
+ def symbolize_and_underscore_keys!
85
+ self.replace(self.symbolize_and_underscore_keys)
86
+ end
87
+ end
88
+
89
+ end
90
+ # end
@@ -0,0 +1,29 @@
1
+ module SwaggerClient
2
+ module Swagger
3
+ class Configuration
4
+ attr_accessor :format, :api_key, :api_key_prefix, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params, :user_agent, :verify_ssl
5
+
6
+ # Defaults go in here..
7
+ def initialize
8
+ @format = 'json'
9
+ @scheme = 'http'
10
+ @host = 'localhost:8080'
11
+ @base_path = '/'
12
+ @user_agent = "ruby-swagger-#{Swagger::VERSION}"
13
+ @inject_format = false
14
+ @force_ending_format = false
15
+ @camelize_params = true
16
+
17
+ # keys for API key authentication (param-name => api-key)
18
+ @api_key = {}
19
+ # api-key prefix for API key authentication, e.g. "Bearer" (param-name => api-key-prefix)
20
+ @api_key_prefix = {}
21
+
22
+ # whether to verify SSL certificate, default to true
23
+ # Note: do NOT set it to false in production code, otherwise you would
24
+ # face multiple types of cryptographic attacks
25
+ @verify_ssl = true
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,264 @@
1
+ module SwaggerClient
2
+ module Swagger
3
+ class Request
4
+ require 'uri'
5
+ require 'addressable/uri'
6
+ require 'typhoeus'
7
+
8
+ attr_accessor :host, :path, :format, :params, :body, :http_method, :headers, :form_params, :auth_names
9
+
10
+ # All requests must have an HTTP method and a path
11
+ # Optionals parameters are :params, :headers, :body, :format, :host
12
+ def initialize(http_method, path, attributes={})
13
+ attributes[:format] ||= Swagger.configuration.format
14
+ attributes[:params] ||= {}
15
+
16
+ # Set default headers
17
+ default_headers = {
18
+ 'Content-Type' => "application/#{attributes[:format].downcase}",
19
+ 'User-Agent' => Swagger.configuration.user_agent
20
+ }
21
+
22
+ # Merge argument headers into defaults
23
+ attributes[:headers] = default_headers.merge(attributes[:headers] || {})
24
+
25
+ # Stick in the auth token if there is one
26
+ if Swagger.authenticated?
27
+ attributes[:headers].merge!({:auth_token => Swagger.configuration.auth_token})
28
+ end
29
+
30
+ self.http_method = http_method.to_sym
31
+ self.path = path
32
+ attributes.each do |name, value|
33
+ send("#{name.to_s.underscore.to_sym}=", value)
34
+ end
35
+
36
+ update_params_for_auth!
37
+ end
38
+
39
+ # Update hearder and query params based on authentication settings.
40
+ def update_params_for_auth!
41
+ (@auth_names || []).each do |auth_name|
42
+
43
+ end
44
+ end
45
+
46
+ # Get API key (with prefix if set).
47
+ # @param [String] param_name the parameter name of API key auth
48
+ def get_api_key_with_prefix(param_name)
49
+ if Swagger.configuration.api_key_prefix[param_name].present?
50
+ "#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}"
51
+ else
52
+ Swagger.configuration.api_key[param_name]
53
+ end
54
+ end
55
+
56
+ # Construct a base URL
57
+ def url(options = {})
58
+ u = Addressable::URI.new(
59
+ :scheme => Swagger.configuration.scheme,
60
+ :host => Swagger.configuration.host,
61
+ :path => self.interpreted_path,
62
+ :query => self.query_string.sub(/\?/, '')
63
+ ).to_s
64
+
65
+ # Drop trailing question mark, if present
66
+ u.sub! /\?$/, ''
67
+
68
+ u
69
+ end
70
+
71
+ # Iterate over the params hash, injecting any path values into the path string
72
+ # e.g. /word.{format}/{word}/entries => /word.json/cat/entries
73
+ def interpreted_path
74
+ p = self.path.dup
75
+
76
+ # Stick a .{format} placeholder into the path if there isn't
77
+ # one already or an actual format like json or xml
78
+ # e.g. /words/blah => /words.{format}/blah
79
+ if Swagger.configuration.inject_format
80
+ unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
81
+ p = p.sub(/^(\/?\w+)/, "\\1.#{format}")
82
+ end
83
+ end
84
+
85
+ # Stick a .{format} placeholder on the end of the path if there isn't
86
+ # one already or an actual format like json or xml
87
+ # e.g. /words/blah => /words/blah.{format}
88
+ if Swagger.configuration.force_ending_format
89
+ unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
90
+ p = "#{p}.#{format}"
91
+ end
92
+ end
93
+
94
+ p = p.sub("{format}", self.format.to_s)
95
+
96
+ URI.encode [Swagger.configuration.base_path, p].join("/").gsub(/\/+/, '/')
97
+ end
98
+
99
+ # Massage the request body into a state of readiness
100
+ # If body is a hash, camelize all keys then convert to a json string
101
+ def body=(value)
102
+ if value.is_a?(Hash)
103
+ value = value.inject({}) do |memo, (k,v)|
104
+ memo[k.to_s.camelize(:lower).to_sym] = v
105
+ memo
106
+ end
107
+ end
108
+ @body = value
109
+ end
110
+
111
+ # If body is an object, JSONify it before making the actual request.
112
+ # For form parameters, remove empty value
113
+ def outgoing_body
114
+ # http form
115
+ if headers['Content-Type'] == 'application/x-www-form-urlencoded'
116
+ data = form_params.dup
117
+ data.each do |key, value|
118
+ data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
119
+ end
120
+ data
121
+ elsif @body # http body is JSON
122
+ @body.is_a?(String) ? @body : @body.to_json
123
+ else
124
+ nil
125
+ end
126
+ end
127
+
128
+ # Construct a query string from the query-string-type params
129
+ def query_string
130
+ # Iterate over all params,
131
+ # .. removing the ones that are part of the path itself.
132
+ # .. stringifying values so Addressable doesn't blow up.
133
+ query_values = {}
134
+ self.params.each_pair do |key, value|
135
+ next if self.path.include? "{#{key}}" # skip path params
136
+ next if value.blank? && value.class != FalseClass # skip empties
137
+ if Swagger.configuration.camelize_params
138
+ key = key.to_s.camelize(:lower).to_sym
139
+ end
140
+ query_values[key] = value.to_s
141
+ end
142
+
143
+ # We don't want to end up with '?' as our query string
144
+ # if there aren't really any params
145
+ return "" if query_values.blank?
146
+
147
+ # Addressable requires query_values to be set after initialization..
148
+ qs = Addressable::URI.new
149
+ qs.query_values = query_values
150
+ qs.to_s
151
+ end
152
+
153
+ def make
154
+ #TODO use configuration setting to determine if debugging
155
+ #logger = Logger.new STDOUT
156
+ #logger.debug self.url
157
+
158
+ request_options = {
159
+ :ssl_verifypeer => Swagger.configuration.verify_ssl,
160
+ :headers => self.headers.stringify_keys
161
+ }
162
+ response = case self.http_method.to_sym
163
+ when :get,:GET
164
+ Typhoeus::Request.get(
165
+ self.url,
166
+ request_options
167
+ )
168
+
169
+ when :post,:POST
170
+ Typhoeus::Request.post(
171
+ self.url,
172
+ request_options.merge(:body => self.outgoing_body)
173
+ )
174
+
175
+ when :patch,:PATCH
176
+ Typhoeus::Request.patch(
177
+ self.url,
178
+ request_options.merge(:body => self.outgoing_body)
179
+ )
180
+
181
+ when :put,:PUT
182
+ Typhoeus::Request.put(
183
+ self.url,
184
+ request_options.merge(:body => self.outgoing_body)
185
+ )
186
+
187
+ when :delete,:DELETE
188
+ Typhoeus::Request.delete(
189
+ self.url,
190
+ request_options.merge(:body => self.outgoing_body)
191
+ )
192
+ end
193
+ Response.new(response)
194
+ end
195
+
196
+ def response
197
+ self.make
198
+ end
199
+
200
+ def response_code_pretty
201
+ return unless @response.present?
202
+ @response.code.to_s
203
+ end
204
+
205
+ def response_headers_pretty
206
+ return unless @response.present?
207
+ # JSON.pretty_generate(@response.headers).gsub(/\n/, '<br/>') # <- This was for RestClient
208
+ @response.headers.gsub(/\n/, '<br/>') # <- This is for Typhoeus
209
+ end
210
+
211
+ # return 'Accept' based on an array of accept provided
212
+ # @param [Array] header_accept_array Array fo 'Accept'
213
+ # @return String Accept (e.g. application/json)
214
+ def self.select_header_accept header_accept_array
215
+ if header_accept_array.empty?
216
+ return
217
+ elsif header_accept_array.any?{ |s| s.casecmp('application/json')==0 }
218
+ 'application/json' # look for json data by default
219
+ else
220
+ header_accept_array.join(',')
221
+ end
222
+ end
223
+
224
+ # return the content type based on an array of content-type provided
225
+ # @param [Array] content_type_array Array fo content-type
226
+ # @return String Content-Type (e.g. application/json)
227
+ def self.select_header_content_type content_type_array
228
+ if content_type_array.empty?
229
+ 'application/json' # use application/json by default
230
+ elsif content_type_array.any?{ |s| s.casecmp('application/json')==0 }
231
+ 'application/json' # use application/json if it's included
232
+ else
233
+ content_type_array[0]; # otherwise, use the first one
234
+ end
235
+ end
236
+
237
+ # static method to convert object (array, hash, object, etc) to JSON string
238
+ # @param model object to be converted into JSON string
239
+ # @return string JSON string representation of the object
240
+ def self.object_to_http_body model
241
+ return if model.nil?
242
+ _body = nil
243
+ if model.is_a?(Array)
244
+ _body = model.map{|m| object_to_hash(m) }
245
+ else
246
+ _body = object_to_hash(model)
247
+ end
248
+ _body.to_json
249
+ end
250
+
251
+ # static method to convert object(non-array) to hash
252
+ # @param obj object to be converted into JSON string
253
+ # @return string JSON string representation of the object
254
+ def self.object_to_hash obj
255
+ if obj.respond_to?(:to_hash)
256
+ obj.to_hash
257
+ else
258
+ obj
259
+ end
260
+ end
261
+
262
+ end
263
+ end
264
+ end
@@ -0,0 +1,70 @@
1
+ module SwaggerClient
2
+ module Swagger
3
+ class Response
4
+ require 'json'
5
+
6
+ attr_accessor :raw
7
+
8
+ def initialize(raw)
9
+ self.raw = raw
10
+
11
+ case self.code
12
+ when 500..510 then raise(ServerError, self.error_message)
13
+ when 299..426 then raise(ClientError, self.error_message)
14
+ end
15
+ end
16
+
17
+ def code
18
+ raw.code
19
+ end
20
+
21
+ # Account for error messages that take different forms...
22
+ def error_message
23
+ body['message']
24
+ rescue
25
+ body
26
+ end
27
+
28
+ # If body is JSON, parse it
29
+ # Otherwise return raw string
30
+ def body
31
+ JSON.parse(raw.body, :symbolize_names => true)
32
+ rescue
33
+ raw.body
34
+ end
35
+
36
+ # `headers_hash` is a Typhoeus-specific extension of Hash,
37
+ # so simplify it back into a regular old Hash.
38
+ def headers
39
+ h = {}
40
+ raw.headers_hash.each {|k,v| h[k] = v }
41
+ h
42
+ end
43
+
44
+ # Extract the response format from the header hash
45
+ # e.g. {'Content-Type' => 'application/json'}
46
+ def format
47
+ headers['Content-Type'].split("/").last.downcase
48
+ end
49
+
50
+ def json?
51
+ format == 'json'
52
+ end
53
+
54
+ def xml?
55
+ format == 'xml'
56
+ end
57
+
58
+ def pretty_body
59
+ return unless body.present?
60
+ case format
61
+ when 'json' then JSON.pretty_generate(body).gsub(/\n/, '<br/>')
62
+ end
63
+ end
64
+
65
+ def pretty_headers
66
+ JSON.pretty_generate(headers).gsub(/\n/, '<br/>')
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module SwaggerClient
2
+ module Swagger
3
+ VERSION = "0.1.0"
4
+ end
5
+ end