Sha256: 9219e7c9cfb9869a3dfea12fb5f6ecc5f96d72f5898977b849e0638cb7a7d6b3

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

module Trumpet
  class Listener
    @@attributes = [
      :id,
      :receiver_id,
      :owner_id,
      :uri,
      :schedule,
      :created_at,
      :updated_at,
    ]
    
    attr_reader *@@attributes
    
    
    def self.create(options)
      if options[:receiver_id]
        Listener.new(Trumpet::Request.post("/receivers/#{options[:receiver_id]}/listeners", :parameters => options))
      else
        raise Trumpet::BadRequest, "Must specify a receiver id when creating a listener"
      end
    end
    
    def self.find(id)
      Listener.new(Trumpet::Request.get("/listeners/#{id}"))
    end
    
    def self.all_by_user(name)
      listeners = Trumpet::Request.get("/users/#{name}/listeners")
      listeners.map { |attributes| Listener.new(attributes) }
    end
    
    def delete
      !!Trumpet::Request.delete("/listeners/#{@id}", :parse_response => false)
    end
    
    
    protected
    
      def initialize(attributes)
        @@attributes.each do |attr|
          self.instance_variable_set(:"@#{attr.to_s}", attributes[attr.to_s]) if attributes[attr.to_s]
        end
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trumpet-trumpet-0.0.10 lib/trumpet/listener.rb
trumpet-trumpet-0.0.11 lib/trumpet/listener.rb
trumpet-trumpet-0.0.12 lib/trumpet/listener.rb