botmetrics-rb 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd36442c6ae3e2378923f8351cc251e5d221d943
4
- data.tar.gz: efe7679645fd4b0f87a2673b870be5e4568145e0
3
+ metadata.gz: 029d34f70a53015b43c0019a882e14077c7c5562
4
+ data.tar.gz: 003dcbb39b9d376d8b3db4866bcb8b895dce1630
5
5
  SHA512:
6
- metadata.gz: c8793f169b7f133304f50b92120927f227ca5862872b9ffc6469cf0d7322f995d58ddddafe74584b1bab140616707d5d6041a3d64c790fcaf18df98be52b4e45
7
- data.tar.gz: e0ed0a2527b5caec23731201365b41df37820e73e550596f1ecb3640014f9af0fbc62adbcab5bc2bcc776f9ba9cee406127296bbcdff5ff5b703755d7a20fc17
6
+ metadata.gz: fe363b2b7acc6edffa5b8e1fb0ded536a2cb7fc140a1d1937b40b3d340d58a36c39e74a56d7fcfc4182c7c44daf2f6bb1338b697cf561f57b04f1546c45eaf9f
7
+ data.tar.gz: fd30b7082a781d677f89a28560ae10a25f77f6d746badf5abdfbb6e69e47b327f976584ec51811e7a677b3ca284fe657a266f9f3e0e539d58274bab8559d6f63
@@ -1,3 +1,3 @@
1
1
  module BotMetrics
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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
- attr_accessor :api_key, :bot_id, :api_host
63
-
64
- def blank?(attr)
65
- attr.nil? || attr == ''
66
- end
85
+ def blank?(attr)
86
+ attr.nil? || attr == ''
87
+ end
67
88
 
68
- def api_url
69
- "#{api_host}/bots/#{bot_id}"
70
- end
89
+ def api_url
90
+ "#{api_host}/bots/#{bot_id}"
91
+ end
71
92
 
72
- def options(extra_params)
73
- {
74
- headers: { "Authorization" => api_key },
75
- omit_default_port: true,
76
- idempotent: true,
77
- retry_limit: 6,
78
- read_timeout: 360,
79
- connect_timeout: 360
80
- }.merge(extra_params)
81
- end
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
- def message_attachments(attachments)
84
- if attachments.nil?
85
- nil
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
- if attachments.is_a? String
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.6
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-06-03 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json