Sha256: 38146aac41593e8a2e3bfc2b6c1839c6c05ebbcef446987ff963936cf21d3b3a
Contents?: true
Size: 1.44 KB
Versions: 2
Compression:
Stored size: 1.44 KB
Contents
class Newslettre::Lists < Newslettre::APIModule class Object < Struct.new(:owner, :list, :data) extend Forwardable def_delegator :owner, :request def_delegator :owner, :api def == other self.to_hash == other end def load_data loaded = request('get', :list => self.list).first raise Newslettre::API::ClientFailure, "missing #{self.list}" if loaded.nil? self.data ||= loaded.to_hash end def to_hash load_data data end def emails @emails ||= Newslettre::APIModuleProxy.new self, Email.new(self.list, self.api) end end def add list, data = {} request 'add', data.merge(:list => list) end def get list Object.new self, list end def list request('get').map {|r| Object.new self, r["list"] } end def edit list, data = {} request 'edit', data.merge(:list => list) end def delete list request 'delete', :list => list end class Email < Newslettre::APIModule attr_reader :list def initialize list, api @list = list @api = api end def add *recipients request 'add', :list => list, :data => recipients.map{|r| JSON.dump(r) } end def get *recipients request 'get', :list => list, :email => recipients end def delete *recipients request 'delete', :list => list, :email => recipients end protected def api_prefix "/lists/email" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
newslettre-0.2.4 | lib/newslettre/lists.rb |
newslettre-0.2.3 | lib/newslettre/lists.rb |