Class: Racked

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Racked

Returns a new instance of Racked.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/racked.rb', line 37

def initialize(options)
  check_options(options, [:server_host, :version_prefix, :user_key, :secret_hash])
  @server_host = options[:server_host]
  @version_prefix = options[:version_prefix]
  @user_key = options[:user_key]
  @secret_hash = options[:secret_hash]
  #read config file
  # @server = Server.new(MAIL_CFG["server"], MAIL_CFG["version_prefix"], MAIL_CFG["user_key"], MAIL_CFG["secret_hash"])
  @server = Server.new(options[:server_host], options[:version_prefix], options[:user_key], options[:secret_hash])
  @server.xml_format
      
end

Instance Attribute Details

#secret_hashObject

include Singleton



35
36
37
# File 'lib/racked.rb', line 35

def secret_hash
  @secret_hash
end

#server_hostObject

include Singleton



35
36
37
# File 'lib/racked.rb', line 35

def server_host
  @server_host
end

#user_keyObject

include Singleton



35
36
37
# File 'lib/racked.rb', line 35

def user_key
  @user_key
end

#version_prefixObject

include Singleton



35
36
37
# File 'lib/racked.rb', line 35

def version_prefix
  @version_prefix
end

Instance Method Details

#add_customer(options) ⇒ Object



143
144
145
146
147
148
# File 'lib/racked.rb', line 143

def add_customer(options)
  check_options(options, [:data_fields_hash])
  #add a customer account
  response = @server.post  "/customers", @data_fields_hash, @server.json_format
  return response
end

#add_domain(options) ⇒ Object



154
155
156
157
158
159
# File 'lib/racked.rb', line 154

def add_domain(options)
  check_options(options, [:domain, :customer_number, :data_fields_hash])
  #add a domain
  response = @server.post  "/customers/#{@customer_number}/domains/#{@domain}", @data_fields_hash, @server.json_format
  return response
end

#create_mailbox(options) ⇒ Object



110
111
112
113
114
115
116
117
118
119
# File 'lib/racked.rb', line 110

def create_mailbox(options)
  check_options(options, [:domain, :customer_number, :mailbox_type, :mailbox, :data_fields_hash])
  #create a customer mailbox
  response = @server.post  "/customers/#{@customer_number}/domains/#{@domain}/#{@mailbox_type}/mailboxes/#{@mailbox}", @data_fields_hash, @server.json_format
  # puts response.inspect
  # puts response['x-error-message']
  # puts response.body.inspect
  return response
  #response = JSON.parse(response.body )
end

#delete_customer(options) ⇒ Object



149
150
151
152
153
# File 'lib/racked.rb', line 149

def delete_customer(options)
  check_options(options, [:customer_number])
  response = @server.delete  "/customers/#{@customer_number}", @server.json_format
  return response
end

#delete_domain(options) ⇒ Object



160
161
162
163
164
# File 'lib/racked.rb', line 160

def delete_domain(options)
  check_options(options, [:domain, :customer_number])
  response = @server.delete  "/customers/#{@customer_number}/domains/#{@domain}", @server.json_format
  return response
end

#delete_mailbox(options) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/racked.rb', line 132

def delete_mailbox(options)
  #delete a customer mailbox
  check_options(options, [:domain, :customer_number, :mailbox_type, :mailbox])
  response = @server.delete  "/customers/#{@customer_number}/domains/#{@domain}/#{@mailbox_type}/mailboxes/#{@mailbox}", @server.json_format
  # puts response.inspect
  # puts response['x-error-message']
  # puts response.body.inspect
  return response
  #response = JSON.parse(response.body )
end

#get_domain_info(options) ⇒ Object



50
51
52
53
# File 'lib/racked.rb', line 50

def get_domain_info(options)
  check_options(options, [:domain, :customer_number])
  response = @server.get  "/customers/#{@customer_number}/domains/#{@domain}", @server.json_format
end

#get_last_login(account_details_for_soap = {}, mailbox) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/racked.rb', line 95

def ( = {}, mailbox)
  #TO DO: need to rethink
  check_options(options, [:mailbox])
  
  self.(options[:account_details])
  driver = UtilsSoapPort.new
  # driver.wiredump_dev = STDOUT

  res = driver.GetUserLastLogin(@account_details[:resellerUsername], @account_details[:resellerPassword], @account_details[:hostName], @mailbox, @account_details[:lastlogin])
  # if res[1].class == String && !res[1].empty?
  #   puts "yes"
  # end
  return res
end

#get_mailbox_details(options) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/racked.rb', line 77

def get_mailbox_details(options)
  check_options(options, [:domain, :customer_number, :mailbox_type, :mailbox])
  
  #get mailbox details
  response = @server.get  "/customers/#{@customer_number}/domains/#{@domain}/#{@mailbox_type}/mailboxes/" + @mailbox, @server.json_format
  puts response.inspect
  puts response['x-error-message']
  # response = JSON.parse(response)
  puts response.code
  puts response.body
  # puts response.inspect
  #TO DO: error checking
  # returning [] do |mailboxes|
  #   response["rsMailboxes"].each {|c| mailboxes << Mailbox.new(c) }
  # end
  return response
end

#get_mailboxes(size = 50, offset = 0) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/racked.rb', line 55

def get_mailboxes(size=50, offset=0)
  check_options(options, [:domain, :customer_number, :mailbox_type])
  size = options[:size] || 50
  offset = options[:offset] || 0
  #get customer list
  response = @server.get  "/customers/#{@customer_number}/domains/#{@domain}/#{@mailbox_type}/mailboxes/?size=" + size.to_s + '&offset=' + offset.to_s, @server.json_format
  puts response.inspect
  # puts response['x-error-message']
  # puts response.body
  response = JSON.parse(response.body )
  # puts response.inspect
  #TO DO: error checking
  # returning [] do |mailboxes|
  #   response["rsMailboxes"].each {|c| mailboxes << Mailbox.new(c) }
  # end
  mailboxes = []
  response["rsMailboxes"].each do |mailbox|
    puts 'mailbox - ' + mailbox["name"]
    #mailboxes << Mailbox.new(mailbox)
    mailboxes << mailbox
  end
end

#update_mailbox(options) ⇒ Object



121
122
123
124
125
126
127
128
129
130
# File 'lib/racked.rb', line 121

def update_mailbox(options)
  check_options(options, [:domain, :customer_number, :mailbox_type, :mailbox, :data_fields_hash])
  #update a customer mailbox
  response = @server.put  "/customers/#{@customer_number}/domains/#{@domain}/#{@mailbox_type}/mailboxes/#{@mailbox}", @data_fields_hash, @server.json_format
  # puts response.inspect
  # puts response['x-error-message']
  # puts response.body.inspect
  return response
  #response = JSON.parse(response.body )
end