Module: OpenStax::Api::Apipie::ClassMethods

Defined in:
lib/openstax/api/apipie.rb

Instance Method Summary collapse

Instance Method Details

#api_example(options = {}) ⇒ Object

Raises:

  • (IllegalArgument)


17
18
19
20
21
22
23
24
25
26
# File 'lib/openstax/api/apipie.rb', line 17

def api_example(options={})
  return if Rails.env.test?
  raise IllegalArgument, "must supply a :url parameter" if !options[:url_base]

  url_base = options[:url_base].is_a?(Symbol) ?
  UrlGenerator.new.send(options[:url_base], protocol: 'https') :
  options[:url_base].to_s

  "#{url_base}/#{options[:url_end] || ''}"
end

#json_schema(representer, options = {}) ⇒ Object



28
29
30
# File 'lib/openstax/api/apipie.rb', line 28

def json_schema(representer, options={})
  RepresentableSchemaPrinter.json(representer, options)
end

#representer(representer) ⇒ Object

A hack at a conversion from a Representer to a series of Apipie declarations Can call it like any Apipie DSL method,

example "blah"
representer Api::V1::ExerciseRepresenter
def update ...


39
40
41
42
43
44
# File 'lib/openstax/api/apipie.rb', line 39

def representer(representer)
  representer.representable_attrs.each do |attr|
    schema_info = attr.options[:schema_info] || {}
    param attr.name, (attr.options[:type] || Object), required: schema_info[:required]
  end
end