Class: WSDSL::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/response.rb

Overview

Response DSL class

Since:

  • 0.0.3

Defined Under Namespace

Classes: Element

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.

Since:

  • 0.0.3



12
13
14
# File 'lib/response.rb', line 12

def initialize
  @elements = []
end

Instance Attribute Details

#elementsArray<WSDSL::Response::Element> (readonly)

The list of all the elements inside the response

Returns:

Since:

  • 0.0.3



10
11
12
# File 'lib/response.rb', line 10

def elements
  @elements
end

Instance Method Details

#element(opts = {}) {|WSDSL::Response::Element| ... } ⇒ Array<WSDSL::Response::Element>

Defines a new element and yields the content of an optional block Each new element is then stored in the elements array.

Examples:

create an element called ‘my_stats’.

service.response do |response|
 response.element(:name => "my_stats", :type => 'Leaderboard')
end

Parameters:

  • opts (Hash) (defaults to: {})

    Options used to define the element

Options Hash (opts):

  • :name (String, Symbol)

    The element name

  • :type (String, Symbol)

    The optional type

Yields:

Returns:

Since:

  • 0.0.3



31
32
33
34
35
# File 'lib/response.rb', line 31

def element(opts={})
  el = Element.new(opts)
  yield(el) if block_given?
  @elements << el
end

#element_named(name) ⇒ WSDSL::Response::Element

Returns a response element object based on its name

Parameters:

  • The (String, Symbol)

    element name we want to match

Returns:

Since:

  • 0.0.3



42
43
44
# File 'lib/response.rb', line 42

def element_named(name)
  @elements.find{|e| e.name.to_s == name.to_s}
end