spymaster 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/spymaster.rb +74 -0
- data/lib/spymaster/version.rb +3 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2dc6e443f85c014e94aa6ea0317885865e040a18
|
4
|
+
data.tar.gz: a923d96544d87d9633059b593abf885a73358a36
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 497c8eeeac3f2469d7a43c70a252bc67afccb3b1de0db103201bf4f5d656f2a4b98a1d88bd01a4f0e801476cf48607209793187cb5468ef43369475ec5e614e8
|
7
|
+
data.tar.gz: f73f4480cc22282b79639b2233cb8591e6d6229082eb549eee3597e5ad5a0d14ec4587d528fa7171f3e4fb79a51af22f2e3e9ae7988cb9786773397bb691afb4
|
data/lib/spymaster.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spymaster/version"
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Spymaster
|
5
|
+
@@app_name = nil, @@app_version = nil, @@uri = 'http://localhost:3000/global/track'
|
6
|
+
|
7
|
+
# => Setup config settings
|
8
|
+
def self.setup(t_app_name = nil, t_app_version = nil, t_uri = 'http://localhost:3000/global/track')
|
9
|
+
@@app_name = t_app_name
|
10
|
+
@@app_version = t_app_version
|
11
|
+
@@uri = t_uri
|
12
|
+
puts("Init Spymaster success" + @@app_name + @@app_version)
|
13
|
+
end
|
14
|
+
|
15
|
+
# => Get app name
|
16
|
+
def self.app_name
|
17
|
+
return @@app_name
|
18
|
+
end
|
19
|
+
|
20
|
+
# => Get app version
|
21
|
+
def self.app_version
|
22
|
+
return @@app_version
|
23
|
+
end
|
24
|
+
|
25
|
+
# => Get uri
|
26
|
+
def self.uri
|
27
|
+
return @@uri
|
28
|
+
end
|
29
|
+
|
30
|
+
# => Send tracking
|
31
|
+
def self.track(params = {})
|
32
|
+
uri = URI(@@uri)
|
33
|
+
fields_hash_type = ['platform', 'device', 'browser', 'extras']
|
34
|
+
params.each do |field, value|
|
35
|
+
value_convert = (fields_hash_type.include? field.to_s) ? self.check_validate(field, value, Hash) : value
|
36
|
+
params[field] = value_convert
|
37
|
+
end
|
38
|
+
params = {
|
39
|
+
:app_name => @@app_name,
|
40
|
+
:app_version => @@app_version
|
41
|
+
}.merge(params)
|
42
|
+
|
43
|
+
uri.query = URI.encode_www_form(params)
|
44
|
+
|
45
|
+
res = Net::HTTP.get_response(uri)
|
46
|
+
if res.is_a?(Net::HTTPSuccess)
|
47
|
+
return {
|
48
|
+
:status => res.code,
|
49
|
+
:response => res.body
|
50
|
+
}
|
51
|
+
else
|
52
|
+
return {
|
53
|
+
:status => res.code
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# => Check validate value
|
59
|
+
def self.check_validate(field, value, class_type)
|
60
|
+
return if value == nil
|
61
|
+
if (value.class == class_type)
|
62
|
+
puts("true")
|
63
|
+
return value.to_json
|
64
|
+
else
|
65
|
+
puts(self.alert_validate_fail(field))
|
66
|
+
return {}.to_json
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# => Alert when invalidate
|
71
|
+
def self.alert_validate_fail(field = nil)
|
72
|
+
return "Invalidate param #{field}"
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spymaster
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hoptq
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Tracking system ruby lib
|
42
|
+
email:
|
43
|
+
- hoptq@topica.edu.vn
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/spymaster.rb
|
49
|
+
- lib/spymaster/version.rb
|
50
|
+
homepage: http://pedia.vn
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.4.8
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Tracking system
|
74
|
+
test_files: []
|