require 'rubygems' require 'rest_client' require 'json' module Maskedmail def self.production_url ENV['MASKEDMAIL_URL'] end def self.dummy_mask {:id => 1, :destination => 'dummy@maskedmail.net', :mask => 'user-1234@maskedmail.net'} end def self.request(method, arg_opts = {}) options = {:dummy_mask => dummy_mask, :suburl => ''} options.merge!(arg_opts) return options[:dummy_mask] unless production_url response = RestClient.send(method, "#{production_url}/#{options[:suburl]}", :email_address => options[:email_address]) JSON.parse(response) end def self.all request(:get, {:dummy_mask => [dummy_mask]}) end def self.create(email_address) request(:post, {:email_address => email_address}) end def self.get(id) request(:get, {:suburl => id}) end def self.update(id, email_address) request(:put, {:email_address => email_address, :suburl => id}) end def self.delete(id) request(:delete, {:suburl => id}) end end