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

.address(name, address, recipient = nil) ⇒ JSON

push address

Parameters:

  • name (String)

    name of address

  • address (String)

    address itself, or query for the address

  • 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
# File 'lib/v2/push.rb', line 80

def self.address(name, address, recipient = nil)
  params = {
    type: :address,
    name: name,
    address: address,
  }
  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

.checklist(title, items, recipient = nil) ⇒ JSON

push checklist

Parameters:

  • title (String)

    title of note

  • items (Array<String>)

    array of checklist items

  • 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)



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/v2/push.rb', line 105

def self.checklist(title, items, recipient = nil)
  params = {
    type: :list,
    title: title,
    items: items,
  }
  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

.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)



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/v2/push.rb', line 130

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