Class: RS::SysRequest

Inherits:
BaseRequest show all
Includes:
Singleton
Defined in:
lib/rs/requests/sys.rb

Overview

System administration related methods.

Constant Summary

Constants inherited from BaseRequest

BaseRequest::DEFAULTS, BaseRequest::INVOICE_SERVICE_URL, BaseRequest::WAYBILL_SERVICE_URL

Instance Attribute Summary

Attributes inherited from BaseRequest

#last_error_code

Instance Method Summary collapse

Methods inherited from BaseRequest

#format_date, #invoice_client, #validate_presence_of, #waybill_client

Instance Method Details

#check_user(opts) ⇒ Object

Check service user. Also used for getting user’s ID and payer’s ID.

possible parameters:

‘su` – service username `sp` – service password

Returns hash with the following structure:

“‘ ’payer unique ID’, user: ‘user unique ID’ “‘



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rs/requests/sys.rb', line 84

def check_user(opts)
  validate_presence_of(opts, :su, :sp)
  response = waybill_client.request 'chek_service_user' do
    soap.body = {'su' => opts[:su], 'sp' => opts[:sp] }
  end
  if response[:chek_service_user_response][:chek_service_user_result]
    payer_id = response[:chek_service_user_response][:un_id]
    user_id  = response[:chek_service_user_response][:s_user_id]
    {payer: payer_id, user: user_id}
  end
end

#error_codes(opts = {}) ⇒ Object

Returns error codes.



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rs/requests/sys.rb', line 97

def error_codes(opts = {})
  validate_presence_of(opts, :su, :sp)
  response = waybill_client.request 'get_error_codes' do
    soap.body = {'su' => opts[:su], 'sp' => opts[:sp] }
  end
  errors = {}
  response[:get_error_codes_response][:get_error_codes_result][:error_codes][:error_code].each do |el|
    errors[el[:id].to_i] = el[:text]
  end
  errors
end

#get_users(opts) ⇒ Object

# Create service user. # # * ‘username` – login for the main user # * `password` – password for the main user # * `ip` – your IP address # * `name` – some name for this user/ip configuration # * `su` – new user login # * `sp` – new user password def create_user(opts)

validate_presence_of(opts, :username, :password, :ip, :name, :su, :sp)
response = waybill_client.request 'create_service_user' do
  soap.body = {'user_name' => opts[:username], 'user_password' => opts[:password], 'ip' => opts[:ip], 'name' => opts[:name], 'su' => opts[:su], 'sp' => opts[:sp]}
end
response.to_hash[:create_service_user_response][:create_service_user_result]

end



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rs/requests/sys.rb', line 37

def get_users(opts)
  validate_presence_of(opts, :username, :password)
  response = (waybill_client.request 'get_service_users' do
          soap.body = { 'user_name' => opts[:username], 'user_password' => opts[:password] }
        end).to_hash
  if response[:get_service_users_response][:get_service_users_result][:service_users].blank?
    raise 'illegal username/password'
  else
    users = []
    users_data = response[:get_service_users_response][:get_service_users_result][:service_users][:service_user]
    if users_data.is_a?(Array)
      users_data.each { |data| users << RS::User.extract(data) }
    else
      users << RS::User.extract(users_data)
    end
    users
  end
end

#update_user(opts) ⇒ Object

Update service user.

  • ‘username` – login for the main user

  • ‘password` – password for the main user

  • ‘ip` – your IP address

  • ‘name` – some name for this user/ip configuration

  • ‘su` – user login

  • ‘sp` – user’s passwrod



64
65
66
67
68
69
70
# File 'lib/rs/requests/sys.rb', line 64

def update_user(opts)
  validate_presence_of(opts, :username, :password, :ip, :name, :su, :sp)
  response = waybill_client.request 'update_service_user' do
    soap.body = {'user_name' => opts[:username], 'user_password' => opts[:password], 'ip' => opts[:ip], 'name' => opts[:name], 'su' => opts[:su], 'sp' => opts[:sp]}
  end
  response.to_hash[:update_service_user_response][:update_service_user_result]
end

#what_is_my_ipObject

Get your outside IP address.



16
17
18
19
# File 'lib/rs/requests/sys.rb', line 16

def what_is_my_ip
  response = waybill_client.request 'what_is_my_ip'
  response.to_hash[:what_is_my_ip_response][:what_is_my_ip_result].strip
end