Module: CloudmunchService

Includes:
Util
Included in:
AppAbstract
Defined in:
lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

generateReport, getJSONArgs, getJSONArgsTEMP, getTemplate, getUrlForViewCards, log, logClose, logInit, logIt, openJSONFile

Class Method Details

.getCustomDataContext(server, endpoint, param) ⇒ Object



69
70
71
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 69

def self.getCustomDataContext(server, endpoint, param)
   return self.http_get(server, endpoint, param)
end

.getDataContext(server, endpoint, param) ⇒ Object



95
96
97
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 95

def self.getDataContext(server, endpoint, param)
   getCustomDataContext(server, endpoint, param)     
end

.http_get(server, path, params) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 73

def self.http_get(server,path,params)
   if params.nil?
    return Net::HTTP.get(server, path)
   else
      queryStr =  "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
      puts ("SDKDEBUG: Calling URL " + server+queryStr)
      uri = URI(server + "/" + queryStr)
      return Net::HTTP.get(uri) 
   end
end

.http_post(server, path, params) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 84

def self.http_post(server,path,params)
     queryStr =  "#{path}?".concat(params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&'))
     puts ("SDKDEBUG: Calling URL " + server+queryStr)
     if params.nil?
         return Net::HTTP.post(server, path)
     else
         uri = URI(server +  path)
         return Net::HTTP.post_form(uri, params)
     end
end

.initialize(appcontext) ⇒ Object



11
12
13
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 11

def self.initialize(appcontext)
 @applicationContext=appcontext
end

.putCustomDataContext(server, endpoint, param) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 58

def self.putCustomDataContext(server, endpoint, param)
   result = self.http_post(server, endpoint, param)
   #p result.code.to_s 
   if result.code.to_s == "200"
     return true 
   else
     return false 
   end     
end

.updateDataContext(server, endpoint, param) ⇒ Object



100
101
102
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 100

def self.updateDataContext(server, endpoint, param)
   putCustomDataContext(server, endpoint, param)  
end

Instance Method Details

#deleteCloudmunchData(context, contextid) ⇒ Object



48
49
50
51
52
53
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 48

def deleteCloudmunchData(context,contextid)
 serverurl=@applicationContext.get_data("{master_url}")+"/applications/"+@applicationContext.get_data("{application}")+"/"+context+"/"+contextid;
serverurl=serverurl+"?apikey="+@applicationContext.get_data("{api_key}")
 uri = URI.parse(serverurl)
 Net::HTTP::Delete(uri)
end

#getCloudmunchData(context, contextid, filterdata) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 28

def getCloudmunchData(context,contextid,filterdata)
 if contextid.nil? || contextid.empty?
  serverurl=@applicationContext.get_data("{master_url}")+"/applications/"+@applicationContext.get_data("{application}")+"/"+context
  else
  serverurl=@applicationContext.get_data("{master_url}")+"/applications/"+@applicationContext.get_data("{application}")+"/"+context+"/"+contextid;
 end
 querystring=""
 if filterdata.nil? || filterdata.empty?
   serverurl=serverurl+"?apikey="+@applicationContext.get_data("{api_key}")
 else
   querystring="filter="+to_json($filerdata);
   serverurl=serverurl+"?"+querystring+"&apikey="+@applicationContext.get_data("{api_key}")
 
 end
uri = URI.parse(serverurl)
 
  return Net::HTTP.get(uri)
end

#updateCloudmunchData(context, contextid, data) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/cloudmunch_Ruby_sdk_v2/CloudmunchService.rb', line 15

def updateCloudmunchData(context,contextid,data)
 
 serverurl=@applicationContext.get_data("{master_url}")+"/applications/"+@applicationContext.get_data("{application}")+"/"+context+"/"+contextid;
 serverurl=serverurl+"?apikey="+@applicationContext.get_data("{api_key}")
  uri = URI.parse(serverurl)
 
  response= Net::HTTP.post_form(uri,"data" => data.to_json)
  
  return response.body
end