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'.freeze
VERSION =
'0.25.0'.freeze

Class Method Summary collapse

Class Method Details

.default_authenticateObject



81
82
83
# File 'lib/haveapi/api.rb', line 81

def self.default_authenticate
  @default_auth || []
end

.default_authenticate=(chain) ⇒ Object



77
78
79
# File 'lib/haveapi/api.rb', line 77

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.



24
25
26
27
28
29
30
31
32
# File 'lib/haveapi/api.rb', line 24

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.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/haveapi/api.rb', line 35

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_versionObject



73
74
75
# File 'lib/haveapi/api.rb', line 73

def self.implicit_version
  @implicit_version
end

.implicit_version=(v) ⇒ Object



69
70
71
# File 'lib/haveapi/api.rb', line 69

def self.implicit_version=(v)
  @implicit_version = v
end

.module_nameObject



65
66
67
# File 'lib/haveapi/api.rb', line 65

def self.module_name
  @module_name
end

.module_name=(name) ⇒ Object



61
62
63
# File 'lib/haveapi/api.rb', line 61

def self.module_name=(name)
  @module_name = name
end

.resources(module_name) {|resource| ... } ⇒ Object

Return a list of all resources or yield them if block is given.

Yield Parameters:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/haveapi/api.rb', line 4

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.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/haveapi/api.rb', line 49

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