Class: Hootenanny::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/hootenanny/errors.rb,
lib/hootenanny/request.rb,
lib/hootenanny/request/subscription.rb,
lib/hootenanny/request/publish_notification.rb

Direct Known Subclasses

PublishNotification, Subscription

Defined Under Namespace

Classes: BuildError, PublishNotification, Subscription

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/hootenanny/request.rb', line 7

def type
  @type
end

Class Method Details

.build(options = {}) ⇒ Object

Private: Builds a specific request object based on the options passed in.

options - A Hash of options representing the request that will be built. The

only option that is required for _this_ method is :type, however
depending on the class that is to be built, it may require other
options.  See each class in turn for details.

:type - The type of request that should be built. Currently, valid
        opitons are:

        * :subscription

Examples:

Hootenanny::Request.build(type:     :subscription,
                          callback: 'http://example.com',)
# => <Hootenanny::Request::Subscription>

Returns an indeterminate type of object based on the :type option Raises Hootenanny::Request::BuildError if there is a problem



31
32
33
34
35
36
37
38
# File 'lib/hootenanny/request.rb', line 31

def self.build(options = {})
  type  = options.fetch(:type).to_s.camelize
  klass = "Hootenanny::Request::#{type}".constantize

  klass.build options
rescue KeyError => e
  raise Hootenanny::Request::BuildError.wrap(e)
end