lib/maskedmail.rb in maskedmail-0.0.1 vs lib/maskedmail.rb in maskedmail-0.1.0

- old
+ new

@@ -2,53 +2,46 @@ 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 + 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 - return [dummy_mask] if @development - - request = @resource.get - JSON.parse(request) + request(:get, {:dummy_mask => [dummy_mask]}) end def self.create(email_address) - return dummy_mask if @development - - request = @resource.post(:email_address => email_address) - JSON.parse(request) + request(:post, {:email_address => email_address}) end def self.get(id) - return dummy_mask if @development - - request = @resource[id].get - JSON.parse(request) + request(:get, {:suburl => id}) end def self.update(id, email_address) - return dummy_mask if @development - - request = @resource[id].put(:email_address => email_address) - JSON.parse(request) + request(:put, {:email_address => email_address, :suburl => id}) end def self.delete(id) - return dummy_mask if @development - - request = @resource[id].delete - JSON.parse(request) + request(:delete, {:suburl => id}) end - def dummy_mask - {:id => 1, :destination => 'dummy@maskedmail.net', - :mask => 'user-1234@maskedmail.net'} - end end