Class: CakeMail::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cakemail/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, user) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
# File 'lib/cakemail/client.rb', line 35

def initialize(id, user)
  @user = user
  @id = id
  get_info
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def address2
  @address2
end

#admin_emailObject

Returns the value of attribute admin_email.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_email
  @admin_email
end

#admin_first_nameObject

Returns the value of attribute admin_first_name.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_first_name
  @admin_first_name
end

#admin_languageObject

Returns the value of attribute admin_language.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_language
  @admin_language
end

#admin_last_nameObject

Returns the value of attribute admin_last_name.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_last_name
  @admin_last_name
end

#admin_mobile_phoneObject

Returns the value of attribute admin_mobile_phone.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_mobile_phone
  @admin_mobile_phone
end

#admin_office_phoneObject

Returns the value of attribute admin_office_phone.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_office_phone
  @admin_office_phone
end

#admin_passwordObject

Returns the value of attribute admin_password.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_password
  @admin_password
end

#admin_titleObject

Returns the value of attribute admin_title.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def admin_title
  @admin_title
end

#cityObject

Returns the value of attribute city.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def city
  @city
end

#client_idObject (readonly)

Returns the value of attribute client_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def client_id
  @client_id
end

#company_nameObject

Returns the value of attribute company_name.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def company_name
  @company_name
end

#contact_emailObject

Returns the value of attribute contact_email.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_email
  @contact_email
end

#contact_first_nameObject

Returns the value of attribute contact_first_name.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_first_name
  @contact_first_name
end

#contact_idObject (readonly)

Returns the value of attribute contact_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def contact_id
  @contact_id
end

#contact_languageObject

Returns the value of attribute contact_language.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_language
  @contact_language
end

#contact_last_nameObject

Returns the value of attribute contact_last_name.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_last_name
  @contact_last_name
end

#contact_mobile_phoneObject

Returns the value of attribute contact_mobile_phone.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_mobile_phone
  @contact_mobile_phone
end

#contact_office_phoneObject

Returns the value of attribute contact_office_phone.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_office_phone
  @contact_office_phone
end

#contact_passwordObject

Returns the value of attribute contact_password.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_password
  @contact_password
end

#contact_timezone_idObject (readonly)

Returns the value of attribute contact_timezone_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def contact_timezone_id
  @contact_timezone_id
end

#contact_titleObject

Returns the value of attribute contact_title.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def contact_title
  @contact_title
end

#country_idObject (readonly)

Returns the value of attribute country_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def country_id
  @country_id
end

#currencyObject

Returns the value of attribute currency.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def currency
  @currency
end

#faxObject

Returns the value of attribute fax.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def fax
  @fax
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def id
  @id
end

#last_activityObject (readonly)

Returns the value of attribute last_activity.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def last_activity
  @last_activity
end

#limitObject (readonly)

Returns the value of attribute limit.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def limit
  @limit
end

#manager_idObject (readonly)

Returns the value of attribute manager_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def manager_id
  @manager_id
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def parent_id
  @parent_id
end

#phoneObject

Returns the value of attribute phone.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def phone
  @phone
end

#postal_codeObject

Returns the value of attribute postal_code.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def postal_code
  @postal_code
end

#province_idObject (readonly)

Returns the value of attribute province_id.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def province_id
  @province_id
end

#registered_dateObject (readonly)

Returns the value of attribute registered_date.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def registered_date
  @registered_date
end

#sessionObject (readonly)

Returns the value of attribute session.



28
29
30
# File 'lib/cakemail/client.rb', line 28

def session
  @session
end

#websiteObject

Returns the value of attribute website.



30
31
32
# File 'lib/cakemail/client.rb', line 30

def website
  @website
end

Class Method Details

.create(args) ⇒ Object

Creates a new client.

Arguments :

  • args = { :user => required, :company_name => required, :admin_email => required, :admin_first_name => required, :admin_last_name => required, :admin_password => required, :contact_email => required, :contact_first_name => required, :contact_last_name => required, :contact_password => required, :parent_id => optional, :currency => optional, :address1 => optional, :address2 => optionall, :city => optional, :province_id => optional, :country_id => optional, :postal_code => optional, :website => optional, :phone => optional, :fax => optional, :admin_title => optional, :admin_office_phone => required, :admin_mobile_phone => optional, :admin_language => optional, :contact_title => optional, :contact_language => optional, :contact_timezone_id => optional, :contact_office_phone => optional, :contact_mobile_phone => optional }

Raises:

  • (ArgumentError)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cakemail/client.rb', line 102

