Module: Eson::API

Overview

Objects including API act as API descriptions. They mostly act as a description of parameter names and roles to use in protocol implementations. Parameters are split in 2 sets: all parameters (params) and parameters that are transmitted in the body of a request (if the protocol has a notion of “body”). These descriptions are intended to be refined by protocol implementations.

For examples of this strategy, see Shared::Index and HTTP::Index.

Instance Method Summary collapse

Methods included from Chainable

#chainable, #extendable

Instance Method Details

#multi_index(bool) ⇒ Object

Indicates whether the api accepts multiple indices like ‘[“index1”, “index2”]



57
58
59
60
61
# File 'lib/eson/api.rb', line 57

def multi_index(bool)
  define_method :multi_index do
    bool
  end
end

#multi_types(bool) ⇒ Object

Indicates whether the api accepts multiple types like ‘[“type1”, “type2”]



64
65
66
67
68
# File 'lib/eson/api.rb', line 64

def multi_types(bool)
  define_method :multi_types do
    bool
  end
end

#no_indices(bool) ⇒ Object

Indicates whether the api does not operate on an index at all.



71
72
73
74
75
# File 'lib/eson/api.rb', line 71

def no_indices(bool)
  define_method :no_indices do
    bool
  end
end

#parameters(*params) ⇒ Object

Designates the names of all parameters supported by this request, including those used in the source later on.



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

def parameters(*params)
  chainable do
    define_method :parameters do
      super() + params
    end
    
    params.each do |p|
      attr_accessor p
    end
  end
end

#source_param(*params) ⇒ Object

Designates the name of the parameter that will be used as the body of the request. Use only if the API has such a parameter (e.g. Search). You still have to list the parameter.

If multiple parameters are given, they will act as the keys in the sent JSON object.

If the transport has no concept of a “source”, this should be ignored.

Examples:

source_param call

parameters :settings, :mappings
source_param :settings, :mappings

result

{
  "settings" : {...},
  "mappings" : {...}
}


46
47
48
49
50
51
52
53
54
# File 'lib/eson/api.rb', line 46

def source_param(*params)
  if params.length == 1
    params = params.first
  end
  
  define_method :source_param do
    params
  end
end