watchdoge 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54505b8b8c7f8b7066dd0d1ed927b071d916f624c51e853c3de530ed460c4d61
4
- data.tar.gz: 7555854b46fdd49bf5701dc82882eed3ec750db2295d7d11b606af9580485c68
3
+ metadata.gz: 4c995950dde2c446b458210461e4d03b32a78d065a025fbd2e42392c28a6a67a
4
+ data.tar.gz: 429647c25c17feab2e9d28bb70033d9fec91e7889dec358fc077f36cd97da72e
5
5
  SHA512:
6
- metadata.gz: 657f5445558802f7de03333de9d483693be6f2c3366f4700e09c0d463bd8f16ccf49c3904d6828a485aebc4ca78aa9be75ea118e01e1225ee01fb49f0359d2bd
7
- data.tar.gz: f7ae31fac25c27f726bc8cf59a98f7648bd7a95fac6cc4f825be9b671f42411ae1f1f002bac99a2c604c4e7901f315909fe84170af1d81f3230e13d600c6e595
6
+ metadata.gz: 03b3eb8808e20dbaf82f96c19b2c25370a1145b2f2866c85e3d7357d331249d14be692f2a37d30a69dc00bb4ce42d64a0409a82cc869395372d9b178131e1d23
7
+ data.tar.gz: 4f0270dbc0c3f3f1c20bc39a55b1716d814ac0a3bb6b95cb874b817f7961c873edf82987c919841f3ef72f2484098ef75480e23d2aa7cbbc495e61f77392657f
@@ -22,6 +22,16 @@ module WatchDoge
22
22
  # slack: {
23
23
  # incoming_url: SLACK_WEBHOOK
24
24
  # }
25
+ # matter_most: {
26
+ # host: HOST,
27
+ # channel_id: CHANNEL_ID,
28
+ # auth_token: AUTH_TOKEN
29
+ # }
30
+ # matter_most: {
31
+ # host: 'HOST',
32
+ # channel_id: 'CHANNEL_ID',
33
+ # auth_token: 'AUTH_TOKEN'
34
+ # }
25
35
  }
26
36
  end
27
37
  end
@@ -0,0 +1,79 @@
1
+ require 'chunky_png'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'net/http/post/multipart'
5
+ require 'uri'
6
+
7
+ module WatchDoge
8
+ module Notification
9
+ class MatterMost
10
+ def initialize args
11
+ @host = args[:host]
12
+ @channel_id = args[:channel_id]
13
+ @auth_token = args[:auth_token]
14
+ end
15
+
16
+ def push message
17
+ case message
18
+ when String
19
+ _post _matter_most_meta(message)
20
+ when ChunkyPNG::Image
21
+ _post_file _matter_most_meta(message)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def _post meta
28
+ Net::HTTP.post _api_uri('/posts'),
29
+ meta.to_json,
30
+ "Content-Type" => "application/json",
31
+ "Authorization" => "Bearer #{@auth_token}"
32
+ end
33
+
34
+ def _post_file meta
35
+ uri = _api_uri("/files")
36
+
37
+ req = Net::HTTP::Post::Multipart.new uri.path, meta
38
+ req.add_field("Authorization", "Bearer #{@auth_token}")
39
+
40
+ res = nil
41
+
42
+ Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == "https")) do |http|
43
+ res = http.request(req).body
44
+ end
45
+
46
+ file_id = JSON.parse(res)['file_infos'].first['id']
47
+
48
+ _post_file_to_channel file_id
49
+ end
50
+
51
+ def _post_file_to_channel file_id
52
+ _post({
53
+ channel_id: @channel_id,
54
+ message: 'file uploaded from WatchDoge',
55
+ file_ids: [file_id]
56
+ })
57
+ end
58
+
59
+ def _api_uri path
60
+ URI("#{@host}/api/v4#{path}")
61
+ end
62
+
63
+ def _matter_most_meta message
64
+ case message
65
+ when String
66
+ {
67
+ channel_id: @channel_id,
68
+ message: message
69
+ }
70
+ when ChunkyPNG::Image
71
+ {
72
+ channel_id: @channel_id,
73
+ files: UploadIO.new(StringIO.new(message.to_blob), "image/png", "image.png")
74
+ }
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -21,6 +21,8 @@ module WatchDoge
21
21
  case source_sym
22
22
  when :slack
23
23
  WatchDoge::Notification::Slack
24
+ when :matter_most
25
+ WatchDoge::Notification::MatterMost
24
26
  end
25
27
  end
26
28
  end
@@ -1,3 +1,3 @@
1
1
  module WatchDoge
2
- Version = '0.0.1'
2
+ Version = '0.0.3'
3
3
  end
Binary file
data/watchdoge.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'watchdoge'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.3'
4
4
  s.date = '2019-07-22'
5
5
  s.summary = "dogi"
6
6
  s.description = "A collection of web test tools"
@@ -16,4 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency "net_http_ssl_fix", "~> 0.0.10"
17
17
  s.add_dependency "webdrivers", "~> 4", "> 4.0.0"
18
18
  s.add_dependency "watir", "~> 6.16", "> 6.16.0"
19
+ s.add_dependency "multipart-post", "~> 2.1", "> 2.1.0"
19
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchdoge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shen Lee
@@ -84,6 +84,26 @@ dependencies:
84
84
  - - "~>"
85
85
  - !ruby/object:Gem::Version
86
86
  version: '6.16'
87
+ - !ruby/object:Gem::Dependency
88
+ name: multipart-post
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 2.1.0
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.0
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
106
+ version: '2.1'
87
107
  description: A collection of web test tools
88
108
  email: no-reply@gmail.com
89
109
  executables: []
@@ -97,9 +117,11 @@ files:
97
117
  - lib/watchdoge/image_diff.rb
98
118
  - lib/watchdoge/install.rb
99
119
  - lib/watchdoge/notification.rb
120
+ - lib/watchdoge/notification/matter_most.rb
100
121
  - lib/watchdoge/notification/slack.rb
101
122
  - lib/watchdoge/version.rb
102
123
  - lib/watchdoge/worker.rb
124
+ - watchdoge-0.0.2.gem
103
125
  - watchdoge.gemspec
104
126
  homepage:
105
127
  licenses: