Class: Pushbullet::V2::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/v2/push.rb

Constant Summary collapse

API_URL =
'https://api.pushbullet.com/v2/pushes'

Class Method Summary collapse

Class Method Details

.file(filepath, text, recipient = nil) ⇒ JSON

push file

Parameters:

  • filepath (String)

    absolute path of file

  • text (String)

    body text

  • recipient (Hash) (defaults to: nil)

    key-value of either one of: ‘email’, ‘device_iden’, ‘channel_tag’, or ‘client_iden’ (can be nil)

Returns:

  • (JSON)

    result as json (nil if error)



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/v2/push.rb', line 80

def self.file(filepath, text, recipient = nil)
  to_upload = _request_upload_file(filepath)
  if _upload_file(filepath, to_upload['upload_url'], to_upload['data'])
    params = {
      type: :file,
      file_name: to_upload['file_name'],
      file_type: to_upload['file_type'],
      file_url: to_upload['file_url'],
      body: text,
    }
    params.merge!(recipient) if recipient

    result = Pushbullet::V2::request(API_URL, params)

    case result
    when Net::HTTPOK
      return JSON.parse(result.body)
    else
      puts result.body if Pushbullet.is_verbose
      return nil
    end
  end

  false
end

push link

Parameters:

  • title (String)

    title of note

  • text (String)

    body text of note

  • link (String)

    url of the link

  • recipient (Hash) (defaults to: nil)

    key-value of either one of: ‘email’, ‘device_iden’, ‘channel_tag’, or ‘client_iden’ (can be nil)

Returns:

  • (JSON)

    result as json (nil if error)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/v2/push.rb', line 54

def self.link(title, text, link, recipient = nil)
  params = {
    type: :link,
    title: title,
    body: text,
    url: link,
  }
  params.merge!(recipient) if recipient

  result = Pushbullet::V2::request(API_URL, params)

  case result
  when Net::HTTPOK
    return JSON.parse(result.body)
  else
    puts result.body if Pushbullet.is_verbose
    return nil
  end
end

.note(title, text, recipient = nil) ⇒ JSON

push note

Parameters:

  • title (String)

    title of note

  • text (String)

    body text of note

  • recipient (Hash) (defaults to: nil)

    key-value of either one of: ‘email’, ‘device_iden’, ‘channel_tag’, or ‘client_iden’ (can be nil)

Returns:

  • (JSON)

    result as json (nil if error)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/v2/push.rb', line 28

def self.note(title, text, recipient = nil)
  params = {
    type: :note,
    title: title,
    body: text,
  }
  params.merge!(recipient) if recipient

  result = Pushbullet::V2::request(API_URL, params)

  case result
  when Net::HTTPOK
    return JSON.parse(result.body)
  else
    puts result.body if Pushbullet.is_verbose
    return nil
  end
end