Class: Pushybullet::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pushybullet/client.rb

Instance Method Summary collapse

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

#devicesObject



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


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