dwolla_swagger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/dwolla_swagger.gemspec +32 -0
- data/lib/dwolla_swagger/api/accounts_api.rb +54 -0
- data/lib/dwolla_swagger/api/customers_api.rb +223 -0
- data/lib/dwolla_swagger/api/documents_api.rb +54 -0
- data/lib/dwolla_swagger/api/events_api.rb +98 -0
- data/lib/dwolla_swagger/api/fundingsources_api.rb +231 -0
- data/lib/dwolla_swagger/api/transfers_api.rb +143 -0
- data/lib/dwolla_swagger/api/webhooks_api.rb +190 -0
- data/lib/dwolla_swagger/api/webhooksubscriptions_api.rb +179 -0
- data/lib/dwolla_swagger/models/account_info.rb +62 -0
- data/lib/dwolla_swagger/models/amount.rb +44 -0
- data/lib/dwolla_swagger/models/application_event.rb +86 -0
- data/lib/dwolla_swagger/models/base_object.rb +84 -0
- data/lib/dwolla_swagger/models/create_customer.rb +132 -0
- data/lib/dwolla_swagger/models/create_funding_source_request.rb +60 -0
- data/lib/dwolla_swagger/models/create_webhook.rb +44 -0
- data/lib/dwolla_swagger/models/customer.rb +102 -0
- data/lib/dwolla_swagger/models/customer_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/document.rb +78 -0
- data/lib/dwolla_swagger/models/document_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/event_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/funding_source.rb +96 -0
- data/lib/dwolla_swagger/models/funding_source_list_response.rb +46 -0
- data/lib/dwolla_swagger/models/hal_link.rb +44 -0
- data/lib/dwolla_swagger/models/money.rb +44 -0
- data/lib/dwolla_swagger/models/transfer.rb +86 -0
- data/lib/dwolla_swagger/models/transfer_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/transfer_request_body.rb +54 -0
- data/lib/dwolla_swagger/models/unit__.rb +28 -0
- data/lib/dwolla_swagger/models/webhook.rb +96 -0
- data/lib/dwolla_swagger/models/webhook_attempt.rb +52 -0
- data/lib/dwolla_swagger/models/webhook_event_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/webhook_header.rb +44 -0
- data/lib/dwolla_swagger/models/webhook_http_request.rb +62 -0
- data/lib/dwolla_swagger/models/webhook_http_response.rb +62 -0
- data/lib/dwolla_swagger/models/webhook_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/webhook_retry.rb +70 -0
- data/lib/dwolla_swagger/models/webhook_retry_request_list_response.rb +54 -0
- data/lib/dwolla_swagger/models/webhook_subscription.rb +70 -0
- data/lib/dwolla_swagger/monkey.rb +90 -0
- data/lib/dwolla_swagger/swagger/configuration.rb +29 -0
- data/lib/dwolla_swagger/swagger/request.rb +264 -0
- data/lib/dwolla_swagger/swagger/response.rb +70 -0
- data/lib/dwolla_swagger/swagger/version.rb +5 -0
- data/lib/dwolla_swagger/swagger.rb +78 -0
- data/lib/dwolla_swagger.rb +54 -0
- metadata +294 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
module DwollaSwagger
|
2
|
+
#
|
3
|
+
class WebhookListResponse < BaseObject
|
4
|
+
attr_accessor :_links, :_embedded, :total
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
#
|
10
|
+
:'_links' => :'_links',
|
11
|
+
|
12
|
+
#
|
13
|
+
:'_embedded' => :'_embedded',
|
14
|
+
|
15
|
+
#
|
16
|
+
:'total' => :'total'
|
17
|
+
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# attribute type
|
22
|
+
def self.swagger_types
|
23
|
+
{
|
24
|
+
:'_links' => :'map[string,HalLink]',
|
25
|
+
:'_embedded' => :'object',
|
26
|
+
:'total' => :'int'
|
27
|
+
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(attributes = {})
|
32
|
+
return if !attributes.is_a?(Hash) || attributes.empty?
|
33
|
+
|
34
|
+
# convert string to symbol for hash key
|
35
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
36
|
+
|
37
|
+
|
38
|
+
if attributes[:'_links']
|
39
|
+
if (value = attributes[:'_links']).is_a?(Array)
|
40
|
+
@_links = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if attributes[:'_embedded']
|
45
|
+
@_embedded = attributes[:'_embedded']
|
46
|
+
end
|
47
|
+
|
48
|
+
if attributes[:'total']
|
49
|
+
@total = attributes[:'total']
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module DwollaSwagger
|
2
|
+
#
|
3
|
+
class WebhookRetry < BaseObject
|
4
|
+
attr_accessor :_links, :_embedded, :id, :time_stamp, :hook_id
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
#
|
10
|
+
:'_links' => :'_links',
|
11
|
+
|
12
|
+
#
|
13
|
+
:'_embedded' => :'_embedded',
|
14
|
+
|
15
|
+
#
|
16
|
+
:'id' => :'id',
|
17
|
+
|
18
|
+
#
|
19
|
+
:'time_stamp' => :'timeStamp',
|
20
|
+
|
21
|
+
#
|
22
|
+
:'hook_id' => :'hookId'
|
23
|
+
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# attribute type
|
28
|
+
def self.swagger_types
|
29
|
+
{
|
30
|
+
:'_links' => :'map[string,HalLink]',
|
31
|
+
:'_embedded' => :'object',
|
32
|
+
:'id' => :'string',
|
33
|
+
:'time_stamp' => :'DateTime',
|
34
|
+
:'hook_id' => :'string'
|
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[:'_links']
|
47
|
+
if (value = attributes[:'_links']).is_a?(Array)
|
48
|
+
@_links = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if attributes[:'_embedded']
|
53
|
+
@_embedded = attributes[:'_embedded']
|
54
|
+
end
|
55
|
+
|
56
|
+
if attributes[:'id']
|
57
|
+
@id = attributes[:'id']
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes[:'timeStamp']
|
61
|
+
@time_stamp = attributes[:'timeStamp']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes[:'hookId']
|
65
|
+
@hook_id = attributes[:'hookId']
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module DwollaSwagger
|
2
|
+
#
|
3
|
+
class WebhookRetryRequestListResponse < BaseObject
|
4
|
+
attr_accessor :_links, :_embedded, :total
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
#
|
10
|
+
:'_links' => :'_links',
|
11
|
+
|
12
|
+
#
|
13
|
+
:'_embedded' => :'_embedded',
|
14
|
+
|
15
|
+
#
|
16
|
+
:'total' => :'total'
|
17
|
+
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
# attribute type
|
22
|
+
def self.swagger_types
|
23
|
+
{
|
24
|
+
:'_links' => :'map[string,HalLink]',
|
25
|
+
:'_embedded' => :'object',
|
26
|
+
:'total' => :'int'
|
27
|
+
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(attributes = {})
|
32
|
+
return if !attributes.is_a?(Hash) || attributes.empty?
|
33
|
+
|
34
|
+
# convert string to symbol for hash key
|
35
|
+
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
36
|
+
|
37
|
+
|
38
|
+
if attributes[:'_links']
|
39
|
+
if (value = attributes[:'_links']).is_a?(Array)
|
40
|
+
@_links = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
if attributes[:'_embedded']
|
45
|
+
@_embedded = attributes[:'_embedded']
|
46
|
+
end
|
47
|
+
|
48
|
+
if attributes[:'total']
|
49
|
+
@total = attributes[:'total']
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module DwollaSwagger
|
2
|
+
#
|
3
|
+
class WebhookSubscription < BaseObject
|
4
|
+
attr_accessor :_links, :_embedded, :id, :url, :created
|
5
|
+
# attribute mapping from ruby-style variable name to JSON key
|
6
|
+
def self.attribute_map
|
7
|
+
{
|
8
|
+
|
9
|
+
#
|
10
|
+
:'_links' => :'_links',
|
11
|
+
|
12
|
+
#
|
13
|
+
:'_embedded' => :'_embedded',
|
14
|
+
|
15
|
+
#
|
16
|
+
:'id' => :'id',
|
17
|
+
|
18
|
+
#
|
19
|
+
:'url' => :'url',
|
20
|
+
|
21
|
+
#
|
22
|
+
:'created' => :'created'
|
23
|
+
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# attribute type
|
28
|
+
def self.swagger_types
|
29
|
+
{
|
30
|
+
:'_links' => :'map[string,HalLink]',
|
31
|
+
:'_embedded' => :'object',
|
32
|
+
:'id' => :'string',
|
33
|
+
:'url' => :'string',
|
34
|
+
:'created' => :'DateTime'
|
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[:'_links']
|
47
|
+
if (value = attributes[:'_links']).is_a?(Array)
|
48
|
+
@_links = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if attributes[:'_embedded']
|
53
|
+
@_embedded = attributes[:'_embedded']
|
54
|
+
end
|
55
|
+
|
56
|
+
if attributes[:'id']
|
57
|
+
@id = attributes[:'id']
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes[:'url']
|
61
|
+
@url = attributes[:'url']
|
62
|
+
end
|
63
|
+
|
64
|
+
if attributes[:'created']
|
65
|
+
@created = attributes[:'created']
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -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 DwollaSwagger
|
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 = 'https'
|
10
|
+
@host = ''
|
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 DwollaSwagger
|
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
|
+
self.http_method = http_method.to_sym
|
26
|
+
self.path = path
|
27
|
+
attributes.each do |name, value|
|
28
|
+
send("#{name.to_s.underscore.to_sym}=", value)
|
29
|
+
end
|
30
|
+
|
31
|
+
update_params_for_auth!
|
32
|
+
end
|
33
|
+
|
34
|
+
# Update hearder and query params based on authentication settings.
|
35
|
+
def update_params_for_auth!
|
36
|
+
(@auth_names || []).each do |auth_name|
|
37
|
+
case auth_name
|
38
|
+
when 'oauth2'
|
39
|
+
|
40
|
+
@headers.merge!({:Authorization => "Bearer #{Swagger.configuration.auth_token}"})
|
41
|
+
|
42
|
+
end
|
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
|