tpaga 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ module Tpaga
2
+ #
3
+ class DaviPlataChargeback < BaseObject
4
+ attr_accessor :id, :davi_plata_charge, :davi_plata, :reimbursed
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ #
10
+ :'id' => :'id',
11
+
12
+ #
13
+ :'davi_plata_charge' => :'daviPlataCharge',
14
+
15
+ #
16
+ :'davi_plata' => :'daviPlata',
17
+
18
+ #
19
+ :'reimbursed' => :'reimbursed'
20
+
21
+ }
22
+ end
23
+
24
+ # attribute type
25
+ def self.swagger_types
26
+ {
27
+ :'id' => :'string',
28
+ :'davi_plata_charge' => :'string',
29
+ :'davi_plata' => :'string',
30
+ :'reimbursed' => :'boolean'
31
+
32
+ }
33
+ end
34
+
35
+ def initialize(attributes = {})
36
+ return if !attributes.is_a?(Hash) || attributes.empty?
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
40
+
41
+
42
+ if attributes[:'id']
43
+ @id = attributes[:'id']
44
+ end
45
+
46
+ if attributes[:'daviPlataCharge']
47
+ @davi_plata_charge = attributes[:'daviPlataCharge']
48
+ end
49
+
50
+ if attributes[:'daviPlata']
51
+ @davi_plata = attributes[:'daviPlata']
52
+ end
53
+
54
+ if attributes[:'reimbursed']
55
+ @reimbursed = attributes[:'reimbursed']
56
+ end
57
+
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,44 @@
1
+ module Tpaga
2
+ #
3
+ class DaviPlataVerification < BaseObject
4
+ attr_accessor :davi_plata, :pin_number
5
+ # attribute mapping from ruby-style variable name to JSON key
6
+ def self.attribute_map
7
+ {
8
+
9
+ #
10
+ :'davi_plata' => :'daviPlata',
11
+
12
+ #
13
+ :'pin_number' => :'pinNumber'
14
+
15
+ }
16
+ end
17
+
18
+ # attribute type
19
+ def self.swagger_types
20
+ {
21
+ :'davi_plata' => :'string',
22
+ :'pin_number' => :'string'
23
+
24
+ }
25
+ end
26
+
27
+ def initialize(attributes = {})
28
+ return if !attributes.is_a?(Hash) || attributes.empty?
29
+
30
+ # convert string to symbol for hash key
31
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
32
+
33
+
34
+ if attributes[:'daviPlata']
35
+ @davi_plata = attributes[:'daviPlata']
36
+ end
37
+
38
+ if attributes[:'pinNumber']
39
+ @pin_number = attributes[:'pinNumber']
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -87,4 +87,4 @@
87
87
  end
88
88
 
89
89
  end
90
- # end
90
+ # end
@@ -1,99 +1,76 @@
1
1
  require 'logger'
2
+ require 'json'
2
3
 
3
4
  module Tpaga
