├── .gitignore ├── matlab-pushbullet-ios.png ├── .gitattributes ├── LICENSE ├── README.md └── Pushbullet.m /.gitignore: -------------------------------------------------------------------------------- 1 | *.asv 2 | tests/ -------------------------------------------------------------------------------- /matlab-pushbullet-ios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jensb89/Matlab-Pushbullet/HEAD/matlab-pushbullet-ios.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Jens Brauer 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Matlab-Pushbullet 2 | ============= 3 | 4 | This Matlab class can be used to send push notifications via pushbullet to your smartphone right from within Matlab. 5 | This could for example inform you that your measurement or simulation is done. 6 | 7 | What you need is a Pushbullet Account and the corresponding App for Android or iOS. 8 | 9 | In order to use the API you need an API key that can be obtained 10 | [here](https://www.pushbullet.com/account). 11 | 12 | ![Matlab Pushbullet Notification on iPhone](matlab-pushbullet-ios.png) 13 | 14 | Important: The Matlab class now uses the new webwrite and webread functions from Matlab. The webwrite was introduced in Matlab R2015a. If you are using an older matlab version, use the older release of Matlab-Pushbullet [here](https://github.com/jensb89/Matlab-Pushbullet/releases/). 15 | 16 | #Usage 17 | 18 | 19 | ##Initialize object 20 | 21 | 22 | ```matlab 23 | p = Pushbullet(apikey) 24 | ``` 25 | 26 | 27 | ##Push 28 | 29 | 30 | ##Pushing a text note 31 | 32 | ```matlab 33 | p.pushNote(device_iden,'Matlab Pushbullet Test','This is the message') 34 | ``` 35 | 36 | ##Pushing a link 37 | 38 | ```matlab 39 | p.pushLink(device_iden, 'Test Link', 'Message to the link', 'http://www.github.com') 40 | ``` 41 | 42 | ##Pushing a file 43 | 44 | ```matlab 45 | p.pushFile(device_iden, file_name, file_type, file_url) 46 | ``` 47 | to push a file which has already been uploaded somewhere. 48 | 49 | ##Pushing to specific devices 50 | 51 | `device_iden` can either be `[]` to send a push notification to all the connected devices or the specific device_iden, which can be displayed by: 52 | 53 | ```matlab 54 | p.load_devices() 55 | ``` 56 | 57 | Furthermore `device_iden` can be an e-mail adress. 58 | 59 | 60 | License 61 | ------- 62 | 63 | MIT license. See LICENSE for full text. -------------------------------------------------------------------------------- /Pushbullet.m: -------------------------------------------------------------------------------- 1 | classdef Pushbullet < handle 2 | %Pushbullet Connect to pushbullet.com and send notes/links/files to the 3 | %connected smartphone as a push notification 4 | % 5 | % Usage: 6 | % p = Pushbullet('abcdefghijk123456') (apikey) 7 | % p.pushNote([],'Matlab Pushbullet Test','This is the message') -- 8 | % sends a push note to all connected devices 9 | % p.pushNote('abhgzt12123','Matlab Pushbullet Test','This is the 10 | % message') --send only to the specific device with the device_iden 11 | % p.load_devices() --show all devices + device_idens 12 | % p.pushFile(device_iden, file_name, file_type, file_url) to push a 13 | % file which has already been uploaded 14 | % 15 | % Copyright 2016, Jens Brauer, https://github.com/jensb89 16 | 17 | properties 18 | HOST = 'https://api.pushbullet.com/v2' 19 | DEVICES_URL = '/devices' 20 | CONTACTS_URL = '/contacts' 21 | ME_URL = '/users/me' 22 | PUSH_URL = '/pushes' 23 | UPLOAD_REQUEST_URL = '/upload-request' 24 | SUBSCRIPTIONS_URL = '/subscriptions' 25 | ApiKey 26 | Devices 27 | Subscriptions 28 | end 29 | 30 | methods 31 | 32 | function self = Pushbullet(apikey) 33 | self.ApiKey = apikey; 34 | if verLessThan('MATLAB','8.5') 35 | warning(['You are using a Matlab version prior to 2015a',... 36 | 'Matlab-Pushbullet might not work with this version.',... 37 | 'Update Matlab or use an older version of Matlab-Pushbullet',... 38 | 'from here: https://github.com/jensb89/Matlab-Pushbullet/releases/']); 39 | end 40 | end 41 | 42 | function load_devices(self) 43 | % Get a list of devices 44 | options = weboptions('KeyName','Access-Token','KeyValue',self.ApiKey); 45 | output = webread([self.HOST,self.DEVICES_URL],options); 46 | self.Devices = output.devices; 47 | for i=1:length(self.Devices) 48 | if self.Devices{i}.active && isfield(self.Devices{i},'nickname') 49 | sprintf('%s : %s', self.Devices{i}.nickname, self.Devices{i}.iden) 50 | end 51 | end 52 | end 53 | 54 | function load_subscriptions(self) 55 | % Get a list of devices 56 | options = weboptions('KeyName','Access-Token','KeyValue',self.ApiKey); 57 | output = webread([self.HOST,self.SUBSCRIPTIONS_URL],options); 58 | self.Subscriptions = output.subscriptions; 59 | for i=1:length(self.Subscriptions) 60 | if self.Subscriptions{i}.active && isfield(self.Subscriptions{i}.channel,'name') 61 | sprintf('%s : %s : %s', self.Subscriptions{i}.channel.name, self.Subscriptions{i}.channel.iden, self.Subscriptions{i}.channel.tag) 62 | end 63 | end 64 | end 65 | 66 | 67 | function output = pushNote(self, device_iden, title, message) 68 | % Push a note 69 | % https://docs.pushbullet.com/v2/pushes 70 | % Arguments: 71 | % device_iden -- iden of device to push to 72 | % title -- a title for the note 73 | % body -- the body of the note 74 | 75 | data = struct('body',message,... 76 | 'device_iden',device_iden,... 77 | 'title',title,... 78 | 'type','note'); 79 | 80 | if isempty(device_iden) 81 | data = rmfield(data,'device_iden'); 82 | end 83 | 84 | output = push(self, data); 85 | end 86 | 87 | function output = pushNote_to_Channel(self, channel_tag, title, message) 88 | % Push a note 89 | % https://docs.pushbullet.com/v2/pushes 90 | % Arguments: 91 | % channel_tag -- tag of channel to push to 92 | % title -- a title for the note 93 | % body -- the body of the note 94 | 95 | data = struct('body',message,... 96 | 'channel_tag',channel_tag,... 97 | 'title',title,... 98 | 'type','note'); 99 | 100 | if isempty(channel_tag) 101 | data = rmfield(data,'channel_tag'); 102 | end 103 | 104 | output = push(self, data); 105 | end 106 | 107 | 108 | function output = pushFile(self, device_iden, file_name, file_type, file_url) 109 | % Push a picture 110 | % https://docs.pushbullet.com/v2/pushes 111 | % Arguments: 112 | % device_iden -- iden of device to push to 113 | % file_name -- the name for the file 114 | % file_type -- The MIME type of the file (for example 115 | % 'image/png') 116 | % file_url -- the url of the file 117 | 118 | data = struct('type','file',... 119 | 'device_iden',device_iden,... 120 | 'file_name',file_name,... 121 | 'file_type',file_type,... 122 | 'file_url',file_url); 123 | 124 | if isempty(device_iden) 125 | data = rmfield(data,'device_iden'); %delete device_iden in data -> push to all connected devices 126 | end 127 | 128 | output = push(self, data); 129 | end 130 | 131 | function output = pushLink(self, device_iden, title, message, url) 132 | % Push a link 133 | % https://docs.pushbullet.com/v2/pushes 134 | % Arguments: 135 | % device_iden -- iden of device to push to 136 | % title -- a title for the note 137 | % body -- the body of the note 138 | 139 | data = struct('type', 'note',... 140 | 'device_iden',device_iden,... 141 | 'title', title,... 142 | 'body', message,... 143 | 'url', url); 144 | 145 | if isempty(device_iden) 146 | data = rmfield(data,'device_iden'); %delete device_iden in data -> push to all connected devices 147 | end 148 | 149 | output = push(self, data); 150 | end 151 | 152 | function output = push(self, data) 153 | % Perform the POST Request 154 | options = weboptions('KeyName','Access-Token',... 155 | 'KeyValue',self.ApiKey,... 156 | 'MediaType','application/json'); 157 | output = webwrite([self.HOST,self.PUSH_URL],data,options); 158 | end 159 | 160 | % HELPER FUNCTIONS 161 | function device_iden = get_device_iden_from_nickname(self, nickname) 162 | if isempty(self.Devices) 163 | load_devices(self) 164 | end 165 | if ~isempty(self.Devices) 166 | for i=1:length(self.Devices) 167 | if strcmp(self.Devices{i}.nickname, nickname) 168 | device_iden = self.Devices{i}.iden; 169 | end 170 | end 171 | end 172 | end 173 | 174 | end 175 | 176 | end 177 | 178 | --------------------------------------------------------------------------------