Class: Pushybullet::Client
- Inherits:
-
Object
- Object
- Pushybullet::Client
- Defined in:
- lib/pushybullet/client.rb
Instance Method Summary collapse
- #create_push(push_request) ⇒ Object
- #devices ⇒ Object
-
#initialize(access_token, request_timeout = 3) ⇒ Client
constructor
A new instance of Client.
- #push_link(title, body, url, target) ⇒ Object
- #push_note(title, body, target) ⇒ Object
Constructor Details
#initialize(access_token, request_timeout = 3) ⇒ Client
Returns a new instance of Client.
10 11 12 13 |
# File 'lib/pushybullet/client.rb', line 10 def initialize(access_token, request_timeout = 3) @access_token = access_token @request_timeout = request_timeout end |
Instance Method Details
#create_push(push_request) ⇒ Object
26 27 28 29 30 |
# File 'lib/pushybullet/client.rb', line 26 def create_push(push_request) payload = JSON.dump(push_request.to_hash) resp = conn.post('v2/pushes', payload, 'Content-Type' => 'application/json') Pushybullet::Types::Push.from_hash(resp.body) end |
#devices ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pushybullet/client.rb', line 15 def devices resp = conn.get('v2/devices') devs = [] puts resp.body resp.body['devices'].each do |data| devs << Pushybullet::Types::Device.from_hash(data) end devs end |
#push_link(title, body, url, target) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pushybullet/client.rb', line 32 def push_link(title, body, url, target) push = Pushybullet::Types::PushRequest.from_hash({ type: :link, title: title, body: body, url: url }) push.target = target create_push(push) end |
#push_note(title, body, target) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/pushybullet/client.rb', line 43 def push_note(title, body, target) push = Pushybullet::Types::PushRequest.from_hash({ type: :note, title: title, body: body }) push.target = target create_push(push) end |