Module: BrickFTP::APIDefinition::ClassMethods

Defined in:
lib/brick_ftp/api_definition.rb

Instance Method Summary collapse

Instance Method Details

#api_component_for(name) ⇒ BrickFTP::APIComponent

Build BrickFTP::APIComponent.

Parameters:

  • name (Symbol)

Returns:

Raises:



59
60
61
62
# File 'lib/brick_ftp/api_definition.rb', line 59

def api_component_for(name)
  raise BrickFTP::API::NoSuchAPI, "#{name} #{self.name}" unless endpoints.key?(name)
  BrickFTP::APIComponent.new(endpoints[name][:path_template], endpoints[name][:query_keys])
end

#api_path_for(name, params = {}) ⇒ String

Build path for API endpoint.

Parameters:

  • name (Symbol)
  • params (Hash) (defaults to: {})

    mixed path parameters and query parameters.

Returns:

  • (String)


52
53
54
# File 'lib/brick_ftp/api_definition.rb', line 52

def api_path_for(name, params = {})
  api_component_for(name).path(params)
end

#attribute(name, writable: false) ⇒ Object

Define attribute.

Parameters:

  • name (Symbol)

    name of attribute.

  • writable (Boolean) (defaults to: false)


34
35
36
37
38
39
40
# File 'lib/brick_ftp/api_definition.rb', line 34

def attribute(name, writable: false)
  if writable
    writable_attributes << name.to_sym
  else
    readonly_attributes << name.to_sym
  end
end

#attributesArray

Return all attributes.

Returns:

  • (Array)


44
45
46
# File 'lib/brick_ftp/api_definition.rb', line 44

def attributes
  writable_attributes + readonly_attributes
end

#endpoint(http_method, name, path_template, *query_keys) ⇒ Object

Define API endpoint.

Parameters:

  • http_method (:Symbol)

    any one of :get, :post, :put, :delete

  • name (Symbol)

    any one of :index, :show, :create, :update, :destroy

  • path_template (Stryng)

    template of endpoint path.

  • query_keys (Array)

    array of query_string’s parameter name.



23
24
25
26
27
28
29
# File 'lib/brick_ftp/api_definition.rb', line 23

def endpoint(http_method, name, path_template, *query_keys)
  endpoints[name] = {
    http_method: http_method,
    path_template: path_template,
    query_keys: query_keys,
  }
end