Class: Kanpachi::DSL::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/kanpachi/dsl/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Resource

Constructor

Parameters:



10
11
12
# File 'lib/kanpachi/dsl/resource.rb', line 10

def initialize(resource)
  @resource = resource
end

Instance Method Details

#authentication(authentication) ⇒ Boolean

Mark that the service requires authentication. Note: Authentication is turned off by default

Parameters:

  • authentication (Boolean)

    True if the resource requires authentication.

Returns:

  • (Boolean)


58
59
60
# File 'lib/kanpachi/dsl/resource.rb', line 58

def authentication(authentication)
  @resource.authentication = authentication
end

#description(description) ⇒ String

Sets the description

Parameters:

  • description (String)

    Description of the resource

Returns:

  • (String)

    Description of resource



28
29
30
# File 'lib/kanpachi/dsl/resource.rb', line 28

def description(description)
  @resource.description = description
end

#formats(*f_types) ⇒ Array<Symbol>

Sets or returns the supported formats

Parameters:

  • f_types (String, Symbol)

    Format type supported, such as :xml

Returns:

  • (Array<Symbol>)

    List of supported formats



76
77
78
# File 'lib/kanpachi/dsl/resource.rb', line 76

def formats(*f_types)
  @resource.formats.merge(f_types) unless f_types.empty?
end

#name(name) ⇒ String

Sets the name

Parameters:

  • name (String)

    Name of the resource

Returns:

  • (String)

    Name of resource



19
20
21
# File 'lib/kanpachi/dsl/resource.rb', line 19

def name(name)
  @resource.name = name
end

#params(&block) ⇒ Kanpachi::Params

Returns the defined params for DSL use only! To keep the distinction between the request params and the service params using the defined_params accessor is recommended.

Returns:

  • (Kanpachi::Params)

    The defined params

See Also:

  • Params


88
89
90
91
92
93
94
# File 'lib/kanpachi/dsl/resource.rb', line 88

def params(&block)
  if block_given?
    @resource.params.class_eval &block
  else
    @resource.params
  end
end

#priority(priority) ⇒ String

Sets the priority matching url a request matches will be executed, priority determines the order in which urls are matched. Defaults to 50.

Parameters:

  • priority (Integer)

    Priority of the resource. Usually, the first

Returns:

  • (String)

    Name of resource



39
40
41
# File 'lib/kanpachi/dsl/resource.rb', line 39

def priority(priority)
  @resource.priority = priority
end

#response(name = :default) { ... } ⇒ Kanpachi::Response

Returns the service response

Yields:

  • The service response object

Returns:



101
102
103
104
105
106
107
# File 'lib/kanpachi/dsl/resource.rb', line 101

def response(name = :default, &block)
  response = Kanpachi::Response.new(name)
  dsl = Kanpachi::DSL::Response.new(response)
  dsl.instance_eval &block if block_given?
  @resource.responses.add(response)
  response
end

#ssl(ssl) ⇒ Boolean

Mark that the service requires a SSL connection

Parameters:

  • ssl (Boolean)

    True if the resource requires ssl.

Returns:

  • (Boolean)


48
49
50
# File 'lib/kanpachi/dsl/resource.rb', line 48

def ssl(ssl)
  @resource.ssl = ssl
end

#versions(*vers) ⇒ Set<String>

Sets or returns the version

Parameters:

  • vers (Set<String>)

    Version of the resource

Returns:

  • (Set<String>)

    versions supported



67
68
69
# File 'lib/kanpachi/dsl/resource.rb', line 67

def versions(*vers)
  @resource.versions.merge(vers) unless vers.empty?
end