module Spymaster

Constants

VERSION

Public Class Methods

alert_validate_fail(field = nil) click to toggle source

> Alert when invalidate

# File lib/spymaster.rb, line 71
def self.alert_validate_fail(field = nil)
        return "Invalidate param #{field}"
end
app_name() click to toggle source

> Get app name

# File lib/spymaster.rb, line 16
def self.app_name
        return @@app_name
end
app_version() click to toggle source

> Get app version

# File lib/spymaster.rb, line 21
def self.app_version
        return @@app_version
end
check_validate(field, value, class_type) click to toggle source

> Check validate value

# File lib/spymaster.rb, line 59
def self.check_validate(field, value, class_type)
        return if value == nil
        if (value.class == class_type)
                puts("true")
                return value.to_json
        else
                puts(self.alert_validate_fail(field))
                return {}.to_json
        end
end
setup(t_app_name = nil, t_app_version = nil, t_uri = 'http://localhost:3000/global/track') click to toggle source

> Setup config settings

# File lib/spymaster.rb, line 8
def self.setup(t_app_name = nil, t_app_version = nil, t_uri = 'http://localhost:3000/global/track')
        @@app_name = t_app_name
        @@app_version = t_app_version
        @@uri = t_uri
        puts("Init Spymaster success" + @@app_name + @@app_version)
end
track(params = {}) click to toggle source

> Send tracking

# File lib/spymaster.rb, line 31
def self.track(params = {})
        uri = URI(@@uri)
        fields_hash_type = ['platform', 'device', 'browser', 'extras']
        params.each do |field, value|
                value_convert = (fields_hash_type.include? field.to_s) ? self.check_validate(field, value, Hash) : value
                params[field] = value_convert
        end
        params = {
                :app_name => @@app_name, 
                :app_version => @@app_version
        }.merge(params)

        uri.query = URI.encode_www_form(params)

        res = Net::HTTP.get_response(uri)             
        if res.is_a?(Net::HTTPSuccess)
                return {
                        :status => res.code,
                        :response => res.body
                } 
        else
                return {
                        :status => res.code
                }
        end
end
uri() click to toggle source

> Get uri

# File lib/spymaster.rb, line 26
def self.uri
        return @@uri
end