Class: FyipeLogger
Instance Method Summary collapse
- #error(content, tags = nil) ⇒ Object
-
#initialize(apiUrl, applicationLogId, applicationLogKey) ⇒ FyipeLogger
constructor
FyipeLogger constructor.
- #log(content, tags = nil) ⇒ Object
- #makeApiRequest(data, type, tags = nil) ⇒ Object
- #setApiUrl(apiUrl) ⇒ Object
- #validateItems(content, tags) ⇒ Object
- #warning(content, tags = nil) ⇒ Object
Constructor Details
#initialize(apiUrl, applicationLogId, applicationLogKey) ⇒ FyipeLogger
FyipeLogger constructor.
11 12 13 14 15 16 |
# File 'lib/fyipeLogger.rb', line 11 def initialize(apiUrl, applicationLogId, applicationLogKey) # instance variable intialzation @applicationLogId = applicationLogId setApiUrl(apiUrl) @applicationLogKey = applicationLogKey end |
Instance Method Details
#error(content, tags = nil) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/fyipeLogger.rb', line 54 def error(content, = nil) validateItems(content, ) #set log type logType = "error"; return makeApiRequest(content, logType, ) end |
#log(content, tags = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fyipeLogger.rb', line 38 def log(content, = nil) validateItems(content, ) #set log type logType = "info"; return makeApiRequest(content, logType, ) end |
#makeApiRequest(data, type, tags = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fyipeLogger.rb', line 62 def makeApiRequest(data, type, = nil) # make api request and return response body = { content: data, type: type, applicationLogKey: @applicationLogKey } if ( != nil) body['tags'] = ; end params = { body: body } response = self.class.post(@apiUrl, params).parsed_response return response end |
#setApiUrl(apiUrl) ⇒ Object
18 19 20 |
# File 'lib/fyipeLogger.rb', line 18 def setApiUrl(apiUrl) @apiUrl = apiUrl + '/application-log/' + @applicationLogId + '/log'; end |
#validateItems(content, tags) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fyipeLogger.rb', line 22 def validateItems(content, ) # get the class of the content and convert to string for comparison contentType = content.class.to_s tagType = != nil ? .class.to_s : nil # check if content type is not a string or hash object if(!((contentType.eql? "String") || (contentType.eql? "Hash"))) raise "Invalid Content to be logged" end # check if tag type is avialable and its not a string or hash object if(tagType != nil && (!((tagType.eql? "String") || (tagType.eql? "Array")))) raise "Invalid Content Tags to be logged" end end |
#warning(content, tags = nil) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/fyipeLogger.rb', line 46 def warning(content, = nil) validateItems(content, ) #set log type logType = "warning"; return makeApiRequest(content, logType, ) end |