def create(args)
  raise ArgumentError if args.nil? or args[:user].nil? or args[:company_name].nil? or args[:admin_email].nil? or 
    args[:admin_first_name].nil? or args[:admin_last_name].nil? or args[:admin_password].nil? or args[:contact_email].nil? or
    args[:contact_first_name].nil? or args[:contact_last_name].nil? or args[:contact_password].nil?
  options = { :company_name => args[:company_name], :admin_email => args[:admin_email], :admin_first_name => args[:admin_first_name],
      :admin_last_name => args[:admin_last_name], :admin_password => args[:admin_password],
      :admin_password_confirmation => args[:admin_password_confirmation], :contact_email => args[:contact_email],
      :contact_first_name => args[:contact_first_name], :contact_last_name => args[:contact_last_name],
      :contact_password => args[:contact_password], :contact_password_confirmation => args[:contact_password_confirmation] }
  options[:parent_id] = args[:parent_id] unless args[:parent_id].nil?
  options[:currency] = args[:currency] unless args[:currency].nil?
  options[:address1] = args[:address1] unless args[:address1].nil?
  options[:address2] = args[:address2] unless args[:address2].nil?
  options[:city] = args[:city] unless args[:city].nil?
  options[:province_id] = args[:province_id] unless args[:province_id].nil?
  options[:postal_code] = args[:postal_code] unless args[:postal_code].nil?
  options[:country_id] = args[:country_id] unless args[:country_id].nil?
  options[:website] = args[:website] unless args[:website].nil?
  options[:phone] = args[:phone] unless args[:phone].nil?
  options[:fax] = args[:fax] unless args[:fax].nil?
  options[:admin_title] = args[:admin_title] unless args[:admin_title].nil?
  options[:admin_office_phone] = args[:admin_office_phone] unless args[:admin_office_phone].nil?
  options[:admin_mobile_phone] = args[:admin_mobile_phone] unless args[:admin_mobile_phone].nil?
  options[:admin_language] = args[:admin_language] unless args[:admin_language].nil?
  options[:admin_timezone_id] =args[:admin_timezone_id] unless args[:admin_timezone_id].nil?
  options[:admin_language] = args[:admin_language] unless args[:admin_language].nil?
  options[:contact_title] = args[:contact_title] unless args[:contact_title].nil?
  options[:contact_language] = args[:contact_language] unless args[:contact_language].nil?
  options[:contact_timezone_id] = args[:contact_timezone_id] unless args[:contact_timezone_id].nil?
  options[:contact_office_phone] = args[:contact_office_phone] unless args[:contact_office_phone].nil?
  options[:contact_mobile_phone] = args[:contact_mobile_phone] unless args[:contact_mobile_phone].nil?
  res = args[:user].session.request("CakeMail::API::ClassClient", "Create", options)
  res = args[:user].session.request("CakeMail::API::ClassClient", "Activate", { :confirmation => res['confirmation'].first })
  return Client.new(id, args[:user])
end

.get_list(args) ⇒ Object

Retrieves the list of clients.

Arguments :

  • args = { :user => required, :count => optional, :status => optional, :limit => optional, :offset => optional }

Raises:

  • (ArgumentError)


141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/cakemail/client.rb', line 141

def get_list(args)
  raise ArgumentError if args.nil? or args[:user].nil?
  options = { :user_key => args[:user].user_key }
  options[:count] = args[:count] unless args[:count].nil?
  options[:status] = args[:status] unless args[:status].nil?
  options[:limit] = args[:limit] unless args[:limit].nil?
  options[:offset] = args[:offset] unless args[:offset].nil?
  res = args[:user].session.request("CakeMail::API::ClassClient", "GetList", options)
  if !args[:count].nil?
    return res['count'].first
  end
  return res['client']
end

.get_timezones(user) ⇒ Object

Returns the list with the supported timezones.



155
156
157
158
# File 'lib/cakemail/client.rb', line 155

def get_timezones(user)
  res = user.session.request("CakeMail::API::ClassClient", "GetTimezones", {})
  res['timezone']
end

Instance Method Details

#get_info(id = @id) ⇒ Object

Returns information about a client.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cakemail/client.rb', line 41

def get_info(id = @id)
  @user.session.request("CakeMail::API::ClassClient", "GetInfo", { :client_id => @id, :user_key => @user.user_key })
  @registered_date = res['registered_date'].first
  @last_activity = res['last_activity'].first
  @manager_id = res['manager_id'].first
  @parent_id = res['parent_id'].first
  @contact_id = res['contact_id'].first
  @province_id = res['province_id'].first
  @country_id = res['country_id'].first
  @limit = res['limit'].first
  @status = res['status'].first
  @currency = res['currency'].first
  @company_name = res['company_name'].first
  @address1 = res['address1'].first
  @address2 = res['address2'].first
  @city = res['city'].first
  @postal_code = res['postal_code'].first
  @website = res['website'].first
  @phone = res['phone'].first
  @fax = res['fax'].first
end

#saveObject



63
64
65
# File 'lib/cakemail/client.rb', line 63

def save
  set_info
end

#set_info(client_id = nil) ⇒ Object

Modifies a client.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cakemail/client.rb', line 67

def set_info(client_id = nil)
  args = { :user_key => @user.user_key }
  if !client_id.nil?
    args[:client_id] = client_id
  else
    args[:client_id] = @id unless @id.nil?
  end
  args[:status] = @status unless @status.nil?
  args[:manager_id] = @manager_id unless @manager_id.nil?
  args[:parent_id] = @parent_id unless @parent_id.nil?
  args[:contact_id] = @contact_id unless @contact_id.nil?
  args[:company_name] = @company_name unless @company_name.nil?
  args[:address1] = @address1 unless @address1.nil?
  args[:address2] = @address2 unless @address2.nil?
  args[:city] = @city unless @city.nil?
  args[:province_id] = @province_id unless @province_id.nil?
  args[:postal_code] = @postal_code unless @postal_code.nil?
  args[:country_id] = @country_id unless @country_id.nil?
  args[:website] = @website unless @website.nil?
  args[:phone] = @phone unless @phone.nil?
  args[:fax] = @fax unless @fax.nil?
  @user.session.request("CakeMail::API::ClassClient", "SetInfo", args)
end