4
- module Swagger
5
-
6
- class << self
7
- attr_accessor :logger
8
-
9
- # A Swagger configuration object. Must act like a hash and return sensible
10
- # values for all Swagger configuration options. See Swagger::Configuration.
11
- attr_accessor :configuration
12
-
13
- attr_accessor :resources
14
-
15
- # Call this method to modify defaults in your initializers.
16
- #
17
- # @example
18
- # Swagger.configure do |config|
19
- # config.api_key = '1234567890abcdef' # required
20
- # config.username = 'wordlover' # optional, but needed for user-related functions
21
- # config.password = 'i<3words' # optional, but needed for user-related functions
22
- # config.format = 'json' # optional, defaults to 'json'
23
- # end
24
- #
25
- def configure
26
- self.configuration ||= Configuration.new
27
- yield(configuration) if block_given?
28
-
29
- # Configure logger. Default to use Rails
30
- self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
31
-
32
- # remove :// from scheme
33
- configuration.scheme.sub!(/:\/\//, '')
34
-
35
- # remove http(s):// and anything after a slash
36
- configuration.host.sub!(/https?:\/\//, '')
37
- configuration.host = configuration.host.split('/').first
38
-
39
- # Add leading and trailing slashes to base_path
40
- configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
41
- configuration.base_path = "" if configuration.base_path == "/"
42
- end
43
-
44
- def authenticated?
45
- Swagger.configuration.auth_token.present?
46
- end
47
-
48
- def de_authenticate
49
- Swagger.configuration.auth_token = nil
50
- end
51
-
52
- def authenticate
53
- return if Swagger.authenticated?
54
-
55
- if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
56
- raise ClientError, "Username and password are required to authenticate."
5
+ module Swagger
6
+ class << self
7
+ attr_accessor :logger
8
+
9
+ # A Swagger configuration object. Must act like a hash and return sensible
10
+ # values for all Swagger configuration options. See Swagger::Configuration.
11
+ attr_accessor :configuration
12
+
13
+ attr_accessor :resources
14
+
15
+ # Call this method to modify defaults in your initializers.
16
+ #
17
+ # @example
18
+ # Swagger.configure do |config|
19
+ # config.api_key = '1234567890abcdef' # api key authentication
20
+ # config.format = 'json' # optional, defaults to 'json'
21
+ # end
22
+ #
23
+ def configure
24
+ yield(configuration) if block_given?
25
+
26
+ # Configure logger. Default to use Rails
27
+ self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
28
+
29
+ # remove :// from scheme
30
+ configuration.scheme.sub!(/:\/\//, '')
31
+
32
+ # remove http(s):// and anything after a slash
33
+ configuration.host.sub!(/https?:\/\//, '')
34
+ configuration.host = configuration.host.split('/').first
35
+
36
+ # Add leading and trailing slashes to base_path
37
+ configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
38
+ configuration.base_path = "" if configuration.base_path == "/"
57
39
  end
58
-
59
- request = Swagger::Request.new(
60
- :get,
61
- "account/authenticate/{username}",
62
- :params => {
63
- :username => Swagger.configuration.username,
64
- :password => Swagger.configuration.password
65
- }
66
- )
67
-
68
- response_body = request.response.body
69
- Swagger.configuration.auth_token = response_body['token']
70
- end
71
40
 
72
- def to_body(obj)
73
- return nil if obj.nil?
74
- return obj.to_body if obj.respond_to? :to_body
75
- return obj.map{|x| to_body(x) } if obj.is_a? Array
76
- return obj
77
- end
41
+ def authenticated?
42
+ Swagger.configuration.auth_token.present?
43
+ end
78
44
 
79
- end
80
-
81
- end
45
+ def de_authenticate
46
+ Swagger.configuration.auth_token = nil
47
+ end
82
48
 
83
- class HTTPError < StandardError
84
- attr_accessor :response
49
+ def authenticate
50
+ return if Swagger.authenticated?
85
51
 
86
- def initialize(message = nil, response = nil)
87
- super(message)
88
- @response = response
89
- end
90
- end
52
+ if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
53
+ raise ClientError, "Username and password are required to authenticate."
54
+ end
91
55
 
92
- class ServerError < HTTPError
93
- end
56
+ request = Swagger::Request.new(
57
+ :get,
58
+ "account/authenticate/{username}",
59
+ :params => {
60
+ :username => Swagger.configuration.username,
61
+ :password => Swagger.configuration.password
62
+ }
63
+ )
94
64
 
95
- class ClientError < HTTPError
96
- end
65
+ response_body = request.response.body
66
+ Swagger.configuration.auth_token = response_body['token']
67
+ end
68
+ end
69
+ end
97
70
 
98
- end
71
+ class ServerError < StandardError
72
+ end
99
73
 
74
+ class ClientError < StandardError
75
+ end
76
+ end
@@ -1,32 +1,29 @@
1
1
  module Tpaga
2
- module Swagger
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
3
5
 
4
- class Configuration
5
-
6
- attr_accessor :format, :api_key, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params, :api_key_type, :api_key_name, :api_key_prefix
7
-
8
- # Defaults go in here..
9
- def initialize
10
- @format = 'json'
11
- @scheme = 'https'
12
- @host = 'api.tpaga.co.local:8443'
13
- @base_path = '/api'
14
- @user_agent = 'Swagger/Ruby/0.0.2/dev'
15
- @inject_format = false
16
- @force_ending_format = false
17
- @camelize_params = false
18
- # for API key/token authentication
19
- @api_key = '';
20
- @api_key_type = '';
21
- @api_key_name = '';
22
- @api_key_prefix = '';
23
- # for http basic authentication
24
- @username = ''
25
- @password = ''
26
- end
6
+ # Defaults go in here..
7
+ def initialize
8
+ @format = 'json'
9
+ @scheme = 'https'
10
+ @host = 'sandbox.tpaga.co'
11
+ @base_path = '/api'
12
+ @user_agent = "ruby-swagger-#{Swagger::VERSION}"
13
+ @inject_format = false
14
+ @force_ending_format = false
15
+ @camelize_params = true
27
16
 
28
- end
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 = {}
29
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
30
29
  end
31
- end
32
-
@@ -1,215 +1,270 @@
1
1
  module Tpaga
2
- module Swagger
3
-
4
- class Request
5
- require 'uri'
6
- require 'addressable/uri'
7
- require 'typhoeus'
8
-
9
- attr_accessor :host, :path, :format, :params, :body, :http_method, :headers, :form_params
10
-
11
-
12
- # All requests must have an HTTP method and a path
13
- # Optionals parameters are :params, :headers, :body, :format, :host
14
- #
15
- def initialize(http_method, path, attributes={})
16
- # initialize Swagger configuraiton if it has not been done so
17
- Swagger.configure if Swagger.configuration.nil?
18
-
19
- attributes[:format] ||= Swagger.configuration.format
20
- attributes[:params] ||= {}
21
-
22
- # set authentication based on configuration setting
23
- if attributes[:require_auth]
24
- case Swagger.configuration.api_key_type
25
- when 'header' # API key in http header
26
- # only header supports prefix
27
- if Swagger.configuration.api_key_prefix.present?
28
- attributes[:headers][Swagger.configuration.api_key_name] = "#{Swagger.configuration.api_key_prefix} #{Swagger.configuration.api_key}"
29
- else
30
- attributes[:headers][Swagger.configuration.api_key_name] = Swagger.configuration.api_key
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
+ case auth_name
43
+ when 'api_key'
44
+ @headers ||= {}
45
+ http_auth_header = 'Basic ' + ["#{Swagger.configuration.api_key}:"].pack('m').delete("\r\n")
46
+ @headers['Authorization'] = http_auth_header
47
+
31
48
  end
32
- when 'query' # API key in url query
33
- attributes[:params][Swagger.configuration.api_key_name] = Swagger.configuration.api_key
49
+ end
50
+ end
51
+
52
+ # Get API key (with prefix if set).
53
+ # @param [String] param_name the parameter name of API key auth
54
+ def get_api_key_with_prefix(param_name)
55
+ if Swagger.configuration.api_key_prefix[param_name].present?
56
+ "#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}"
34
57
  else
35
- unless Swagger.configuration.api_key.blank?
36
- # HTTP basic
37
- http_auth_header = 'Basic ' + ["#{Swagger.configuration.api_key}:"].pack('m').delete("\r\n")
38
- attributes[:headers]['Authorization'] = http_auth_header
39
- else
40
- # throw error before sending the request to server
58
+ Swagger.configuration.api_key[param_name]
59
+ end
60
+ end
61
+
62
+ # Construct a base URL
63
+ def url(options = {})
64
+ u = Addressable::URI.new(
65
+ :scheme => Swagger.configuration.scheme,
66
+ :host => Swagger.configuration.host,
67
+ :path => self.interpreted_path,
68
+ :query => self.query_string.sub(/\?/, '')
69
+ ).to_s
70
+
71
+ # Drop trailing question mark, if present
72
+ u.sub! /\?$/, ''
73
+
74
+ u
75
+ end
76
+
77
+ # Iterate over the params hash, injecting any path values into the path string
78
+ # e.g. /word.{format}/{word}/entries => /word.json/cat/entries
79
+ def interpreted_path
80
+ p = self.path.dup
81
+
82
+ # Stick a .{format} placeholder into the path if there isn't
83
+ # one already or an actual format like json or xml
84
+ # e.g. /words/blah => /words.{format}/blah
85
+ if Swagger.configuration.inject_format
86
+ unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
87
+ p = p.sub(/^(\/?\w+)/, "\\1.#{format}")
88
+ end
89
+ end
90
+
91
+ # Stick a .{format} placeholder on the end of the path if there isn't
92
+ # one already or an actual format like json or xml
93
+ # e.g. /words/blah => /words/blah.{format}
94
+ if Swagger.configuration.force_ending_format
95
+ unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
96
+ p = "#{p}.#{format}"
41
97
  end
42
98
  end
99
+
100
+ p = p.sub("{format}", self.format.to_s)
101
+
102
+ URI.encode [Swagger.configuration.base_path, p].join("/").gsub(/\/+/, '/')
43
103
  end
44
104
 
45
- self.http_method = http_method.to_sym
46
- self.path = path
47
- attributes.each do |name, value|
48
- #send("#{name.to_s.underscore.to_sym}=", value)
49
- attr = name.to_s.underscore.to_sym
50
- send("#{attr}=", value) if respond_to? attr
105
+ # Massage the request body into a state of readiness
106
+ # If body is a hash, camelize all keys then convert to a json string
107
+ def body=(value)
108
+ if value.is_a?(Hash)
109
+ value = value.inject({}) do |memo, (k,v)|
110
+ memo[k.to_s.camelize(:lower).to_sym] = v
111
+ memo
112
+ end
113
+ end
114
+ @body = value
51
115
  end
52
- end
53
116
 
54
- # Construct a base URL
55
- #
56
- def url(options = {})
57
- u = Addressable::URI.new(
58
- :scheme => Swagger.configuration.scheme,
59
- :host => Swagger.configuration.host,
60
- :path => self.interpreted_path,
61
- :query => self.query_string.sub(/\?/, '')
62
- ).to_s
63
-
64
- # Drop trailing question mark, if present
65
- u.sub! /\?$/, ''
66
-
67
- # no longer needed as we no longer support obfuscated
68
- ## Obfuscate API key?
69
- #u.sub! /api\_key=\w+/, 'api_key=YOUR_API_KEY' if options[:obfuscated]
70
-
71
- u
72
- end
117
+ # If body is an object, JSONify it before making the actual request.
118
+ # For form parameters, remove empty value
119
+ def outgoing_body
120
+ # http form
121
+ if headers['Content-Type'] == 'application/x-www-form-urlencoded'
122
+ data = form_params.dup
123
+ data.each do |key, value|
124
+ data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
125
+ end
126
+ data
127
+ elsif @body # http body is JSON
128
+ @body.is_a?(String) ? @body : @body.to_json
129
+ else
130
+ nil
131
+ end
132
+ end
73
133
 
74
- # Iterate over the params hash, injecting any path values into the path string
75
- #
76
- # e.g. /word.{format}/{word}/entries => /word.json/cat/entries
77
- def interpreted_path
78
- p = self.path.dup
134
+ # Construct a query string from the query-string-type params
135
+ def query_string
136
+ # Iterate over all params,
137
+ # .. removing the ones that are part of the path itself.
138
+ # .. stringifying values so Addressable doesn't blow up.
139
+ query_values = {}
140
+ self.params.each_pair do |key, value|
141
+ next if self.path.include? "{#{key}}" # skip path params
142
+ next if value.blank? && value.class != FalseClass # skip empties
143
+ if Swagger.configuration.camelize_params
144
+ key = key.to_s.camelize(:lower).to_sym
145
+ end
146
+ query_values[key] = value.to_s
147
+ end
79
148
 
80
- # Fill in the path params
81
- self.params.each_pair do |key, value|
82
- p = p.gsub("{#{key}}", value.to_s)
149
+ # We don't want to end up with '?' as our query string
150
+ # if there aren't really any params
151
+ return "" if query_values.blank?
152
+
153
+ # Addressable requires query_values to be set after initialization..
154
+ qs = Addressable::URI.new
155
+ qs.query_values = query_values
156
+ qs.to_s
83
157
  end
84
158
 
85
- # Stick a .{format} placeholder into the path if there isn't
86
- # one already or an actual format like json or xml
87
- # e.g. /words/blah => /words.{format}/blah
88
- if Swagger.configuration.inject_format
89
- unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
90
- p = p.sub(/^(\/?\w+)/, "\\1.#{format}")
159
+ def make
160
+ #TODO use configuration setting to determine if debugging
161
+ #logger = Logger.new STDOUT
162
+ #logger.debug self.url
163
+
164
+ request_options = {
165
+ :ssl_verifypeer => Swagger.configuration.verify_ssl,
166
+ :headers => self.headers.stringify_keys
167
+ }
168
+ response = case self.http_method.to_sym
169
+ when :get,:GET
170
+ Typhoeus::Request.get(
171
+ self.url,
172
+ request_options
173
+ )
174
+
175
+ when :post,:POST
176
+ Typhoeus::Request.post(
177
+ self.url,
178
+ request_options.merge(:body => self.outgoing_body)
179
+ )
180
+
181
+ when :patch,:PATCH
182
+ Typhoeus::Request.patch(
183
+ self.url,
184
+ request_options.merge(:body => self.outgoing_body)
185
+ )
186
+
187
+ when :put,:PUT
188
+ Typhoeus::Request.put(
189
+ self.url,
190
+ request_options.merge(:body => self.outgoing_body)
191
+ )
192
+
193
+ when :delete,:DELETE
194
+ Typhoeus::Request.delete(
195
+ self.url,
196
+ request_options.merge(:body => self.outgoing_body)
197
+ )
91
198
  end
199
+ Response.new(response)
92
200
  end
93
201
 
94
- # Stick a .{format} placeholder on the end of the path if there isn't
95
- # one already or an actual format like json or xml
96
- # e.g. /words/blah => /words/blah.{format}
97
- if Swagger.configuration.force_ending_format
98
- unless ['.json', '.xml', '{format}'].any? {|s| p.downcase.include? s }
99
- p = "#{p}.#{format}"
202
+ def response
203
+ self.make
204
+ end
205
+
206
+ def response_code_pretty
207
+ return unless @response.present?
208
+ @response.code.to_s
209
+ end
210
+
211
+ def response_headers_pretty
212
+ return unless @response.present?
213
+ # JSON.pretty_generate(@response.headers).gsub(/\n/, '<br/>') # <- This was for RestClient
214
+ @response.headers.gsub(/\n/, '<br/>') # <- This is for Typhoeus
215
+ end
216
+
217
+ # return 'Accept' based on an array of accept provided
218
+ # @param [Array] header_accept_array Array fo 'Accept'
219
+ # @return String Accept (e.g. application/json)
220
+ def self.select_header_accept header_accept_array
221
+ if header_accept_array.empty?
222
+ return
223
+ elsif header_accept_array.any?{ |s| s.casecmp('application/json')==0 }
224
+ 'application/json' # look for json data by default
225
+ else
226
+ header_accept_array.join(',')
100
227
  end
101
228
  end
102
229
 
103
- p = p.sub("{format}", self.format.to_s)
104
-
105
- URI.encode [Swagger.configuration.base_path, p].join("/").gsub(/\/+/, '/')
106
- end
107
-
108
- # Massage the request body into a state of readiness
109
- # If body is a hash, camelize all keys then convert to a json string
110
- #
111
- def body=(value)
112
- #comment: no need to use camelize keys
113
- #if value.is_a?(Hash)
114
- # value = value.inject({}) do |memo, (k,v)|
115
- # memo[k.to_s.camelize(:lower).to_sym] = v
116
- # memo
117
- # end
118
- #end
119
- @body = value
120
- end
121
-
122
- # If body is an object, JSONify it before making the actual request.
123
- #
124
- def outgoing_body
125
- if @body.nil? && @form_params && !@form_params.empty?
126
- data = form_params.dup
127
- data.each do |key, value|
128
- data[key] = value.to_s if value && !value.is_a?(File)
230
+ # return the content type based on an array of content-type provided
231
+ # @param [Array] content_type_array Array fo content-type
232
+ # @return String Content-Type (e.g. application/json)
233
+ def self.select_header_content_type content_type_array
234
+ if content_type_array.empty?
235
+ 'application/json' # use application/json by default
236
+ elsif content_type_array.any?{ |s| s.casecmp('application/json')==0 }
237
+ 'application/json' # use application/json if it's included
238
+ else
239
+ content_type_array[0]; # otherwise, use the first one
129
240
  end
130
- data
131
- else
132
- @body.is_a?(String) ? @body : @body.to_json
133
- end
134
- end
135
-
136
- # Construct a query string from the query-string-type params
137
- def query_string
138
-
139
- # Iterate over all params,
140
- # .. removing the ones that are part of the path itself.
141
- # .. stringifying values so Addressable doesn't blow up.
142
- query_values = {}
143
- self.params.each_pair do |key, value|
144
- next if self.path.include? "{#{key}}" # skip path params
145
- next if value.blank? && value.class != FalseClass # skip empties
146
-
147
- # no longer support Swagger.configuration.camelize_params
148
- #if Swagger.configuration.camelize_params
149
- # key = key.to_s.camelize(:lower).to_sym unless key.to_sym == :api_key # api_key is not a camelCased param
150
- #end
151
-
152
- query_values[key] = value.to_s
153
- end
154
-
155
- # We don't want to end up with '?' as our query string
156
- # if there aren't really any params
157
- return "" if query_values.blank?
158
-
159
- # Addressable requires query_values to be set after initialization..
160
- qs = Addressable::URI.new
161
- qs.query_values = query_values
162
- qs.to_s
163
- end
164
-
165
- def make
166
- response = case self.http_method.to_sym
167
- when :get,:GET
168
- Typhoeus::Request.get(
169
- self.url,
170
- :headers => self.headers.stringify_keys,
171
- )
172
-
173
- when :post,:POST
174
- Typhoeus::Request.post(
175
- self.url,
176
- :body => self.outgoing_body,
177
- :headers => self.headers.stringify_keys,
178
- )
179
-
180
- when :put,:PUT
181
- Typhoeus::Request.put(
182
- self.url,
183
- :body => self.outgoing_body,
184
- :headers => self.headers.stringify_keys,
185
- )
186
-
187
- when :delete,:DELETE
188
- Typhoeus::Request.delete(
189
- self.url,
190
- :body => self.outgoing_body,
191
- :headers => self.headers.stringify_keys,
192
- )
193
- end
194
- Response.new(response)
195
- end
196
-
197
- def response
198
- self.make
199
- end
200
-
201
- def response_code_pretty
202
- return unless @response.present?
203
- @response.code.to_s
204
- end
205
-
206
- def response_headers_pretty
207
- return unless @response.present?
208
- # JSON.pretty_generate(@response.headers).gsub(/\n/, '<br/>') # <- This was for RestClient
209
- @response.headers.gsub(/\n/, '<br/>') # <- This is for Typhoeus
210
- end
241
+ end
242
+
243
+ # static method to convert object (array, hash, object, etc) to JSON string
244
+ # @param model object to be converted into JSON string
245
+ # @return string JSON string representation of the object
246
+ def self.object_to_http_body model
247
+ return if model.nil?
248
+ _body = nil
249
+ if model.is_a?(Array)
250
+ _body = model.map{|m| object_to_hash(m) }
251
+ else
252
+ _body = object_to_hash(model)
253
+ end
254
+ _body.to_json
255
+ end
211
256
 
257
+ # static method to convert object(non-array) to hash
258
+ # @param obj object to be converted into JSON string
259
+ # @return string JSON string representation of the object
260
+ def self.object_to_hash obj
261
+ if obj.respond_to?(:to_hash)
262
+ obj.to_hash
263
+ else
264
+ obj
265
+ end
266
+ end
267
+
268
+ end
212
269
  end
213
270
  end
214
- end
215
-