Module: HaveAPI
- Defined in:
- lib/haveapi.rb,
lib/haveapi/api.rb,
lib/haveapi/hooks.rb,
lib/haveapi/route.rb,
lib/haveapi/action.rb,
lib/haveapi/common.rb,
lib/haveapi/params.rb,
lib/haveapi/server.rb,
lib/haveapi/context.rb,
lib/haveapi/example.rb,
lib/haveapi/version.rb,
lib/haveapi/metadata.rb,
lib/haveapi/resource.rb,
lib/haveapi/validator.rb,
lib/haveapi/exceptions.rb,
lib/haveapi/action_state.rb,
lib/haveapi/example_list.rb,
lib/haveapi/spec/helpers.rb,
lib/haveapi/authorization.rb,
lib/haveapi/model_adapter.rb,
lib/haveapi/client_example.rb,
lib/haveapi/actions/default.rb,
lib/haveapi/extensions/base.rb,
lib/haveapi/validator_chain.rb,
lib/haveapi/output_formatter.rb,
lib/haveapi/validators/custom.rb,
lib/haveapi/validators/format.rb,
lib/haveapi/validators/length.rb,
lib/haveapi/authentication/base.rb,
lib/haveapi/validators/presence.rb,
lib/haveapi/validators/exclusion.rb,
lib/haveapi/validators/inclusion.rb,
lib/haveapi/validators/acceptance.rb,
lib/haveapi/validators/confirmation.rb,
lib/haveapi/validators/numericality.rb,
lib/haveapi/client_examples/ruby_cli.rb
Defined Under Namespace
Modules: Actions, Authentication, CLI, ClientExamples, Extensions, Hookable, Hooks, ModelAdapters, OutputFormatters, Parameters, Resources, Spec, Validators
Classes: Action, ActionState, AuthenticationError, Authorization, BuildError, ClientExample, Common, Context, Example, ExampleList, Metadata, ModelAdapter, OutputFormatter, Params, Resource, Route, Server, ValidationError, Validator, ValidatorChain
Constant Summary
collapse
- PROTOCOL_VERSION =
'2.0'
- VERSION =
'0.16.0'
Class Method Summary
collapse
Class Method Details
.default_authenticate ⇒ Object
80
81
82
|
# File 'lib/haveapi/api.rb', line 80
def self.default_authenticate
@default_auth || []
end
|
.default_authenticate=(chain) ⇒ Object
76
77
78
|
# File 'lib/haveapi/api.rb', line 76
def self.default_authenticate=(chain)
@default_auth = chain
end
|
.filter_resources(module_name) ⇒ Object
Iterate through all resources and return those for which yielded block returned true.
23
24
25
26
27
28
29
30
31
|
# File 'lib/haveapi/api.rb', line 23
def self.filter_resources(module_name)
ret = []
resources(module_name) do |r|
ret << r if yield(r)
end
ret
end
|
.get_version_resources(module_name, v) ⇒ Object
Return list of resources for version v
.
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/haveapi/api.rb', line 34
def self.get_version_resources(module_name, v)
filter_resources(module_name) do |r|
r_v = r.version || implicit_version
if r_v.is_a?(Array)
r_v.include?(v)
else
r_v == v || r_v == :all
end
end
end
|
.implicit_version ⇒ Object
72
73
74
|
# File 'lib/haveapi/api.rb', line 72
def self.implicit_version
@implicit_version
end
|
.implicit_version=(v) ⇒ Object
68
69
70
|
# File 'lib/haveapi/api.rb', line 68
def self.implicit_version=(v)
@implicit_version = v
end
|
.module_name ⇒ Object
64
65
66
|
# File 'lib/haveapi/api.rb', line 64
def self.module_name
@module_name
end
|
.module_name=(name) ⇒ Object
60
61
62
|
# File 'lib/haveapi/api.rb', line 60
def self.module_name=(name)
@module_name = name
end
|
.resources(module_name) ⇒ Object
Return a list of all resources or yield them if block is given.
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/haveapi/api.rb', line 3
def self.resources(module_name) ret = []
module_name.constants.select do |c|
obj = module_name.const_get(c)
if obj.obj_type == :resource
if block_given?
yield obj
else
ret << obj
end
end
end
ret
end
|
.versions(module_name) ⇒ Object
Return a list of all API versions.
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/haveapi/api.rb', line 48
def self.versions(module_name)
ret = []
resources(module_name) do |r|
ret << r.version unless ret.include?(r.version)
end
ret.compact!
ret << implicit_version if ret.empty? && implicit_version
ret
end
|