whmcs-ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ # whmcs-ruby
2
+
3
+ whmcs-ruby provides Ruby bindings for the [WHMCS API](http://wiki.whmcs.com/API:Functions).
4
+
5
+
6
+ ## Usage
7
+
8
+ require 'whmcs'
9
+
10
+ WHMCS.configure do |config|
11
+ config.api_url = 'http://example.com/includes/api.php'
12
+ config.api_username = 'someusername'
13
+ config.api_password = 'c4ca4238a0b923820dcc509a6f75849b' # md5 hash
14
+ end
15
+
16
+ WHMCS::Client.get_clients_details(:clientid => '1')
17
+
18
+ See the [documentation](http://dotblock.github.com/whmcs-ruby/) for more
19
+ details.
20
+
21
+
22
+ ## Installation
23
+
24
+ gem install whmcs-ruby
25
+
26
+
27
+ ## Copyright
28
+
29
+ Copyright (c) 2011 DotBlock.com, see LICENSE in this repo for details.
@@ -0,0 +1,31 @@
1
+ $:.unshift 'lib'
2
+
3
+ task :default => :test
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test' << '.'
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = true
10
+ end
11
+
12
+ desc "Open an irb session preloaded with this library"
13
+ task :console do
14
+ sh "irb -rubygems -r ./lib/whmcs.rb -I ./lib"
15
+ end
16
+
17
+ require 'sdoc_helpers'
18
+ desc "Push a new version to Gemcutter"
19
+ task :publish do
20
+ require 'whmcs/version'
21
+
22
+ ver = WHMCS::Version
23
+
24
+ sh "gem build whmcs-ruby.gemspec"
25
+ sh "gem push whmcs-ruby-#{ver}.gem"
26
+ sh "git tag -a -m 'whmcs-ruby v#{ver}' v#{ver}"
27
+ sh "git push origin v#{ver}"
28
+ sh "git push origin master"
29
+ sh "git clean -fd"
30
+ sh "rake pages"
31
+ end
@@ -0,0 +1,30 @@
1
+ module WHMCS
2
+ autoload :Version, "whmcs/version"
3
+ autoload :Config, "whmcs/config"
4
+ autoload :Base, "whmcs/base"
5
+ autoload :Client, "whmcs/client"
6
+ autoload :Invoice, "whmcs/invoice"
7
+ autoload :Misc, "whmcs/misc"
8
+ autoload :Module, "whmcs/module"
9
+ autoload :Order, "whmcs/order"
10
+ autoload :Quote, "whmcs/quote"
11
+ autoload :Ticket, "whmcs/ticket"
12
+
13
+ class << self
14
+ attr_accessor :config
15
+ end
16
+
17
+ self.config ||= Config.new
18
+
19
+ # Pass a block to configure the WHMCS API
20
+ #
21
+ # WHMCS.configure do |config|
22
+ # config.api_username = 'apiuser'
23
+ # config.api_password = 'c4ca4238a0b923820dcc509a6f75849b'
24
+ # config.api_url = 'http://example.com/includes/api.php
25
+ # end
26
+ def self.configure
27
+ yield config
28
+ config
29
+ end
30
+ end
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'crack'
4
+
5
+ module WHMCS
6
+ # WHMCS::Base is the main class used to subclass WHMCS API resources
7
+ class Base
8
+
9
+ # Sends an API request to the WHMCS API
10
+ #
11
+ # Parameters:
12
+ # * <tt>:action</tt> - The API action to perform
13
+ #
14
+ # All other paramters are passed along as HTTP POST variables
15
+ def self.send_request(params = {})
16
+ if params[:action].blank?
17
+ raise "No API action set"
18
+ end
19
+
20
+ params.merge!(
21
+ :username => WHMCS.config.api_username,
22
+ :password => WHMCS.config.api_password
23
+ )
24
+
25
+ url = URI.parse(WHMCS.config.api_url)
26
+
27
+ http = Net::HTTP.new(url.host, url.port)
28
+
29
+ if url.port == 443
30
+ http.use_ssl = true
31
+ end
32
+
33
+ req = Net::HTTP::Post.new(url.path)
34
+ req.set_form_data(params)
35
+
36
+ res = http.start { |http| http.request(req) }
37
+ parse_response(res.body)
38
+ end
39
+
40
+ # Converts the API response to a Hash
41
+ def self.parse_response(raw)
42
+ return {} if raw.to_s.blank?
43
+
44
+ if raw.match(/xml version/)
45
+ Crack::XML.parse(raw)
46
+ else
47
+ Hash[raw.split(';').map { |line| line.split('=') }]
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ # Fix Net::HTTP so we dont get
54
+ # warning: peer certificate won't be verified in this SSL session
55
+ #
56
+ # See:
57
+ #
58
+ # http://www.5dollarwhitebox.org/drupal/node/64
59
+ module Net #:nodoc:all
60
+ class HTTP
61
+ alias_method :old_initialize, :initialize
62
+
63
+ def initialize(*args)
64
+ old_initialize(*args)
65
+ @ssl_context = OpenSSL::SSL::SSLContext.new
66
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,326 @@
1
+ module WHMCS
2
+ # WHMCS::Client is the class for managing clients
3
+ class Client < Base
4
+
5
+ # Create a new client
6
+ #
7
+ # Parameters:
8
+ #
9
+ # * <tt>:firstname</tt>
10
+ # * <tt>:lastname</tt>
11
+ # * <tt>:companyname</tt> - optional
12
+ # * <tt>:email</tt>
13
+ # * <tt>:address1</tt>
14
+ # * <tt>:address2</tt> - optional
15
+ # * <tt>:city</tt>
16
+ # * <tt>:state</tt>
17
+ # * <tt>:postcode</tt>
18
+ # * <tt>:country</tt> - two letter ISO country code
19
+ # * <tt>:phonenumber</tt>
20
+ # * <tt>:password2</tt> - password for the new user account
21
+ # * <tt>:currency</tt> - the ID of the currency to set the user to
22
+ # * <tt>:groupid</tt> - used to assign the client to a client group
23
+ # * <tt>:notes</tt>
24
+ # * <tt>:cctype</tt> - Visa, Mastercard, etc...
25
+ # * <tt>:cardnum</tt>
26
+ # * <tt>:expdate</tt> - in the format MMYY
27
+ # * <tt>:startdate</tt>
28
+ # * <tt>:issuenumber</tt>
29
+ # * <tt>:customfields</tt> - a base64 encoded serialized array of custom field values
30
+ # * <tt>:noemail</tt> - pass as true to surpress the client signup welcome email sending
31
+ #
32
+ # See:
33
+ #
34
+ # http://wiki.whmcs.com/API:Add_Client
35
+ def self.add_client(params = {})
36
+ params.merge!(:action => 'addclient')
37
+ send_request(params)
38
+ end
39
+
40
+ # Update a client's info
41
+ #
42
+ # Parameters:
43
+ #
44
+ # * <tt>:firstname</tt>
45
+ # * <tt>:lastname</tt>
46
+ # * <tt>:companyname</tt>
47
+ # * <tt>:email</tt>
48
+ # * <tt>:address1</tt>
49
+ # * <tt>:address2</tt>
50
+ # * <tt>:city</tt>
51
+ # * <tt>:state</tt>
52
+ # * <tt>:postcode</tt>
53
+ # * <tt>:country</tt> - two letter ISO country code
54
+ # * <tt>:phonenumber</tt>
55
+ # * <tt>:password2</tt>
56
+ # * <tt>:credit</tt> - credit balance
57
+ # * <tt>:taxexempt</tt> - true to enable
58
+ # * <tt>:notes</tt>
59
+ # * <tt>:cardtype</tt> - visa, mastercard, etc...
60
+ # * <tt>:cardnum</tt> - cc number
61
+ # * <tt>:expdate</tt> - cc expiry date
62
+ # * <tt>:startdate</tt> - cc start date
63
+ # * <tt>:issuenumber</tt> - cc issue number
64
+ # * <tt>:language</tt> - default language
65
+ # * <tt>:status</tt> - active or inactive
66
+ #
67
+ # See:
68
+ #
69
+ # http://wiki.whmcs.com/API:Update_Client
70
+ def self.update_client(params = {})
71
+ params.merge!(:action => 'updateclient')
72
+ send_request(params)
73
+ end
74
+
75
+ # Delete a client
76
+ #
77
+ # Parameters:
78
+ #
79
+ # * <tt>:clientid</tt> - ID Number of the client to delete
80
+ #
81
+ # See:
82
+ #
83
+ # http://wiki.whmcs.com/API:Delete_Client
84
+ def self.delete_client(params = {})
85
+ params.merge!(:action => 'deleteclient')
86
+ send_request(params)
87
+ end
88
+
89
+ # Get multiple clients
90
+ #
91
+ # Parameters:
92
+ #
93
+ # * <tt>:limitstart</tt> - Record to start at (default = 0)
94
+ # * <tt>:limitnum</tt> - Number of records to return (default = 25)
95
+ # * <tt>:search</tt> - Can be passed to filter for clients with a name/email matching the term entered
96
+ #
97
+ # See:
98
+ #
99
+ # http://wiki.whmcs.com/API:Get_Clients
100
+ def self.get_clients(params = {})
101
+ params.merge!(:action => 'getclients')
102
+ send_request(params)
103
+ end
104
+
105
+ # Get a client's info
106
+ #
107
+ # Parameters:
108
+ #
109
+ # * <tt>:clientid</tt> - the id number of the client
110
+ # * <tt>:email</tt> - the email address of the client
111
+ #
112
+ # See:
113
+ #
114
+ # http://wiki.whmcs.com/API:Get_Clients_Details
115
+ def self.get_clients_details(params = {})
116
+ params.merge!(:action => 'getclientsdetails')
117
+ send_request(params)
118
+ end
119
+
120
+ # Get a hash of a client's password
121
+ #
122
+ # Parameters:
123
+ #
124
+ # * <tt>:userid</tt> - should contain the user id of the client you wish to get the password for
125
+ #
126
+ # See:
127
+ #
128
+ # http://wiki.whmcs.com/API:Get_Clients_Password
129
+ def self.get_clients_password(params = {})
130
+ params.merge!(:action => 'getclientpassword')
131
+ send_request(params)
132
+ end
133
+
134
+ # Add a client contact
135
+ #
136
+ # Parameters:
137
+ #
138
+ # * <tt>:clientid</tt> - the client ID to add the contact to
139
+ # * <tt>:firstname</tt>
140
+ # * <tt>:lastname</tt>
141
+ # * <tt>:companyname</tt>
142
+ # * <tt>:email</tt>
143
+ # * <tt>:address1</tt>
144
+ # * <tt>:address2</tt>
145
+ # * <tt>:city</tt>
146
+ # * <tt>:state</tt>
147
+ # * <tt>:postcode</tt>
148
+ # * <tt>:country</tt> - two letter ISO country code
149
+ # * <tt>:phonenumber</tt>
150
+ # * <tt>:password2</tt> - if creating a sub-account
151
+ # * <tt>:permissions</tt> - can specify sub-account permissions eg manageproducts,managedomains
152
+ # * <tt>:generalemails</tt> - set true to receive general email types
153
+ # * <tt>:productemails</tt> - set true to receive product related emails
154
+ # * <tt>:domainemails</tt> - set true to receive domain related emails
155
+ # * <tt>:invoiceemails</tt> - set true to receive billing related emails
156
+ # * <tt>:supportemails</tt> - set true to receive support ticket related emails
157
+ #
158
+ # See:
159
+ #
160
+ # http://wiki.whmcs.com/API:Add_Contact
161
+ def self.add_contact(params = {})
162
+ params.merge!(:action => 'addcontact')
163
+ send_request(params)
164
+ end
165
+
166
+ # Get client's contacts
167
+ #
168
+ # Parameters:
169
+ #
170
+ # * <tt>:limitstart</tt> - Record to start at (default = 0)
171
+ # * <tt>:limitnum</tt> - Number of records to return (default = 25)
172
+ # * <tt>:userid</tt>
173
+ # * <tt>:firstname</tt>
174
+ # * <tt>:lastname</tt>
175
+ # * <tt>:companyname</tt>
176
+ # * <tt>:email</tt>
177
+ # * <tt>:address1</tt>
178
+ # * <tt>:address2</tt>
179
+ # * <tt>:city</tt>
180
+ # * <tt>:state</tt>
181
+ # * <tt>:postcode</tt>
182
+ # * <tt>:country</tt>
183
+ # * <tt>:phonenumber</tt>
184
+ # * <tt>:subaccount</tt> - true/false
185
+ #
186
+ # See:
187
+ #
188
+ # http://wiki.whmcs.com/API:Get_Contacts
189
+ def self.get_contacts(params = {})
190
+ params.merge!(:action => 'getcontacts')
191
+ send_request(params)
192
+ end
193
+
194
+ # Update a client's contact
195
+ #
196
+ # Parameters:
197
+ #
198
+ # * <tt>:contactid</tt> - The ID of the contact to delete
199
+ # * <tt>:generalemails</tt> - set to true to receive general emails
200
+ # * <tt>:productemails</tt> - set to true to receive product emails
201
+ # * <tt>:domainemails</tt> - set to true to receive domain emails
202
+ # * <tt>:invoiceemails</tt> - set to true to receive invoice emails
203
+ # * <tt>:supportemails</tt> - set to true to receive support emails
204
+ # * <tt>:firstname</tt> - change the firstname
205
+ # * <tt>:lastname</tt> - change the lastname
206
+ # * <tt>:companyname</tt> - change the companyname
207
+ # * <tt>:email</tt> - change the email address
208
+ # * <tt>:address1</tt> - change address1
209
+ # * <tt>:address2</tt> - change address2
210
+ # * <tt>:city</tt> - change city
211
+ # * <tt>:state</tt> - change state
212
+ # * <tt>:postcode</tt> - change postcode
213
+ # * <tt>:country</tt> - change country
214
+ # * <tt>:phonenumber</tt> - change phonenumber
215
+ # * <tt>:subaccount</tt> - enable subaccount
216
+ # * <tt>:password</tt> - change the password
217
+ # * <tt>:permissions</tt> - set permissions eg manageproducts,managedomains
218
+ #
219
+ # Only send fields you wish to update
220
+ #
221
+ # See:
222
+ #
223
+ # http://wiki.whmcs.com/API:Update_Contact
224
+ def self.update_contact(params = {})
225
+ params.merge!(:action => 'updatecontact')
226
+ send_request(params)
227
+ end
228
+
229
+ # Delete a client's contact
230
+ #
231
+ # Parameters:
232
+ #
233
+ # * <tt>:contactid</tt> - The ID of the contact to delete
234
+ #
235
+ # See:
236
+ #
237
+ # http://wiki.whmcs.com/API:Delete_Contact
238
+ def self.delete_contact(params = {})
239
+ params.merge!(:action => 'deletecontact')
240
+ send_request(params)
241
+ end
242
+
243
+ # Get client's products
244
+ #
245
+ # Parameters:
246
+ #
247
+ # * <tt>:clientid</tt> - the ID of the client to retrieve products for
248
+ # * <tt>:serviceid</tt> - the ID of the service to retrieve details for
249
+ # * <tt>:domain</tt> - the domain of the service to retrieve details for
250
+ # * <tt>:pid</tt> - the product ID of the services to retrieve products for
251
+ #
252
+ # See:
253
+ #
254
+ # http://wiki.whmcs.com/API:Get_Clients_Products
255
+ def self.get_clients_products(params = {})
256
+ params.merge!(:action => 'getclientsproducts')
257
+ send_request(params)
258
+ end
259
+
260
+ # Update client's product
261
+ #
262
+ # Parameters:
263
+ #
264
+ # * <tt>:serviceid</tt> - the ID of the service to be updated
265
+ # * <tt>:pid</tt>
266
+ # * <tt>:serverid</tt>
267
+ # * <tt>:regdate</tt> - Format: YYYY-MM-DD
268
+ # * <tt>:nextduedate</tt> - Format: YYYY-MM-DD
269
+ # * <tt>:domain</tt>
270
+ # * <tt>:firstpaymentamount</tt>
271
+ # * <tt>:recurringamount</tt>
272
+ # * <tt>:billingcycle</tt>
273
+ # * <tt>:paymentmethod</tt>
274
+ # * <tt>:status</tt>
275
+ # * <tt>:serviceusername</tt>
276
+ # * <tt>:servicepassword</tt>
277
+ # * <tt>:subscriptionid</tt>
278
+ # * <tt>:promoid</tt>
279
+ # * <tt>:overideautosuspend</tt> - on/off
280
+ # * <tt>:overidesuspenduntil</tt> - Format: YYYY-MM-DD
281
+ # * <tt>:ns1</tt>
282
+ # * <tt>:ns2</tt>
283
+ # * <tt>:dedicatedip</tt>
284
+ # * <tt>:assignedips</tt>
285
+ # * <tt>:notes</tt>
286
+ # * <tt>:autorecalc</tt> - pass true to auto set price based on product ID or billing cycle change
287
+ #
288
+ # See:
289
+ #
290
+ # http://wiki.whmcs.com/API:Update_Client_Product
291
+ def self.update_client_product(params = {})
292
+ params.merge!(:action => 'updateclientproduct')
293
+ send_request(params)
294
+ end
295
+
296
+ # Validate client login info
297
+ #
298
+ # Parameters:
299
+ #
300
+ # * <tt>:email</tt> - the email address of the user trying to login
301
+ # * <tt>:password2</tt> - the password they supply for authentication
302
+ #
303
+ # See:
304
+ #
305
+ # http://wiki.whmcs.com/API:Validate_Login
306
+ def self.validate_login(params = {})
307
+ params.merge!(:action => 'validatelogin')
308
+ send_request(params)
309
+ end
310
+
311
+ # Send email to client
312
+ #
313
+ # Parameters:
314
+ #
315
+ # * <tt>:messagename</tt> - unique name of the email template to send from WHMCS
316
+ # * <tt>:id</tt> - related ID number to send message for
317
+ #
318
+ # See:
319
+ #
320
+ # http://wiki.whmcs.com/API:Send_Email
321
+ def self.send_email(params = {})
322
+ params.merge!(:action => 'sendemail')
323
+ send_request(params)
324
+ end
325
+ end
326
+ end