washbullet 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rspec +1 -1
- data/.travis.yml +3 -0
- data/README.md +61 -24
- data/Rakefile +6 -1
- data/lib/washbullet.rb +5 -0
- data/lib/washbullet/api.rb +3 -1
- data/lib/washbullet/api/contacts.rb +13 -3
- data/lib/washbullet/api/devices.rb +9 -3
- data/lib/washbullet/api/me.rb +1 -1
- data/lib/washbullet/api/pushes.rb +14 -55
- data/lib/washbullet/api/subscriptions.rb +17 -0
- data/lib/washbullet/{basic_authentication.rb → authorization.rb} +1 -1
- data/lib/washbullet/channel.rb +29 -0
- data/lib/washbullet/client.rb +18 -18
- data/lib/washbullet/contact.rb +35 -0
- data/lib/washbullet/device.rb +27 -0
- data/lib/washbullet/entity.rb +27 -0
- data/lib/washbullet/http_exception.rb +19 -14
- data/lib/washbullet/push.rb +27 -0
- data/lib/washbullet/pushable.rb +59 -0
- data/lib/washbullet/pushable/file.rb +55 -0
- data/lib/washbullet/pushable/link.rb +13 -0
- data/lib/washbullet/pushable/note.rb +13 -0
- data/lib/washbullet/request.rb +1 -1
- data/lib/washbullet/user.rb +9 -0
- data/lib/washbullet/version.rb +1 -1
- data/spec/fixtures/green.png +0 -0
- data/spec/spec_helper.rb +48 -68
- data/spec/vcr/Washbullet_API_Contacts/_contacts/Get_own_active_contacts.yml +48 -0
- data/spec/vcr/Washbullet_API_Devices/_devices/Get_own_active_devices.yml +50 -0
- data/spec/vcr/Washbullet_API_Me/_me/Get_the_self_information.yml +50 -0
- data/spec/vcr/Washbullet_API_Subscriptions/_channel_info/when_channel_is_existing/Get_information_about_a_channel.yml +49 -0
- data/spec/vcr/Washbullet_API_Subscriptions/_channel_info/when_channel_is_not_existing/raise_error.yml +49 -0
- data/spec/vcr/Washbullet_API_Subscriptions/_subscriptions/Get_list_subscriptions.yml +50 -0
- data/spec/vcr/Washbullet_Pushable_File/_push/.yml +170 -0
- data/spec/vcr/Washbullet_Pushable_Link/_push/.yml +52 -0
- data/spec/vcr/Washbullet_Pushable_Note/_push/.yml +51 -0
- data/spec/washbullet/api/contacts_spec.rb +15 -0
- data/spec/washbullet/api/devices_spec.rb +14 -0
- data/spec/washbullet/api/me_spec.rb +11 -0
- data/spec/washbullet/api/subscriptions_spec.rb +31 -0
- data/spec/washbullet/pushable/file_spec.rb +23 -0
- data/spec/washbullet/pushable/link_spec.rb +24 -0
- data/spec/washbullet/pushable/note_spec.rb +20 -0
- data/washbullet.gemspec +5 -1
- metadata +107 -29
- data/spec/fixtures/contacts.json +0 -16
- data/spec/fixtures/devices.json +0 -19
- data/spec/fixtures/push.json +0 -18
- data/spec/fixtures/pushes.json +0 -24
- data/spec/fixtures/upload_request.json +0 -14
- data/spec/fixtures/users.json +0 -31
- data/spec/washbullet/client_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b00def53d0001c2857430d0125e2804e39c4cb
|
4
|
+
data.tar.gz: 18d2a8debae29e33f43d02e02b3668110cfe61f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e332376572793ddc8ed5f411f921d77c73bbfef5c40275d0ba653cdb266eee6cfaf26fe93bb7d7c5b08d43a951782f8f4a2929b9c011dc505d0c77450b270e5a
|
7
|
+
data.tar.gz: efc87efe004731cd662c6599652dc2e25bc798bd5106615b2fd55edb7cd19bc4b21b97d23b245ada80ccdf7d1db04eb40f57198767ed894f41e3dd7cdb3a269e
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--
|
2
|
+
--require spec_helper
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Washbullet
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/hrysd/washbullet.svg?branch=master)](https://travis-ci.org/hrysd/washbullet)
|
4
|
+
|
3
5
|
Ruby client of [Pushbullet](https://www.pushbullet.com/).
|
4
6
|
|
5
7
|
## Installation
|
@@ -10,51 +12,86 @@ $ gem install washbullet
|
|
10
12
|
|
11
13
|
## Usage
|
12
14
|
|
13
|
-
|
15
|
+
### Setup Client
|
14
16
|
|
15
17
|
```ruby
|
16
18
|
client = Washbullet::Client.new('YOUR_API_KEY')
|
17
19
|
```
|
18
20
|
|
19
|
-
|
21
|
+
### Push
|
20
22
|
|
21
23
|
You can send following list:
|
24
|
+
|
22
25
|
- note
|
23
26
|
- link
|
24
|
-
- address
|
25
|
-
- list
|
26
27
|
- file
|
27
28
|
|
28
29
|
```ruby
|
29
|
-
|
30
|
-
client
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
client.push_note(
|
31
|
+
receiver: :device, # :email, :channel, :client
|
32
|
+
identifier: '<IDENTIFIER>',
|
33
|
+
params: {
|
34
|
+
title: 'Title',
|
35
|
+
body: 'Contents'
|
36
|
+
}
|
37
|
+
)
|
38
|
+
```
|
37
39
|
|
38
|
-
|
39
|
-
client.push_address(device_iden, 'Name of address', 'Addrss of place')
|
40
|
+
### Devices
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
```ruby
|
43
|
+
# Get own active devices
|
44
|
+
client.devices
|
45
|
+
```
|
43
46
|
|
44
|
-
|
45
|
-
client.push_file(device_iden, 'File name', 'path/to/file', 'An optional message')
|
47
|
+
### Contacts
|
46
48
|
|
47
|
-
|
49
|
+
```ruby
|
50
|
+
# Get friends list
|
48
51
|
client.contacts
|
52
|
+
```
|
49
53
|
|
50
|
-
|
54
|
+
### Get self info
|
55
|
+
|
56
|
+
```
|
51
57
|
client.me
|
52
58
|
```
|
53
59
|
|
54
|
-
##
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
## Supported API
|
61
|
+
|
62
|
+
detail: https://docs.pushbullet.com/
|
63
|
+
|
64
|
+
**Pushes**
|
65
|
+
- [X] Push to device
|
66
|
+
- [ ] Request push history
|
67
|
+
- [ ] Update a push
|
68
|
+
- [ ] Deleting a push
|
69
|
+
- [ ] Deleting all pushes
|
70
|
+
|
71
|
+
**Devices**
|
72
|
+
- [X] Get the devices that can be pushed to
|
73
|
+
- [ ] Create a new device
|
74
|
+
- [ ] Update an existing device
|
75
|
+
- [ ] Delete a device
|
76
|
+
|
77
|
+
**Contacts**
|
78
|
+
- [X] Get your contacts
|
79
|
+
- [ ] Create a contact
|
80
|
+
- [ ] Update a contact
|
81
|
+
- [ ] Delete a contact
|
82
|
+
|
83
|
+
**Subscriptions**
|
84
|
+
- [ ] Subscribe to a channel
|
85
|
+
- [X] List subscriptions
|
86
|
+
- [ ] Unsubscribe from a channel
|
87
|
+
- [X] Get information about a channel
|
88
|
+
|
89
|
+
**Users**
|
90
|
+
- [X] Get the current user
|
91
|
+
- [ ] Update the current user
|
92
|
+
|
93
|
+
**Realtime Event Stream**
|
94
|
+
- Not yet
|
58
95
|
|
59
96
|
## Contributing
|
60
97
|
|
data/Rakefile
CHANGED
data/lib/washbullet.rb
CHANGED
data/lib/washbullet/api.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'washbullet/api/contacts'
|
2
2
|
require 'washbullet/api/devices'
|
3
|
-
require 'washbullet/api/pushes'
|
4
3
|
require 'washbullet/api/me'
|
4
|
+
require 'washbullet/api/pushes'
|
5
|
+
require 'washbullet/api/subscriptions'
|
5
6
|
|
6
7
|
module Washbullet
|
7
8
|
module API
|
@@ -9,5 +10,6 @@ module Washbullet
|
|
9
10
|
include Devices
|
10
11
|
include Pushes
|
11
12
|
include Me
|
13
|
+
include Subscriptions
|
12
14
|
end
|
13
15
|
end
|
@@ -2,11 +2,21 @@ module Washbullet
|
|
2
2
|
module API
|
3
3
|
module Contacts
|
4
4
|
def contacts
|
5
|
-
get
|
5
|
+
response = get('/v2/contacts')
|
6
|
+
|
7
|
+
Washbullet::Contact.from_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_contact
|
11
|
+
raise NotImplementedError
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_contact
|
15
|
+
raise NotImplementedError
|
6
16
|
end
|
7
17
|
|
8
|
-
def delete_contact
|
9
|
-
|
18
|
+
def delete_contact
|
19
|
+
raise NotImplementedError
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
@@ -2,11 +2,17 @@ module Washbullet
|
|
2
2
|
module API
|
3
3
|
module Devices
|
4
4
|
def devices
|
5
|
-
get
|
5
|
+
response = get('/v2/devices')
|
6
|
+
|
7
|
+
Washbullet::Device.from_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_device
|
11
|
+
raise NotImplementedError
|
6
12
|
end
|
7
13
|
|
8
|
-
def delete_device
|
9
|
-
|
14
|
+
def delete_device
|
15
|
+
raise NotImplementedError
|
10
16
|
end
|
11
17
|
end
|
12
18
|
end
|
data/lib/washbullet/api/me.rb
CHANGED
@@ -1,70 +1,29 @@
|
|
1
|
+
require 'washbullet/pushable'
|
2
|
+
require 'washbullet/pushable/file'
|
3
|
+
require 'washbullet/pushable/link'
|
4
|
+
require 'washbullet/pushable/note'
|
5
|
+
|
1
6
|
module Washbullet
|
2
7
|
module API
|
3
8
|
module Pushes
|
4
|
-
def push_note(
|
5
|
-
push
|
6
|
-
end
|
7
|
-
|
8
|
-
def push_link(device_iden, title, url, body)
|
9
|
-
push :link, device_iden, title: title, url: url, body: body
|
10
|
-
end
|
11
|
-
|
12
|
-
def push_address(device_iden, name, address)
|
13
|
-
push :address, device_iden, name: name, address: address
|
9
|
+
def push_note(receiver: nil, identifier: nil, params: {})
|
10
|
+
Washbullet::Pushable::Note.push(self, receiver, identifier, params)
|
14
11
|
end
|
15
12
|
|
16
|
-
def
|
17
|
-
push
|
13
|
+
def push_link(receiver: nil, identifier: nil, params: {})
|
14
|
+
Washbullet::Pushable::Link.push(self, receiver, identifier, params)
|
18
15
|
end
|
19
16
|
|
20
|
-
def push_file(
|
21
|
-
|
22
|
-
payload = {
|
23
|
-
file_name: data['file_name'],
|
24
|
-
file_type: data['file_type'],
|
25
|
-
file_url: data['file_url'],
|
26
|
-
body: body
|
27
|
-
}
|
28
|
-
|
29
|
-
push :file, device_iden, payload
|
30
|
-
end
|
17
|
+
def push_file(receiver: nil, identifier: nil, params: {})
|
18
|
+
Washbullet::Pushable::File.push(self, receiver, identifier, params)
|
31
19
|
end
|
32
20
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
params = params.values.all?(&:nil?) ? {} : params
|
37
|
-
|
38
|
-
get 'v2/pushes', params
|
21
|
+
def get_pushes(modified_after = nil, cursor = nil)
|
22
|
+
raise NotImplementedError
|
39
23
|
end
|
40
24
|
|
41
25
|
def delete_push(push_iden)
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def upload_file(file_name, file_path, &block)
|
48
|
-
mime_type = MIME::Types.type_for(file_path).first.to_s
|
49
|
-
|
50
|
-
data = upload_request(file_name, mime_type)
|
51
|
-
|
52
|
-
upload_url = data.body['upload_url']
|
53
|
-
payload = data.body['data']
|
54
|
-
|
55
|
-
io = Faraday::UploadIO.new(file_path, mime_type)
|
56
|
-
|
57
|
-
post upload_url, payload.merge(file: io)
|
58
|
-
|
59
|
-
yield data.body
|
60
|
-
end
|
61
|
-
|
62
|
-
def upload_request(file_name, mime_type)
|
63
|
-
get '/v2/upload-request', file_name: file_name, file_type: mime_type
|
64
|
-
end
|
65
|
-
|
66
|
-
def push(type, device_iden, payload)
|
67
|
-
post '/v2/pushes', payload.merge(device_iden: device_iden, type: type)
|
26
|
+
raise NotImplementedError
|
68
27
|
end
|
69
28
|
end
|
70
29
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Washbullet
|
2
|
+
module API
|
3
|
+
module Subscriptions
|
4
|
+
def subscriptions
|
5
|
+
response = get('/v2/subscriptions')
|
6
|
+
|
7
|
+
Washbullet::Channel.from_response(response)
|
8
|
+
end
|
9
|
+
|
10
|
+
def channel_info(tag)
|
11
|
+
response = get('/v2/channel-info', tag: tag).body
|
12
|
+
|
13
|
+
Washbullet::Channel.new(response)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Washbullet
|
2
|
+
class Channel
|
3
|
+
attr_reader :body
|
4
|
+
|
5
|
+
def self.from_response(response)
|
6
|
+
response.body['subscriptions'].each_with_object([]) {|attributes, memo|
|
7
|
+
next unless attributes['active']
|
8
|
+
|
9
|
+
memo << new(attributes['channel'])
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(response_body)
|
14
|
+
@body = response_body
|
15
|
+
end
|
16
|
+
|
17
|
+
def name
|
18
|
+
body['name']
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
body['description']
|
23
|
+
end
|
24
|
+
|
25
|
+
def identifier
|
26
|
+
body['iden']
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/washbullet/client.rb
CHANGED
@@ -2,7 +2,7 @@ require 'faraday'
|
|
2
2
|
require 'mime/types'
|
3
3
|
|
4
4
|
require 'washbullet/api'
|
5
|
-
require 'washbullet/
|
5
|
+
require 'washbullet/authorization'
|
6
6
|
require 'washbullet/http_exception'
|
7
7
|
require 'washbullet/parse_json'
|
8
8
|
require 'washbullet/request'
|
@@ -21,33 +21,33 @@ module Washbullet
|
|
21
21
|
@api_key = api_key
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
@middleware ||= Faraday::RackBuilder.new do |f|
|
26
|
-
f.request :multipart
|
27
|
-
f.request :url_encoded
|
28
|
-
|
29
|
-
f.use Washbullet::BasicAuthentication, @api_key, ''
|
30
|
-
f.use Washbullet::ParseJSON
|
31
|
-
f.use Washbullet::HttpException
|
24
|
+
private
|
32
25
|
|
33
|
-
|
34
|
-
|
26
|
+
def connection
|
27
|
+
@connection ||= Faraday.new(ENDPOINT, connection_options)
|
35
28
|
end
|
36
29
|
|
37
30
|
def connection_options
|
38
31
|
@connection_options ||= {
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
32
|
+
builder: middleware,
|
33
|
+
headers: {
|
34
|
+
accept: 'application/json',
|
35
|
+
user_agent: "Washbullet Ruby Gem #{Washbullet::VERSION}"
|
43
36
|
}
|
44
37
|
}
|
45
38
|
end
|
46
39
|
|
47
|
-
|
40
|
+
def middleware
|
41
|
+
@middleware ||= Faraday::RackBuilder.new do |f|
|
42
|
+
f.request :multipart
|
43
|
+
f.request :url_encoded
|
48
44
|
|
49
|
-
|
50
|
-
|
45
|
+
f.use Washbullet::Authorization, 'Bearer', api_key
|
46
|
+
f.use Washbullet::ParseJSON
|
47
|
+
f.use Washbullet::HttpException
|
48
|
+
|
49
|
+
f.adapter :net_http
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|