Project

General

Profile

« Previous | Next » 

Revision 981a9508

Added by Martin Bacovsky almost 12 years ago

  • ID 981a95082583910355873a3c675bb7c748227f21

api v1 - restapi renamed to apipie

View differences:

Gemfile
gem 'net-ldap'
gem "safemode", "~> 1.0.1"
gem 'uuidtools'
gem "restapi", :git => "git://github.com/Katello/rails-restapi.git", :branch => "katello"
gem "apipie-rails", ">= 0.0.7"
gem 'rabl'
# Previous versions collide with Environment model
gem "ruby_parser", ">= 2.3.1"
Rakefile
require 'rake'
include Rake::DSL
if Rails.env.test?
require 'single_test'
SingleTest.load_tasks
end
SingleTest.load_tasks if defined? SingleTest
Foreman::Application.load_tasks
bundler.d/development.rb
gem "ruby-debug", :platforms => :ruby_18
gem "ruby-debug19", :platforms => :ruby_19
gem 'redcarpet'
gem 'single_test'
gem 'pry'
gem "term-ansicolor"
end
config/initializers/apipie.rb
Apipie.configure do |config|
config.app_name = "Foreman"
config.app_info = "The Foreman is aimed to be a single address for all machines life cycle management."
config.copyright = ""
config.api_base_url = "/api"
config.api_controllers_matcher = "#{Rails.root}/app/controllers/api/v1/*.rb"
config.ignored_by_recorder = %w[]
config.doc_base_url = "/apidoc"
config.use_cache = false #Rails.env.production?
config.validate = false
config.reload_controllers = true
config.markup = Apipie::Markup::Markdown.new
end
# special type of validator: we say that it's not specified
class UndefValidator < Apipie::Validator::BaseValidator
def validate(value)
true
end
def self.build(param_description, argument, options, block)
if argument == :undef
self.new(param_description)
end
end
def description
nil
end
end
class Apipie::Validator::TypeValidator
def description
@type.name
end
end
class Apipie::Validator::HashValidator
def description
"Hash"
end
end
class NumberValidator < Apipie::Validator::BaseValidator
def validate(value)
value.to_s =~ /^(0|[1-9]\d*)$/
end
def self.build(param_description, argument, options, block)
if argument == :number
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be a number, got: #{@error_value}"
end
def description
"number."
end
end
class IdentifierValidator < Apipie::Validator::BaseValidator
def validate(value)
value = value.to_s
value =~ /\A[\w| |_|-]*\Z/ && value.strip == value && (2..128).include?(value.length)
end
def self.build(param_description, argument, options, block)
if argument == :identifier
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be an identifier, got: #{@error_value}"
end
def description
"string from 2 to 128 characters containting only alphanumeric characters, space, '_', '-' with no leading or trailing space.."
end
end
class BooleanValidator < Apipie::Validator::BaseValidator
def validate(value)
%w[true false].include?(value.to_s)
end
def self.build(param_description, argument, options, block)
if argument == :bool
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be a boolean value, got: #{@error_value}"
end
def description
"boolean"
end
end
config/initializers/restapi.rb
Restapi.configure do |config|
config.app_name = "Foreman"
config.app_info = "The Foreman is aimed to be a single address for all machines life cycle management."
config.copyright = ""
config.api_base_url = "/api"
config.api_controllers_matcher = "#{Rails.root}/app/controllers/api/v1/*.rb"
config.ignored_by_recorder = %w[]
config.doc_base_url = "/apidoc"
config.use_cache = false #Rails.env.production?
config.validate = false
config.reload_controllers = true
config.markup = Restapi::Markup::Markdown.new
end
# special type of validator: we say that it's not specified
class UndefValidator < Restapi::Validator::BaseValidator
def validate(value)
true
end
def self.build(param_description, argument, options, block)
if argument == :undef
self.new(param_description)
end
end
def description
nil
end
end
class Restapi::Validator::TypeValidator
def description
@type.name
end
end
class Restapi::Validator::HashValidator
def description
"Hash"
end
end
class NumberValidator < Restapi::Validator::BaseValidator
def validate(value)
value.to_s =~ /^(0|[1-9]\d*)$/
end
def self.build(param_description, argument, options, block)
if argument == :number
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be a number, got: #{@error_value}"
end
def description
"number."
end
end
class IdentifierValidator < Restapi::Validator::BaseValidator
def validate(value)
value = value.to_s
value =~ /\A[\w| |_|-]*\Z/ && value.strip == value && (2..128).include?(value.length)
end
def self.build(param_description, argument, options, block)
if argument == :identifier
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be an identifier, got: #{@error_value}"
end
def description
"string from 2 to 128 characters containting only alphanumeric characters, space, '_', '-' with no leading or trailing space.."
end
end
class BooleanValidator < Restapi::Validator::BaseValidator
def validate(value)
%w[true false].include?(value.to_s)
end
def self.build(param_description, argument, options, block)
if argument == :bool
self.new(param_description)
end
end
def error
"Parameter #{param_name} expecting to be a boolean value, got: #{@error_value}"
end
def description
"boolean"
end
end
config/routes/api/apipiedoc.rb
# config/routes/api/restapidoc.rb
Rails.application.routes.draw do |map|
apipie
end
config/routes/api/restapidoc.rb
# config/routes/api/restapidoc.rb
Rails.application.routes.draw do |map|
restapi
end

Also available in: Unified diff