pushbullet_client 0.0.1 → 0.0.6

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: 562aa25969940582d115c9518b2da602d44b24854ead9a50c34eb5ec66a41cc8
4
- data.tar.gz: 539dafb070d592bd34333eabdf26b28a46182f8c67d32bb2a408592054b6fbc4
3
+ metadata.gz: 41e090f3defb5e7fdab2d0d09ac0f9e4724acd0c4de1bac80cb211921a201081
4
+ data.tar.gz: '0429f947e802b79d68bae4567f2f3e85d7c1b3a8672864ec0575b0b5d1e5ab56'
5
5
  SHA512:
6
- metadata.gz: 9818f7d0cb27f67319e8185a676b427f0c9a75aeacc28651a0863140a87c30684347fcbe5f0b4b3fabde6c163c87d8171f8a5e9514806eda89e30f4fafadd9fe
7
- data.tar.gz: e14eba20f5cd19bb93895a486f6a6c216e7701bf08ae12ea4a74a2cbd4a70b9f5ccf6f2b179c3ac759fa23da3ebfa7b3cbd42df60580026fc784c6604ebe1a42
6
+ metadata.gz: b0fc33fb5b681f4522a36d730607c44c42876209f1321c068dffc43c0dc2b182ad0e928d240e66aef41e25acf3fe8e476c2b6c9f772a8ef5baee5faf6b46d0a1
7
+ data.tar.gz: e4106fd2235666a8d43e73fbe60700154300791b1e84af3d782c45dc10179eda2d1486068dbdd550ca475b2eaf6d7e8b0991a30b1879d7b0554e125c0a769ee4
data/README.md CHANGED
@@ -23,11 +23,17 @@ Or install it yourself as:
23
23
 
24
24
  ```ruby
25
25
  require 'pushbullet_client'
26
- client = PushBullet::Client.new(key: 'your key', secret: 'your secret')
26
+ client = PushBullet::Client.new(access_token: 'your access_token')
27
27
  ```
28
28
 
29
29
  ### Endpoints
30
- -
30
+ - Chats
31
+ - Devices
32
+ - Permanents
33
+ - Pushes
34
+ - Subscriptions
35
+ - Texts
36
+ - Users
31
37
 
32
38
  ### Constants
33
39
  Constants
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ gem build pushbullet_client.gemspec
3
+ gem push pushbullet_client
@@ -5,9 +5,16 @@ require 'pushbullet/version'
5
5
  require 'pushbullet/constants'
6
6
 
7
7
  # Endpoints
8
+ require 'pushbullet/chats'
9
+ require 'pushbullet/devices'
10
+ require 'pushbullet/permanents'
11
+ require 'pushbullet/pushes'
12
+ require 'pushbullet/subscriptions'
13
+ require 'pushbullet/texts'
14
+ require 'pushbullet/users'
8
15
 
9
16
  require 'pushbullet/client'
10
17
 
11
- module Luno
18
+ module Pushbullet
12
19
  class Error < StandardError; end
13
20
  end
