presbeus 0.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/presbeus +85 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a94dc414150874dfacffd96c1a8a55897d300614
4
+ data.tar.gz: 6d2d918b3b65ec8610c7775951fd93a65d33d8a2
5
+ SHA512:
6
+ metadata.gz: ec92135c054c9e93424bfceea5363605098745186262b1b8679c2472d901a2c9cb1e4a495b7a9338a4c4f995d8fd1a84971665db4e8cdcb46ff49120dfcfa861
7
+ data.tar.gz: b2ecd9352794a2d0b68ccf4a621d628de889d181db11617675c26dac8a5e1251912766604f594f13270892149535c3e0708034345f5372d2336f89fcc1ffb047
data/bin/presbeus ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rest-client'
3
+ require 'json'
4
+ require 'yaml'
5
+ require 'awesome_print'
6
+ require 'time_ago_in_words'
7
+
8
+ class Presbeus
9
+
10
+ def initialize
11
+ configuration_path = "#{ENV['HOME']}/.config/presbeus.yml"
12
+ configuration = YAML.load_file configuration_path
13
+ token = `#{configuration['password_command']}`
14
+ @headers = {"Access-Token" => token}
15
+ end
16
+
17
+ def get_v2 what
18
+ response = RestClient.get(
19
+ 'https://api.pushbullet.com/v2/' + what, @headers)
20
+ JSON.parse response.body
21
+ end
22
+
23
+ def devices
24
+ Hash[get_v2("devices")["devices"].select do |device|
25
+ device["icon"] == "phone"
26
+ end.map do |device|
27
+ [device["iden"], device["model"]]
28
+ end]
29
+ end
30
+
31
+ def threads iden
32
+ Hash[get_v2("permanents/#{iden}_threads")["threads"].reverse.map do |thread|
33
+ [thread["id"], thread["recipients"].map { |r| r["name"] }]
34
+ end]
35
+ end
36
+
37
+ def thread device, id
38
+ get_v2("permanents/#{device}_thread_#{id}")["thread"]
39
+ end
40
+
41
+ def user_iden
42
+ get_v2("users/me")["iden"]
43
+ end
44
+
45
+ def send_sms device, conversation_iden, message
46
+ RestClient.post(
47
+ 'https://api.pushbullet.com/v2/ephemerals',
48
+ {
49
+ push: {
50
+ conversation_iden: conversation_iden,
51
+ message: message,
52
+ package_name: "com.pushbullet.android",
53
+ source_user_iden: user_iden,
54
+ target_device_iden: device,
55
+ type: "messaging_extension_reply"
56
+ },
57
+ type: "push"
58
+ }.to_json,
59
+ @headers)
60
+ end
61
+
62
+ def run command
63
+ case command[0]
64
+ when "devices"
65
+ devices.each do |iden, name|
66
+ puts "#{iden} #{name}"
67
+ end
68
+ when "threads"
69
+ threads(command[1]).each do |id, recipients|
70
+ puts "#{id} #{recipients.join(",")}"
71
+ end
72
+ when "thread"
73
+ thread(command[1], command[2]).reverse.each do |message|
74
+ puts message["direction"] == "incoming" ? ">" : "<"
75
+ puts " #{message["body"]}"
76
+ puts " #{Time.at(message["timestamp"]).ago_in_words}"
77
+ end
78
+ when "sms"
79
+ send_sms command[1], command[2], command[3..-1].join(" ")
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ Presbeus.new.run ARGV
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: presbeus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Olivier Abdesselam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows to view/send pushbullet SMS
14
+ email:
15
+ executables:
16
+ - presbeus
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/presbeus
21
+ homepage: http://rubygems.org/gems/presbeus
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.11
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: command line SMS client for pushbullet
45
+ test_files: []