Class: FyipeLogger

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fyipeLogger.rb

Instance Method Summary collapse

Constructor Details

#initialize(apiUrl, applicationLogId, applicationLogKey) ⇒ FyipeLogger

FyipeLogger constructor.

Parameters:

  • string

    apiUrl

  • string

    applicationLogId

  • string

    applicationLogKey


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, tags = nil)
    validateItems(content, tags)

    #set log type
    logType = "error";
    return makeApiRequest(content, logType, tags)
end

#log(content, tags = nil) ⇒ Object


38
39
40
41
42
43
44
# File 'lib/fyipeLogger.rb', line 38

def log(content, tags = nil)
    validateItems(content, tags)

    #set log type
    logType = "info";
    return makeApiRequest(content, logType, tags)
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, tags = nil)
    # make api request and return response 
    
    body = { content: data, type: type, applicationLogKey: @applicationLogKey }
    if (tags != nil)    
        body['tags'] = 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, tags)
     # get the class of the content and convert to string for comparison
     contentType = content.class.to_s
     tagType = tags != nil ? tags.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, tags = nil)
    validateItems(content, tags)

    #set log type
    logType = "warning";
    return makeApiRequest(content, logType, tags)
end