Class: GcxApi::User

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

Class Method Summary collapse

Class Method Details

.create(site_name, users) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gcx_api/user.rb', line 7

def self.create(site_name, users)
  parameters = users.to_json
  service_url = GcxApi::User.create_endpoint(site_name)
  ticket = GcxApi::Cas.new.get_cas_service_ticket(service_url)

  attr = {:method => :post, :url => service_url + '?ticket=' + ticket, :payload => parameters, :timeout => -1}
  Rails.logger.debug attr
  res = RestClient::Request.execute(:method => :post, :url => service_url + '?ticket=' + ticket, :payload => parameters, :timeout => -1) { |response, request, result, &block|
                                    Rails.logger.debug request.to_s
                                    Rails.logger.debug response.to_s
                                    Rails.logger.debug result.to_s
                                    # check for error response
                                    if response.code.to_i == 400
                                      raise response.inspect
                                    end
                                    if response.code.to_i != 200
                                      raise result.inspect
                                    end
                                    response.to_str
  }
  JSON.parse(res)
end

.create_endpoint(site_name) ⇒ Object



3
4
5
# File 'lib/gcx_api/user.rb', line 3

def self.create_endpoint(site_name)
  GcxApi.gcx_url + "/#{site_name}/wp-gcx/add-users.php"
end