Module: HaveAPI::Spec::ApiBuilder
- Defined in:
- lib/haveapi/spec/api_builder.rb
Overview
Contains methods for specification of API to be used in ‘description` block.
Instance Method Summary collapse
-
#action_state(backend) ⇒ Object
Set action state backend to mount HaveAPI::Resources::ActionState.
-
#action_state_auth(mode) ⇒ Object
Set action state authentication mode.
-
#api(mod = nil) { ... } ⇒ Object
Set an API module or create the API using DSL.
-
#auth_chain(chain) ⇒ Object
Set authentication chain.
-
#default_version(v) ⇒ Object
Set default API version.
-
#empty_api ⇒ Object
Uses an empty module as the source for the API.
-
#login(*credentials) ⇒ Object
Login using HTTP basic.
-
#mount_to(path) ⇒ Object
Set a custom mount path.
- #opt(name, v) ⇒ Object
- #opts ⇒ Object
-
#use_version(v) ⇒ Object
Select API versions to be used.
-
#validation_error_http_status(status) ⇒ Object
Set HTTP status for action validation errors.
Instance Method Details
#action_state(backend) ⇒ Object
Set action state backend to mount HaveAPI::Resources::ActionState
53 54 55 |
# File 'lib/haveapi/spec/api_builder.rb', line 53 def action_state(backend) opt(:action_state, backend) end |
#action_state_auth(mode) ⇒ Object
Set action state authentication mode.
58 59 60 |
# File 'lib/haveapi/spec/api_builder.rb', line 58 def action_state_auth(mode) opt(:action_state_auth, mode) end |
#api(mod = nil) { ... } ⇒ Object
Set an API module or create the API using DSL.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/haveapi/spec/api_builder.rb', line 14 def api(mod = nil, &block) unless mod mod = Module.new do def self.define_resource(name, superclass: HaveAPI::Resource, &block) return false if const_defined?(name) cls = Class.new(superclass) const_set(name, cls) cls.class_exec(&block) if block cls end module_eval(&block) end const_set(:ApiModule, mod) end opt(:api_module, mod) end |
#auth_chain(chain) ⇒ Object
Set authentication chain.
36 37 38 |
# File 'lib/haveapi/spec/api_builder.rb', line 36 def auth_chain(chain) opt(:auth_chain, chain) end |
#default_version(v) ⇒ Object
Set default API version.
48 49 50 |
# File 'lib/haveapi/spec/api_builder.rb', line 48 def default_version(v) opt(:default_version, v) end |
#empty_api ⇒ Object
Uses an empty module as the source for the API. It will have no resources, no actions. Version default to ‘1`.
6 7 8 9 |
# File 'lib/haveapi/spec/api_builder.rb', line 6 def empty_api api(Module.new) default_version(1) end |
#login(*credentials) ⇒ Object
Login using HTTP basic.
73 74 75 76 77 |
# File 'lib/haveapi/spec/api_builder.rb', line 73 def login(*credentials) before do (*credentials) end end |
#mount_to(path) ⇒ Object
Set a custom mount path.
68 69 70 |
# File 'lib/haveapi/spec/api_builder.rb', line 68 def mount_to(path) opt(:mount, path) end |
#opt(name, v) ⇒ Object
85 86 87 88 |
# File 'lib/haveapi/spec/api_builder.rb', line 85 def opt(name, v) @opts ||= {} @opts[name] = v end |
#opts ⇒ Object
80 81 82 |
# File 'lib/haveapi/spec/api_builder.rb', line 80 def opts @opts end |
#use_version(v) ⇒ Object
Select API versions to be used.
41 42 43 44 45 |
# File 'lib/haveapi/spec/api_builder.rb', line 41 def use_version(v) before do self.class.opt(:versions, v) end end |
#validation_error_http_status(status) ⇒ Object
Set HTTP status for action validation errors. Nil preserves legacy 200.
63 64 65 |
# File 'lib/haveapi/spec/api_builder.rb', line 63 def validation_error_http_status(status) opt(:validation_error_http_status, status) end |