Sha256: 3311abf1242e374bce0743ed14a683eab83da9531f7643707159dd19d1a5e72f

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module Trumpet
  class Transmitter
    @@attributes = [
      :transmitter_id,
      :source_url,
      :tags,
      :location_string,
      :channel,
      :lat,
      :lng,
      :radius,
      :public,
      :created_at,
      :updated_at,
    ]
    
    attr_reader *@@attributes
    
    def self.create(options)
      Transmitter.new(Trumpet::Request.post('transmitters', :parameters => options))
    end
    
    def self.find(id)
      Transmitter.new(Trumpet::Request.get("/transmitters/#{id}"))
    end
    
    def delete
      Trumpet::Request.delete("/transmitters/#{@id}")
    end
    
    def listeners
      listeners = Trumpet::Request.get("/transmitters/#{@id}/listeners")
      listeners.map { |attributes| Listener.new(attributes) }
    end
    
    def broadcast(message)
      Trumpet::Request.post("/transmitters/#{@transmitter_id}/messages", :parameters => message.to_h)
    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

1 entries across 1 versions & 1 rubygems

Version Path
trumpet-trumpet-0.0.2 lib/trumpet/transmitter.rb