Class: CumulogicClient::BaseClient
- Inherits:
-
Object
- Object
- CumulogicClient::BaseClient
- Defined in:
- lib/cumulogic_client/base_client.rb
Instance Method Summary collapse
- #call(command, params = nil) ⇒ Object
- #get_serviceplans(createdBy, serviceType) ⇒ Object
-
#initialize(api_url, username, password, use_ssl = nil, debug = false) ⇒ BaseClient
constructor
A new instance of BaseClient.
- #login ⇒ Object
- #provisioning_completed(targetobject, timeout = nil) ⇒ Object
- #request(command, params = nil) ⇒ Object
Constructor Details
#initialize(api_url, username, password, use_ssl = nil, debug = false) ⇒ BaseClient
Returns a new instance of BaseClient.
19 20 21 22 23 24 25 26 |
# File 'lib/cumulogic_client/base_client.rb', line 19 def initialize(api_url, username, password, use_ssl=nil, debug=false) @api_url = api_url @username = username @password = password @use_ssl = use_ssl @debug = debug @validationparams = nil end |
Instance Method Details
#call(command, params = nil) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/cumulogic_client/base_client.rb', line 28 def call(command, params=nil) login() if not @validationparams callparams = Hash.new() callparams[:inputParams] = Array.new(1) callparams[:inputParams][0] = params if params callparams[:validationParams] = @validationparams request(command, callparams) end |
#get_serviceplans(createdBy, serviceType) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/cumulogic_client/base_client.rb', line 98 def get_serviceplans(createdBy, serviceType) params = { 'createdBy' => createdBy, 'serviceType' => serviceType } call('serviceplan/getAllServicePlansByUserId', params) end |
#login ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cumulogic_client/base_client.rb', line 66 def login() credentials = Array.new(1) credentials[0] = { "userName" => @username, "password" => @password } login_params = Hash.new login_params["validationParams"] = Hash.new login_params["inputParams"] = credentials loginresponse = request("auth/login", login_params) @validationparams = { "userID" => loginresponse[0]["userID"], "userName" => loginresponse[0]["userName"], "userLoginToken" => loginresponse[0]["userLoginToken"] } end |
#provisioning_completed(targetobject, timeout = nil) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cumulogic_client/base_client.rb', line 84 def provisioning_completed(targetobject, timeout=nil) return Timeout::timeout(timeout) do while true do if not targetobject.isComplete() puts "returned false" sleep 10 else puts "returned true" return true end end end end |
#request(command, params = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cumulogic_client/base_client.rb', line 37 def request(command, params=nil) url = "#{@api_url}#{command}" puts url if @debug puts params.to_json if @debug uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = @use_ssl http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.body = URI::encode(params.to_json) if params response = http.request(request) if !response.is_a?(Net::HTTPOK) if ["431","530","404"].include?(response.code) raise ArgumentError, response. end raise RuntimeError, "Username and password not accepted" if ["401","403"].include?(response.code) raise RuntimeError, "Unknown error: code=#{response.code} message=#{response.}" end puts response.body if @debug responsedata = JSON.parse(response.body) raise RuntimeError, "Errors: #{responsedata["errors"]}" if not responsedata["success"] return responsedata["response"] end |