Sha256: 77079234a436688ab93724592e4ef59826e36a659de0bd5cecaa62e199378570

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'rubygems'
require 'rest_client'
require 'json'

module Maskedmail

  def self.configure 
    if ENV['MASKEDMAIL_URL']
      @resource = RestClient::Resource.new(ENV['MASKEDMAIL_URL'])
    else
      @development = true
    end
  end

  def self.all
    return [dummy_mask] if @development
      
    request = @resource.get
    JSON.parse(request)
  end

  def self.create(email_address)
    return dummy_mask if @development 
   
    request = @resource.post(:email_address => email_address)
    JSON.parse(request)
  end

  def self.get(id)
    return dummy_mask if @development 
    
    request = @resource[id].get
    JSON.parse(request)
  end

  def self.update(id, email_address)
    return dummy_mask if @development 

    request = @resource[id].put(:email_address => email_address)
    JSON.parse(request)
  end

  def self.delete(id)
    return dummy_mask if @development 

    request = @resource[id].delete
    JSON.parse(request)
  end

  def dummy_mask
    {:id => 1, :destination => 'dummy@maskedmail.net', 
      :mask => 'user-1234@maskedmail.net'}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maskedmail-0.0.1 lib/maskedmail.rb