Class: Kanpachi::DSL::Resource
- Inherits:
-
Object
- Object
- Kanpachi::DSL::Resource
- Defined in:
- lib/kanpachi/dsl/resource.rb
Instance Method Summary collapse
-
#authentication(authentication) ⇒ Boolean
Mark that the service requires authentication.
-
#description(description) ⇒ String
Sets the description.
-
#formats(*f_types) ⇒ Array<Symbol>
Sets or returns the supported formats.
-
#initialize(resource) ⇒ Resource
constructor
Constructor.
-
#name(name) ⇒ String
Sets the name.
-
#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. -
#priority(priority) ⇒ String
Sets the priority matching url a request matches will be executed, priority determines the order in which urls are matched.
-
#response(name = :default) { ... } ⇒ Kanpachi::Response
Returns the service response.
-
#ssl(ssl) ⇒ Boolean
Mark that the service requires a SSL connection.
-
#versions(*vers) ⇒ Set<String>
Sets or returns the version.
Constructor Details
#initialize(resource) ⇒ Resource
Constructor
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
58 59 60 |
# File 'lib/kanpachi/dsl/resource.rb', line 58 def authentication(authentication) @resource.authentication = authentication end |
#description(description) ⇒ String
Sets the description
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
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
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.
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.
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
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
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
67 68 69 |
# File 'lib/kanpachi/dsl/resource.rb', line 67 def versions(*vers) @resource.versions.merge(vers) unless vers.empty? end |