Class: Pechkin::List

Inherits:
Model
  • Object
show all
Defined in:
lib/pechkinrb/list.rb

Overview

Mailing list representation class

Constant Summary collapse

FIELDS =
[
  :id,
  :state,
  :count_active,
  :count_all,
  :name,
  :description,
  :company,
  :abuse_name,
  :phone,
  :address,
  :city,
  :url
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, doc) ⇒ List

Initialize new list instance

Parameters:

  • connection (Pachkin::Connection)

    Active connection

  • doc (Hash)

    API object data


29
30
31
32
33
34
# File 'lib/pechkinrb/list.rb', line 29

def initialize(connection, doc)
  super(connection, doc)
  FIELDS.each do |field|
    instance_variable_set :"@#{field}", doc[field.to_s]
  end
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw


4
5
6
# File 'lib/pechkinrb/list.rb', line 4

def raw
  @raw
end

Instance Method Details

#add_memberPechkin::Member

Invokes 'lists.add_memner' method

Parameters:

  • params (Hash)

    Params to be passed

Returns:


52
53
54
55
# File 'lib/pechkinrb/list.rb', line 52

def add_member
  added = connection.call_method('lists.add_member', params.merge(id_params))
  get_members(added).first
end

#get_members(params = {}) ⇒ Array Also known as: members

Invokes 'lists.get_members' API method to retreive list members

Parameters:

  • params (Hash) (defaults to: {})

    Params to be passed

Returns:

  • (Array)

    Array of Pechkin::Members instances


40
41
42
# File 'lib/pechkinrb/list.rb', line 40

def get_members(params = {})
  connection.call_method('lists.get_members', params.merge(id_params)).map {|member| Pechkin::Member.new(connection, member)}
end

#unsubscribe_member(params) ⇒ Fixnum

Invokes 'lists.unsubscribe_member' API method

Parameters:

  • params (Hash)

    Params to be passed

Returns:

  • (Fixnum)

    Count of unsubscribed members


61
62
63
# File 'lib/pechkinrb/list.rb', line 61

def unsubscribe_member(params)
  connection.call_method('lists.unsubscribe_member', params.merge(id_params))['unsubscribed']
end