Sha256: 499aa2a00773aafd21f257509f0b2223bd1956f1d3e54c3c3a7d66f122b11cac

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

module Trumpet
  class Transmitter
    @@attributes = [
      :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 self.all_by_user(name)
      transmitters = Trumpet::Request.get("/users/#{name}/transmitters")
      transmitters.map { |attributes| Trumpet::Transmitter.new(attributes) }
    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, :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/transmitter.rb
trumpet-trumpet-0.0.11 lib/trumpet/transmitter.rb
trumpet-trumpet-0.0.12 lib/trumpet/transmitter.rb