presbeus 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/presbeus +50 -9
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6e9f092c95ac7a42ab4a3d734fe240169b0995
|
4
|
+
data.tar.gz: 77c0037c697c764b6e4da23cc2eccfdb14e69dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 006affe9abb7bd67066afa54acde980344f216a2f6bf87f52c695a9ba1bfbef80c86376120472701592ec51a7a1fb1b4417951a0c62532e3bdbbe30b07575089
|
7
|
+
data.tar.gz: 829fd5d5c602b3fb7a739a8bfdfa60ea30ba4d01a6e3cd9739b54f8a08315e5a82d93b6b11137b8d084df4b2b7a937572fd712f395fa01e5e94d41fdcb0c0d03
|
data/bin/presbeus
CHANGED
@@ -6,7 +6,10 @@ require 'time_ago_in_words'
|
|
6
6
|
require 'terminal-table'
|
7
7
|
require 'highline'
|
8
8
|
require 'colorize'
|
9
|
-
require
|
9
|
+
require 'readline'
|
10
|
+
#require 'websocket-eventmachine-client'
|
11
|
+
require 'kontena-websocket-client'
|
12
|
+
require 'open-uri'
|
10
13
|
|
11
14
|
class Time
|
12
15
|
|
@@ -18,6 +21,7 @@ class Presbeus
|
|
18
21
|
|
19
22
|
def initialize_arguments
|
20
23
|
argument(:help, [], "show this help") { help }
|
24
|
+
argument(:realtime, [], "handle realtime event stream") { realtime }
|
21
25
|
argument(:shell, [], "run in an interactive shell") { shell }
|
22
26
|
argument(:devices, [], "list devices") { puts table devices }
|
23
27
|
argument(:pushes, [], "list pushes") { puts table pushes_with_color }
|
@@ -42,18 +46,52 @@ class Presbeus
|
|
42
46
|
initialize_arguments
|
43
47
|
configuration_path = "#{ENV['HOME']}/.config/presbeus.yml"
|
44
48
|
configuration = YAML.load_file configuration_path
|
45
|
-
token = `#{configuration['password_command']}
|
46
|
-
@
|
49
|
+
@token = `#{configuration['password_command']}`.chomp
|
50
|
+
@notify_command = configuration['notify_command']
|
51
|
+
@headers = {"Access-Token" => @token, "Content-Type" => "json"}
|
52
|
+
@api_prefix = 'https://api.pushbullet.com/v2/'
|
53
|
+
end
|
54
|
+
|
55
|
+
def realtime_no_reconnect
|
56
|
+
uri = "wss://stream.pushbullet.com/websocket/#{@token}"
|
57
|
+
Kontena::Websocket::Client.connect(uri, ping_timeout: 60) do |client|
|
58
|
+
client.on_pong do |time, delay|
|
59
|
+
p time, delay
|
60
|
+
end
|
61
|
+
client.read do |message|
|
62
|
+
json = JSON.parse(message)
|
63
|
+
type = json["type"]
|
64
|
+
if type != "nop"
|
65
|
+
if type == "tickle"
|
66
|
+
puts(table(pushes_with_color(Time.now.to_i) do |push|
|
67
|
+
`#{@notify_command} "#{push[1]}"` if @notify_command
|
68
|
+
end))
|
69
|
+
end
|
70
|
+
else
|
71
|
+
client.send message # pong
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def realtime
|
78
|
+
while true
|
79
|
+
begin
|
80
|
+
realtime_no_reconnect
|
81
|
+
rescue Kontena::Websocket::TimeoutError => e
|
82
|
+
puts "timeout #{e}"
|
83
|
+
end
|
84
|
+
end
|
47
85
|
end
|
48
86
|
|
49
87
|
def post_v2 what, payload
|
50
88
|
RestClient.post(
|
51
|
-
|
89
|
+
@api_prefix + what, payload.to_json, @headers)
|
52
90
|
end
|
53
91
|
|
54
92
|
def get_v2 what
|
55
93
|
response = RestClient.get(
|
56
|
-
|
94
|
+
@api_prefix + what, @headers)
|
57
95
|
JSON.parse response.body
|
58
96
|
end
|
59
97
|
|
@@ -74,8 +112,10 @@ class Presbeus
|
|
74
112
|
get_v2("permanents/#{device}_thread_#{id}")["thread"]
|
75
113
|
end
|
76
114
|
|
77
|
-
def pushes
|
78
|
-
|
115
|
+
def pushes modified_after = nil
|
116
|
+
path = "pushes"
|
117
|
+
path += "?modified_after=#{modified_after}" if modified_after
|
118
|
+
get_v2(path)["pushes"].map do |push|
|
79
119
|
[Time.at(push["created"].to_i).ago_in_words, push["body"]]
|
80
120
|
end
|
81
121
|
end
|
@@ -151,8 +191,9 @@ class Presbeus
|
|
151
191
|
res
|
152
192
|
end
|
153
193
|
|
154
|
-
def pushes_with_color
|
155
|
-
pushes.reverse.map do |push|
|
194
|
+
def pushes_with_color modified_after = nil
|
195
|
+
pushes(modified_after).reverse.map do |push|
|
196
|
+
yield(push) if block_given?
|
156
197
|
["\n" + push[0] + "\n" + with_color(wrap(push[1], width_2), width_2, :green)]
|
157
198
|
end
|
158
199
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: presbeus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Abdesselam
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: kontena-websocket-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
83
97
|
description: Allows to view/send pushbullet SMS
|
84
98
|
email:
|
85
99
|
executables:
|