lib/newslettre/letter.rb in newslettre-0.0.1 vs lib/newslettre/letter.rb in newslettre-0.1.0

- old
+ new

@@ -1,16 +1,41 @@ class Newslettre::Letter < Newslettre::APIModule + class Object < Struct.new(:owner, :name, :data) + extend Forwardable + + def_delegator :owner, :request + def_delegator :owner, :api + + def == other + self.to_hash == other + end + + def load_data + self.data ||= request('get', :name => self.name).to_hash + end + + def to_hash + load_data + + data + end + + def recipients + @recipients ||= Newslettre::APIModuleProxy.new self, Recipients.new(self.name, self.api) + end + end + def list request 'list' end def add name, data = {} request 'add', data.merge(:name => name) end def get name - request 'get', :name => name + Object.new self, name end def delete name request 'delete', :name => name end @@ -20,21 +45,22 @@ end class Recipients < Newslettre::APIModule attr_reader :letter - def initialize letter, client + def initialize letter, api @letter = letter - @client = client + @api = api end def add list request 'add', { :list => list, :name => letter } end def get request 'get', { :name => letter } end + alias_method :list, :get def delete list request 'delete', { :list => list, :name => letter } end end