@@ -0,0 +1,9 @@
1
+ module Pushbullet
2
+ module Chats
3
+ def chats(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'chats'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+ end
9
+ end
@@ -3,60 +3,31 @@ module Pushbullet
3
3
  include ::Pushbullet::Constants
4
4
 
5
5
  # Endpoints
6
-
7
- # TODO: Cleanup modules
6
+ include ::Pushbullet::Chats
7
+ include ::Pushbullet::Devices
8
+ include ::Pushbullet::Permanents
9
+ include ::Pushbullet::Pushes
10
+ include ::Pushbullet::Subscriptions
11
+ include ::Pushbullet::Texts
12
+ include ::Pushbullet::Users
13
+
14
+ # TODO: Add uploads
15
+ # TODO: Add ephemerals
16
+ # TODO: Websockets
17
+ # TODO: Universal copy/paste
18
+ # TODO: Encryption
8
19
  # TODO: Pagination
9
20
  # TODO: Limits
10
21
  # TODO: Date parsing
11
22
  # TODO: Create api client creation library
12
23
 
13
- def me
14
- path = 'users/me'
15
- authorise_and_send(http_method: :get, path: path)
16
- end
17
-
18
- def devices
19
- path = 'devices'
20
- authorise_and_send(http_method: :get, path: path)
21
- end
22
-
23
- def pushes
24
- path = 'pushes'
25
- authorise_and_send(http_method: :get, path: path)
26
- end
27
-
28
- def chats
29
- path = 'chats'
30
- authorise_and_send(http_method: :get, path: path)
31
- end
32
-
33
- def subscriptions
34
- path = 'subscriptions'
35
- authorise_and_send(http_method: :get, path: path)
36
- end
37
-
38
- def texts
39
- path = 'texts'
40
- authorise_and_send(http_method: :get, path: path)
41
- end
42
-
43
- # See: https://stackoverflow.com/questions/38027963/pushbullet-api-thread-id-to-conversation-iden-for-sms
44
- def permanents(device_identity:)
45
- path = "permanents/#{device_identity}_threads"
46
- authorise_and_send(http_method: :get, path: path)
47
- end
48
-
49
- def permanent_conversation(device_identity:, thread_id:)
50
- path = "permanents/#{device_identity}_thread_#{thread_id}"
51
- authorise_and_send(http_method: :get, path: path)
52
- end
53
-
54
24
  attr_reader :key, :secret, :base_path, :port
55
25
 
56
- def initialize(access_token:, base_path: 'https://api.pushbullet.com/v2', port: 80)
26
+ def initialize(access_token:, base_path: API_V2_BASE_PATH, port: 80, limit: 500)
57
27
  @access_token = access_token
58
28
  @base_path = base_path
59
29
  @port = port
30
+ @limit = limit
60
31
  end
61
32
 
62
33
  def self.compatible_api_version
@@ -73,6 +44,12 @@ module Pushbullet
73
44
  def authorise_and_send(http_method:, path:, payload: {}, params: {})
74
45
  start_time = micro_second_time_now
75
46
 
47
+ if params.nil? || params.empty?
48
+ params = {}
49
+ end
50
+
51
+ params['limit'] = @limit
52
+
76
53
  response = HTTParty.send(
77
54
  http_method.to_sym,
78
55
  construct_base_path(path, params),
@@ -103,7 +80,8 @@ module Pushbullet
103
80
  {
104
81
  'start_time' => start_time,
105
82
  'end_time' => end_time,
106
- 'total_time' => total_time
83
+ 'total_time' => total_time,
84
+ 'cursor' => response.dig('cursor')
107
85
  }
108
86
  end
109
87
 
@@ -134,7 +112,7 @@ module Pushbullet
134
112
  def construct_base_path(path, params)
135
113
  constructed_path = "#{base_path}/#{path}"
136
114
 
137
- if params != {}
115
+ if params == {}
138
116
  constructed_path
139
117
  else
140
118
  "#{constructed_path}?#{process_params(params)}"
@@ -144,5 +122,11 @@ module Pushbullet
144
122
  def process_params(params)
145
123
  params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
146
124
  end
125
+
126
+ def process_cursor(cursor, params: {})
127
+ unless cursor.nil? || cursor.empty?
128
+ params['cursor'] = cursor
129
+ end
130
+ end
147
131
  end
148
132
  end
@@ -1,4 +1,5 @@
1
1
  module Pushbullet
2
2
  module Constants
3
+ API_V2_BASE_PATH = 'https://api.pushbullet.com/v2'
3
4
  end
4
5
  end
@@ -0,0 +1,9 @@
1
+ module Pushbullet
2
+ module Devices
3
+ def devices(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'devices'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module Pushbullet
2
+ module Permanents
3
+ # See: https://stackoverflow.com/questions/38027963/pushbullet-api-thread-id-to-conversation-iden-for-sms
4
+ def permanents(device_identity:, params: {}, cursor: nil)
5
+ params = process_cursor(cursor, params: params)
6
+
7
+ path = "permanents/#{device_identity}_threads"
8
+ authorise_and_send(http_method: :get, path: path, params: params)
9
+ end
10
+
11
+ def permanent_conversation(device_identity:, thread_id:, params: {}, cursor: nil)
12
+ params = process_cursor(cursor, params: params)
13
+
14
+ path = "permanents/#{device_identity}_thread_#{thread_id}"
15
+ authorise_and_send(http_method: :get, path: path, params: params)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ module Pushbullet
2
+ module Pushes
3
+ def pushes(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'pushes'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+
9
+ def self_pushes(params: {}, cursor: nil)
10
+ params = process_cursor(cursor, params: params.merge({ self: true }))
11
+
12
+ path = 'pushes'
13
+ authorise_and_send(http_method: :get, path: path, params: params)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Pushbullet
2
+ module Subscriptions
3
+ def subscriptions(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'subscriptions'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Pushbullet
2
+ module Texts
3
+ def texts(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'texts'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Pushbullet
2
+ module Users
3
+ def me(params: {}, cursor: nil)
4
+ params = process_cursor(cursor, params: params)
5
+ path = 'users/me'
6
+ authorise_and_send(http_method: :get, path: path, params: params)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Pushbullet
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pushbullet_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - trex22
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-17 00:00:00.000000000 Z
11
+ date: 2020-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_attr
@@ -194,10 +194,18 @@ files:
194
194
  - README.md
195
195
  - Rakefile
196
196
  - bin/console
197
+ - bin/make
197
198
  - bin/setup
198
199
  - lib/pushbullet.rb
200
+ - lib/pushbullet/chats.rb
199
201
  - lib/pushbullet/client.rb
200
202
  - lib/pushbullet/constants.rb
203
+ - lib/pushbullet/devices.rb
204
+ - lib/pushbullet/permanents.rb
205
+ - lib/pushbullet/pushes.rb
206
+ - lib/pushbullet/subscriptions.rb
207
+ - lib/pushbullet/texts.rb
208
+ - lib/pushbullet/users.rb
201
209
  - lib/pushbullet/version.rb
202
210
  - pushbullet_client.gemspec
203
211
  homepage: https://github.com/TRex22/pushbullet_client