openapi 0.9.8 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/Rakefile +3 -8
- data/lib/openapi/auth_token.rb +1 -1
- data/lib/openapi/client.rb +26 -22
- data/lib/openapi/handlers/hashie.rb +15 -0
- data/lib/openapi/handlers/raw.rb +0 -3
- data/lib/openapi/handlers.rb +1 -1
- data/lib/openapi/models/response.rb +5 -0
- data/lib/openapi/models.rb +3 -7
- data/lib/openapi/route.rb +19 -78
- data/lib/openapi/version.rb +1 -1
- data/lib/openapi.rb +1 -2
- metadata +10 -14
- data/License +0 -20
- data/lib/openapi/handlers/array.rb +0 -44
- data/lib/openapi/handlers/dummy.rb +0 -31
- data/lib/openapi/handlers/model.rb +0 -30
- data/lib/openapi/models/base.rb +0 -16
- data/lib/openapi/utils.rb +0 -52
- data/lib/openapi/validators.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64d9861b06ef5838fafa2c28d4d807e54f013469
|
4
|
+
data.tar.gz: 70d6c3028ef631acff79cf6d50f823cc6b85e1e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87d5b5f0f03932b351bbb317f6cd58f76360b0baaeb06b4b51e50bf52a2ca05c92d180281c8d0a6e1cb05c1e6fd65452beaf3ca3d756b9dd7b7a306cad3a6124
|
7
|
+
data.tar.gz: 327520510456ba0423a0be6852f12458a676859cb87403533083a73426ac3d864de8e5f3cfe7dfb3283b718d684661aa64ba20a11568dcc9983d264b35325818
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Antoine Legrand
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
RSpec::Core::RakeTask.new do |t|
|
6
|
-
t.rspec_opts = ['-c', '-f progress', '-r ./spec/spec_helper.rb']
|
7
|
-
t.pattern = 'spec/**/*_spec.rb'
|
8
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
Dir.glob('tasks/*.rake').each { |r| import r }
|
data/lib/openapi/auth_token.rb
CHANGED
data/lib/openapi/client.rb
CHANGED
@@ -16,7 +16,7 @@ module OpenAPI
|
|
16
16
|
|
17
17
|
module ClassMethods
|
18
18
|
attr_accessor :application_key, :application_secret, :max_retry,
|
19
|
-
:logger, :request_timeout, :client_id, :site, :auth_token, :
|
19
|
+
:logger, :request_timeout, :client_id, :site, :auth_token, :api_methods, :use_ssl, :cache
|
20
20
|
|
21
21
|
def api_methods
|
22
22
|
@api_methods ||= []
|
@@ -37,15 +37,15 @@ module OpenAPI
|
|
37
37
|
response = OpenAPI::Response.wrap(response)
|
38
38
|
return response
|
39
39
|
end
|
40
|
-
rescue Timeout::Error
|
40
|
+
rescue Timeout::Error => e
|
41
41
|
unless logger.nil?
|
42
|
-
logger.error "
|
42
|
+
logger.error "Request timed out after #{request_timeout} seconds: [#{request.path} #{request.body}]"
|
43
43
|
end
|
44
|
-
|
44
|
+
raise e
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_path(path, params=nil)
|
48
|
-
uri = URI("/#{
|
48
|
+
uri = URI("/#{path}")
|
49
49
|
if params != nil
|
50
50
|
uri.query = URI.encode_www_form(params)
|
51
51
|
end
|
@@ -56,19 +56,23 @@ module OpenAPI
|
|
56
56
|
raise NotImplementedError
|
57
57
|
end
|
58
58
|
|
59
|
-
def do_request(http_method, path,
|
60
|
-
path = build_path(path,
|
61
|
-
|
59
|
+
def do_request(http_method, path, params: {}, body: nil, headers: {}, options: {})
|
60
|
+
path = build_path(path, params)
|
62
61
|
klass = Net::HTTP.const_get(http_method.to_s.capitalize)
|
63
62
|
request = klass.new(path.to_s)
|
64
|
-
request.add_field "Content-Type",
|
65
|
-
|
66
|
-
|
63
|
+
request.add_field "Content-Type", headers["Content-Type"] || "application/json"
|
64
|
+
|
65
|
+
if options[:skip_auth] != true && !auth_token.nil?
|
66
|
+
auth_token.headers.each do |k,v|
|
67
|
+
request.add_field k, v
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
request.add_field "Accept", headers["Accept"] || "application/json"
|
72
|
+
headers.each do |h,v|
|
73
|
+
request.add_field h, v
|
67
74
|
end
|
68
|
-
request.
|
69
|
-
#Authorization: Basic dWJ1ZHUtYXBpOmZHWTI4aypOZTh2YzA=
|
70
|
-
#Authorization: Bearer
|
71
|
-
request.body = options[:body] if options[:body]
|
75
|
+
request.body = body if body.present?
|
72
76
|
response = call_api(request)
|
73
77
|
return response
|
74
78
|
end
|
@@ -83,7 +87,12 @@ module OpenAPI
|
|
83
87
|
end
|
84
88
|
|
85
89
|
def http_client
|
86
|
-
|
90
|
+
uri = URI(site)
|
91
|
+
client = Net::HTTP.new(uri.hostname, uri.port)
|
92
|
+
if uri.scheme == "https"
|
93
|
+
client.tap{|http| http.use_ssl = true}
|
94
|
+
end
|
95
|
+
return client
|
87
96
|
end
|
88
97
|
|
89
98
|
def log_request_and_response(request, response, time)
|
@@ -103,11 +112,7 @@ module OpenAPI
|
|
103
112
|
@request_timeout || 5.0
|
104
113
|
end
|
105
114
|
|
106
|
-
|
107
|
-
@api_version || "v1"
|
108
|
-
end
|
109
|
-
|
110
|
-
def logger
|
115
|
+
def logger
|
111
116
|
@logger ||= OpenAPI.logger
|
112
117
|
end
|
113
118
|
|
@@ -124,7 +129,6 @@ module OpenAPI
|
|
124
129
|
include ClassMethods
|
125
130
|
|
126
131
|
def initialize(options={})
|
127
|
-
@api_version = options[:api_version] || OpenAPI.api_version
|
128
132
|
@logger = options[:logger] || OpenAPI.logger
|
129
133
|
@application_key = options[:application_key] || OpenAPI.application_key
|
130
134
|
@application_secret = options[:application_secret] || OpenAPI.application_secret
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module OpenAPI
|
2
|
+
module Handlers
|
3
|
+
class Hashie < OpenAPI::Handler
|
4
|
+
class << self
|
5
|
+
def hashie(snake_name, response, options)
|
6
|
+
return self.failed(response) if not response.success?
|
7
|
+
klass_name = snake_name.camelize
|
8
|
+
hash = JSON.parse(response.raw)
|
9
|
+
resp = Payplug::Model::Response.new(hash)
|
10
|
+
return OpenAPI::Handlers::Response.wrap(resp, response)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/openapi/handlers/raw.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require File.join(File.dirname(__FILE__), '../models')
|
3
1
|
module OpenAPI
|
4
2
|
module Handlers
|
5
3
|
class Raw < OpenAPI::Handler
|
6
4
|
class << self
|
7
|
-
|
8
5
|
def text(response, options)
|
9
6
|
return self.failed(response) if not response.success?
|
10
7
|
return response
|
data/lib/openapi/handlers.rb
CHANGED
@@ -2,7 +2,7 @@ module OpenAPI
|
|
2
2
|
class Handler
|
3
3
|
def self.failed(response)
|
4
4
|
# error = OpenAPI::Models::Error.new().from_json(response.raw)
|
5
|
-
model =
|
5
|
+
model = OpenAPI::Handlers::Response.wrap(response.raw, response)
|
6
6
|
return model
|
7
7
|
end
|
8
8
|
end
|
data/lib/openapi/models.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require 'simplemodel'
|
2
|
-
require 'active_model'
|
3
1
|
$:.unshift(File.dirname(__FILE__))
|
4
2
|
module OpenAPI
|
5
|
-
module
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
autoload :Base, "models/base"
|
3
|
+
module Model
|
4
|
+
autoload :Response, "models/response"
|
5
|
+
|
10
6
|
end
|
11
7
|
end
|
data/lib/openapi/route.rb
CHANGED
@@ -5,81 +5,29 @@ module OpenAPI
|
|
5
5
|
# match '/track_coupon/:source/:id' => 'mobile_banner#track_coupon', :as_ => :track_coupon, :defaults => { :format => 'png' }
|
6
6
|
module ClassMethods
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def replace_uri_vars(path, params)
|
9
|
+
new_path = path.clone()
|
10
10
|
parts = path.split("/")
|
11
11
|
parts.each do |part|
|
12
12
|
if part.start_with?(":")
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# @todo raise real errors
|
20
|
-
raise "Missing params: set '#{part}' to complete '#{path}' request"
|
21
|
-
end
|
13
|
+
key = part[1..-1].to_sym
|
14
|
+
if params.has_key?(key)
|
15
|
+
new_path.gsub!(Regexp.compile(":" + key.to_s), params[key].to_s)
|
16
|
+
else
|
17
|
+
# @todo raise real errors
|
18
|
+
raise "Missing params: set '#{part}' to complete '#{path}' request"
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
25
|
-
return
|
22
|
+
return new_path
|
26
23
|
end
|
27
24
|
|
25
|
+
def create_proc(klass, kmethod, urlpath, opts, client=nil)
|
26
|
+
proc = Proc.new() do |params: {}, body: nil, headers: {}, path: nil|
|
27
|
+
client = OpenAPI::Route.get_client() if client.nil?
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
proc = Proc.new() do |arg1=nil, arg2={}, p=nil|
|
32
|
-
if p != nil
|
33
|
-
uri_path = p.clone()
|
34
|
-
else
|
35
|
-
uri_path = path.clone()
|
36
|
-
end
|
37
|
-
if client == nil
|
38
|
-
client = OpenAPI::Route.get_client()
|
39
|
-
end
|
40
|
-
model = nil
|
41
|
-
if options.has_key?(:body) && !arg1.instance_of?(Hash)
|
42
|
-
model = arg1
|
43
|
-
params = arg2
|
44
|
-
if !model.instance_of?(options[:body])
|
45
|
-
raise "Expected #{options[:body]} class, got #{model.class} instead"
|
46
|
-
end
|
47
|
-
elsif arg1.instance_of?(Hash) && options.has_key?(:body) && arg1[:body] == nil
|
48
|
-
raise "No body provided"
|
49
|
-
else
|
50
|
-
if arg1 == nil || arg1.instance_of?(Hash)
|
51
|
-
params = arg1 || {}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
if model != nil
|
56
|
-
to_json_options = nil
|
57
|
-
if params.has_key?(:to_json)
|
58
|
-
to_json_options = params[:to_json]
|
59
|
-
elsif options.has_key?(:to_json)
|
60
|
-
to_json_options = options[:to_json]
|
61
|
-
end
|
62
|
-
if to_json_options
|
63
|
-
params[:body] = model.send :to_json, to_json_options
|
64
|
-
else
|
65
|
-
params[:body] = model.to_json
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
if params.has_key?(:display_help) && params[:display_help]
|
70
|
-
return options
|
71
|
-
end
|
72
|
-
|
73
|
-
parameters = params[:params] || {}
|
74
|
-
params.each do |key,v|
|
75
|
-
if options.has_key?(:params) && options[:params].has_key?(key)
|
76
|
-
parameters[key] = v
|
77
|
-
end
|
78
|
-
end
|
79
|
-
params[:params] = parameters
|
80
|
-
|
81
|
-
if options.has_key?(:extra)
|
82
|
-
options[:extra].each do |k,v|
|
29
|
+
if opts.has_key?(:default)
|
30
|
+
opts[:defaults].each do |k,v|
|
83
31
|
if !params.has_key?(k)
|
84
32
|
params[k] = v
|
85
33
|
end
|
@@ -87,21 +35,14 @@ module OpenAPI
|
|
87
35
|
end
|
88
36
|
|
89
37
|
OpenAPI.logger.debug params
|
90
|
-
|
91
|
-
|
92
|
-
end
|
93
|
-
OpenAPI::Route.check_params(uri_path, params, model)
|
38
|
+
|
39
|
+
path = OpenAPI::Route.replace_uri_vars(path || urlpath, params)
|
94
40
|
|
95
41
|
#1. soon.wrap = do_request opts[:body] => postjson
|
96
|
-
|
97
|
-
|
98
|
-
r = Regexp.compile(":" + key.to_s)
|
99
|
-
new_path.gsub!(r, v.to_s)
|
100
|
-
end
|
101
|
-
OpenAPI.logger.debug(new_path)
|
102
|
-
response = client.do_request(options[:via], new_path, params)
|
42
|
+
OpenAPI.logger.debug(path)
|
43
|
+
response = client.do_request(opts[:via], path, {params: params, body: body, headers: headers, options: opts[:options] || {}})
|
103
44
|
#2. callback
|
104
|
-
return klass.send kmethod.to_s.to_sym, response, params
|
45
|
+
return klass.send kmethod.to_s.to_sym, response, {params: params, body: body, headers: headers, options: opts[:options] || {}}
|
105
46
|
end
|
106
47
|
return proc
|
107
48
|
end
|
data/lib/openapi/version.rb
CHANGED
data/lib/openapi.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
+
require 'hashie'
|
1
2
|
require "active_support/core_ext/numeric/time"
|
2
3
|
require 'openapi/exceptions'
|
3
|
-
require 'openapi/utils'
|
4
4
|
require 'openapi/client'
|
5
5
|
require 'openapi/response'
|
6
6
|
require 'openapi/metaclass'
|
7
7
|
require 'openapi/handlers'
|
8
8
|
require 'openapi/route'
|
9
|
-
require 'openapi/models'
|
10
9
|
require 'openapi/auth_token'
|
11
10
|
|
12
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.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:
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.8
|
19
|
+
version: '1.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.8
|
26
|
+
version: '1.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,17 +39,17 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: hashie
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -89,7 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- Changelog
|
92
|
-
-
|
92
|
+
- LICENSE
|
93
93
|
- README.md
|
94
94
|
- Rakefile
|
95
95
|
- lib/openapi.rb
|
@@ -97,18 +97,14 @@ files:
|
|
97
97
|
- lib/openapi/client.rb
|
98
98
|
- lib/openapi/exceptions.rb
|
99
99
|
- lib/openapi/handlers.rb
|
100
|
-
- lib/openapi/handlers/
|
101
|
-
- lib/openapi/handlers/dummy.rb
|
102
|
-
- lib/openapi/handlers/model.rb
|
100
|
+
- lib/openapi/handlers/hashie.rb
|
103
101
|
- lib/openapi/handlers/raw.rb
|
104
102
|
- lib/openapi/handlers/response.rb
|
105
103
|
- lib/openapi/metaclass.rb
|
106
104
|
- lib/openapi/models.rb
|
107
|
-
- lib/openapi/models/
|
105
|
+
- lib/openapi/models/response.rb
|
108
106
|
- lib/openapi/response.rb
|
109
107
|
- lib/openapi/route.rb
|
110
|
-
- lib/openapi/utils.rb
|
111
|
-
- lib/openapi/validators.rb
|
112
108
|
- lib/openapi/version.rb
|
113
109
|
homepage: http://github.com/antlegrand/openapi
|
114
110
|
licenses:
|
data/License
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Antoine Legrand (ant.legrand@gmail.com)
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require File.join(File.dirname(__FILE__), '../models')
|
3
|
-
module OpenAPI
|
4
|
-
module Handlers
|
5
|
-
class Array < OpenAPI::Handler
|
6
|
-
class << self
|
7
|
-
|
8
|
-
|
9
|
-
def method_missing(method_symbol, *arguments) #:nodoc:
|
10
|
-
method_name = method_symbol.to_s
|
11
|
-
if method_name =~ /^(\w+)_array$/
|
12
|
-
return self.send :construct_array, $1, *arguments
|
13
|
-
else
|
14
|
-
super
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def raw_array(response, options)
|
19
|
-
array = []
|
20
|
-
response.each do |model_attr|
|
21
|
-
array << model_attr
|
22
|
-
end
|
23
|
-
array = OpenAPI::Handlers::Response.wrap(array, response)
|
24
|
-
return array
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def construct_array(snake_name, response, options)
|
30
|
-
return self.failed(response) if not response.success?
|
31
|
-
array = []
|
32
|
-
klass_name = ActiveSupport::Inflector.camelize(snake_name, true)
|
33
|
-
klass = OpenAPI::Models.const_get(klass_name)
|
34
|
-
response.each do |model_attr|
|
35
|
-
array << klass.new.from_json(model_attr.to_json)
|
36
|
-
end
|
37
|
-
array = OpenAPI::Handlers::Response.wrap(array, response)
|
38
|
-
return array
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../handlers')
|
2
|
-
|
3
|
-
module OpenAPI
|
4
|
-
module Handlers
|
5
|
-
|
6
|
-
class Dummy < OpenAPI::Handler
|
7
|
-
class << self
|
8
|
-
def titi(id, name)
|
9
|
-
puts "id:#{id.to_s[0..10]}, name:#{name}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Campaigns < OpenAPI::Handler
|
15
|
-
class << self
|
16
|
-
def stats(response, options)
|
17
|
-
return response, options
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Offers < OpenAPI::Handler
|
23
|
-
class << self
|
24
|
-
def index(response, options)
|
25
|
-
return response, options
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require File.join(File.dirname(__FILE__), '../models')
|
3
|
-
module OpenAPI
|
4
|
-
module Handlers
|
5
|
-
class Model < OpenAPI::Handler
|
6
|
-
class << self
|
7
|
-
def method_missing(method_symbol, *arguments) #:nodoc:
|
8
|
-
method_name = method_symbol.to_s
|
9
|
-
if method_name =~ /^(\w+)_model$/
|
10
|
-
return self.send :construct_model, $1, *arguments
|
11
|
-
else
|
12
|
-
super
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def construct_model(snake_name, response, options)
|
19
|
-
return self.failed(response) if not response.success?
|
20
|
-
klass_name = ActiveSupport::Inflector.camelize(snake_name, true)
|
21
|
-
klass = OpenAPI::Models.const_get(klass_name)
|
22
|
-
model = klass.new.from_json(response.raw)
|
23
|
-
model = OpenAPI::Handlers::Response.wrap(model, response)
|
24
|
-
return model
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/openapi/models/base.rb
DELETED
data/lib/openapi/utils.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
|
-
module OpenAPI
|
4
|
-
module Utils
|
5
|
-
class Random
|
6
|
-
class << self
|
7
|
-
def hex(n=16)
|
8
|
-
SecureRandom.hex(n)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Date
|
14
|
-
class << self
|
15
|
-
|
16
|
-
def format(date)
|
17
|
-
date.strftime("%Y%m%d")
|
18
|
-
end
|
19
|
-
|
20
|
-
def now()
|
21
|
-
format(Time.now.utc())
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_s()
|
26
|
-
@date_str
|
27
|
-
end
|
28
|
-
|
29
|
-
def date()
|
30
|
-
@date
|
31
|
-
end
|
32
|
-
|
33
|
-
def inititialize(t = nil)
|
34
|
-
if t == nil
|
35
|
-
t = Time.now.utc()
|
36
|
-
end
|
37
|
-
@date_str = OpenAPI::Utils::Date.format(t)
|
38
|
-
@date = t.dup()
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
module ActiveRecord
|
45
|
-
module SecureRandom
|
46
|
-
class << self
|
47
|
-
def hex(n=16)
|
48
|
-
OpenAPI::Utils::Random.hex(n)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/lib/openapi/validators.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module OpenAPI
|
2
|
-
module Models
|
3
|
-
module Validation
|
4
|
-
class UrlValidator < ActiveModel::EachValidator
|
5
|
-
def validate_each(record, attribute, value)
|
6
|
-
begin
|
7
|
-
uri = URI.parse(value)
|
8
|
-
resp = uri.kind_of?(URI::HTTP)
|
9
|
-
rescue URI::InvalidURIError
|
10
|
-
resp = false
|
11
|
-
end
|
12
|
-
unless resp == true
|
13
|
-
record.errors[attribute] << (options[:message] || "is not an url")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|