botmetrics-rb 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/botmetrics-rb/version.rb +1 -1
- data/lib/botmetrics.rb +47 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 029d34f70a53015b43c0019a882e14077c7c5562
|
4
|
+
data.tar.gz: 003dcbb39b9d376d8b3db4866bcb8b895dce1630
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe363b2b7acc6edffa5b8e1fb0ded536a2cb7fc140a1d1937b40b3d340d58a36c39e74a56d7fcfc4182c7c44daf2f6bb1338b697cf561f57b04f1546c45eaf9f
|
7
|
+
data.tar.gz: fd30b7082a781d677f89a28560ae10a25f77f6d746badf5abdfbb6e69e47b327f976584ec51811e7a677b3ca284fe657a266f9f3e0e539d58274bab8559d6f63
|
data/lib/botmetrics.rb
CHANGED
@@ -30,6 +30,28 @@ module BotMetrics
|
|
30
30
|
response.code == 201
|
31
31
|
end
|
32
32
|
|
33
|
+
def track(event)
|
34
|
+
event_json = nil
|
35
|
+
|
36
|
+
if event.is_a?(Hash)
|
37
|
+
event_json = event.to_json
|
38
|
+
elsif event.is_a?(String)
|
39
|
+
begin
|
40
|
+
event_json = JSON.parse(event)
|
41
|
+
rescue JSON::ParserError
|
42
|
+
raise ArgumentError.new("event is not a valid JSON string or Hash")
|
43
|
+
end
|
44
|
+
event_json = event
|
45
|
+
end
|
46
|
+
|
47
|
+
if event_json.nil?
|
48
|
+
raise ArgumentError.new("event is not a valid JSON string or Hash")
|
49
|
+
end
|
50
|
+
|
51
|
+
response = HTTP.auth(api_key).post("#{api_url}/events", params: {event: event_json})
|
52
|
+
response.code == 201
|
53
|
+
end
|
54
|
+
|
33
55
|
def message(team_id, opts = {})
|
34
56
|
channel = opts[:channel]
|
35
57
|
user = opts[:user]
|
@@ -58,38 +80,37 @@ module BotMetrics
|
|
58
80
|
end
|
59
81
|
|
60
82
|
private
|
83
|
+
attr_accessor :api_key, :bot_id, :api_host
|
61
84
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
attr.nil? || attr == ''
|
66
|
-
end
|
85
|
+
def blank?(attr)
|
86
|
+
attr.nil? || attr == ''
|
87
|
+
end
|
67
88
|
|
68
|
-
|
69
|
-
|
70
|
-
|
89
|
+
def api_url
|
90
|
+
"#{api_host}/bots/#{bot_id}"
|
91
|
+
end
|
71
92
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
93
|
+
def options(extra_params)
|
94
|
+
{
|
95
|
+
headers: { "Authorization" => api_key },
|
96
|
+
omit_default_port: true,
|
97
|
+
idempotent: true,
|
98
|
+
retry_limit: 6,
|
99
|
+
read_timeout: 360,
|
100
|
+
connect_timeout: 360
|
101
|
+
}.merge(extra_params)
|
102
|
+
end
|
82
103
|
|
83
|
-
|
84
|
-
|
85
|
-
|
104
|
+
def message_attachments(attachments)
|
105
|
+
if attachments.nil?
|
106
|
+
nil
|
107
|
+
else
|
108
|
+
if attachments.is_a? String
|
109
|
+
attachments
|
86
110
|
else
|
87
|
-
|
88
|
-
attachments
|
89
|
-
else
|
90
|
-
attachments.to_json
|
91
|
-
end
|
111
|
+
attachments.to_json
|
92
112
|
end
|
93
113
|
end
|
114
|
+
end
|
94
115
|
end
|
95
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: botmetrics-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arunthampi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|