ruby-pushbullet 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +63 -0
- data/lib/core_ext/string.rb +9 -0
- data/lib/pushbullet.rb +25 -0
- data/lib/pushbullet/channel.rb +5 -0
- data/lib/pushbullet/client.rb +28 -0
- data/lib/pushbullet/contact.rb +21 -0
- data/lib/pushbullet/device.rb +17 -0
- data/lib/pushbullet/push.rb +5 -0
- data/lib/pushbullet/pushable.rb +27 -0
- data/lib/pushbullet/resource.rb +28 -0
- data/spec/fixtures/vcr_cassettes/contacts_all.yml +42 -0
- data/spec/fixtures/vcr_cassettes/contacts_create.yml +46 -0
- data/spec/fixtures/vcr_cassettes/contacts_remove.yml +42 -0
- data/spec/fixtures/vcr_cassettes/contacts_update.yml +47 -0
- data/spec/fixtures/vcr_cassettes/devices_all.yml +42 -0
- data/spec/fixtures/vcr_cassettes/devices_create.yml +47 -0
- data/spec/fixtures/vcr_cassettes/devices_remove.yml +42 -0
- data/spec/fixtures/vcr_cassettes/devices_update.yml +47 -0
- data/spec/pushbullet/contact_spec.rb +55 -0
- data/spec/pushbullet/devices_spec.rb +55 -0
- data/spec/pushbullet_spec.rb +23 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/support/factories.rb +23 -0
- metadata +262 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6a02b2f222504da04a87dcb0e26f2b3cdb584c7
|
4
|
+
data.tar.gz: 4610a8f50ba0ee77cd7f8f3692aa296a283cadbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f3510d3b8eec8491db05af3117a9877fe40f56ce317f4f90c88bb0bf4289114d54de9a762c99c5374ba937faa971cccb87bedbe252f99f4063f78eeb4488ccc
|
7
|
+
data.tar.gz: 3e75f31d44050bc2e62f3470b512d8439295e9ca5cbabf7a8e5f3bb2a07648d96bb9f720f3bd1f1a54b764b6109ee77c7c70432b813ac4c6a69c5396a22cf517
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Ruby Pushbullet API
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/letz/ruby-pushbullet.svg)](https://travis-ci.org/letz/ruby-pushbullet)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/letz/ruby-pushbullet/badges/gpa.svg)](https://codeclimate.com/github/letz/ruby-pushbullet)
|
5
|
+
|
6
|
+
|
7
|
+
This library is an implementation of [Pushbullet API](https://docs.pushbullet.com/http)
|
8
|
+
|
9
|
+
|
10
|
+
Feel free to contribute :smile:
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
|
14
|
+
You can get your api token from [Account Settings](https://www.pushbullet.com/account)
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
Pushbullet.api_token = 'YOUR_API_TOKEN'
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Contact
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# Get all contacts
|
26
|
+
Pushbullet::Contact.all
|
27
|
+
|
28
|
+
# create contact
|
29
|
+
contact = Pushbullet::Contact.create('Name', 'example@mail.com')
|
30
|
+
contact.name = 'Another name'
|
31
|
+
contact.save # update
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
### Device
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Get all devices
|
39
|
+
devices = Pushbullet::Device.all
|
40
|
+
|
41
|
+
# create device
|
42
|
+
device = Pushbullet::Device.create('Device Name', 'stream')
|
43
|
+
device.nickname = 'Another name'
|
44
|
+
device.save #update
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
### Push
|
49
|
+
|
50
|
+
DOC TODO...
|
51
|
+
|
52
|
+
### Channel
|
53
|
+
|
54
|
+
TODO...
|
55
|
+
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/lib/pushbullet.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'logger'
|
3
|
+
require 'pushbullet/pushable'
|
4
|
+
require 'pushbullet/client'
|
5
|
+
require 'pushbullet/resource'
|
6
|
+
require 'pushbullet/contact'
|
7
|
+
require 'pushbullet/device'
|
8
|
+
require 'pushbullet/push'
|
9
|
+
require 'pushbullet/channel'
|
10
|
+
|
11
|
+
require 'core_ext/string.rb'
|
12
|
+
|
13
|
+
module Pushbullet
|
14
|
+
def self.api_token=(api_token)
|
15
|
+
@api_token = api_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.api_token
|
19
|
+
@api_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.client
|
23
|
+
@client ||= Client.new
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
class Client
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
API_VERSION = 2
|
6
|
+
END_POINT = "https://api.pushbullet.com/v#{API_VERSION}/"
|
7
|
+
|
8
|
+
def get(path)
|
9
|
+
JSON.parse(generic_request(path).get)
|
10
|
+
end
|
11
|
+
|
12
|
+
def post(path, params = {})
|
13
|
+
JSON.parse(generic_request(path).post params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def put(path, params = {})
|
17
|
+
JSON.parse(generic_request(path).put params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(path, params = {})
|
21
|
+
JSON.parse(generic_request(path).delete params)
|
22
|
+
end
|
23
|
+
|
24
|
+
def generic_request(path)
|
25
|
+
RestClient::Resource.new("#{END_POINT}#{path}", Pushbullet.api_token, '')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
class Contact < Resource
|
3
|
+
include Pushable
|
4
|
+
|
5
|
+
def self.me
|
6
|
+
new Pushbullet.client.get('users/me')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.create(name, email)
|
10
|
+
super(name: name, email: email)
|
11
|
+
end
|
12
|
+
|
13
|
+
def save
|
14
|
+
super(name: name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def target_id
|
18
|
+
email
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
module Pushable
|
3
|
+
|
4
|
+
def push_note(title, body)
|
5
|
+
push :note, target_id, title: title, body: body
|
6
|
+
end
|
7
|
+
|
8
|
+
def push_link(title, url, body)
|
9
|
+
push :link, target_id, title: title, url: url, body: body
|
10
|
+
end
|
11
|
+
|
12
|
+
def push_address(name, address)
|
13
|
+
push :address, target_id, name: name, address: address
|
14
|
+
end
|
15
|
+
|
16
|
+
def push_list(title, items)
|
17
|
+
push :list, target_id, title: title, items: items
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def push(type, iden, payload)
|
23
|
+
id = iden[/.@.?/].nil? ? :device_iden : :email
|
24
|
+
Push.create(payload.merge(type: type, id => iden))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
class Resource < OpenStruct
|
3
|
+
def self.path
|
4
|
+
klass = self.is_a?(Class) ? self : self.class
|
5
|
+
@path ||= "#{klass.to_s.demodulize.downcase}s"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.create(params)
|
9
|
+
new Pushbullet.client.post(path, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
Pushbullet.client.get(path)[path].map do |model|
|
14
|
+
new model
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def save(params)
|
19
|
+
Pushbullet.client.post "#{self.class.path}/#{iden}", params
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy
|
24
|
+
Pushbullet.client.delete "#{self.class.path}/#{iden}"
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/contacts
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
X-Ratelimit-Limit:
|
22
|
+
- '16384'
|
23
|
+
X-Ratelimit-Remaining:
|
24
|
+
- '16310'
|
25
|
+
X-Ratelimit-Reset:
|
26
|
+
- '1422816448'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Sun, 01 Feb 2015 18:40:46 GMT
|
31
|
+
Server:
|
32
|
+
- Google Frontend
|
33
|
+
Cache-Control:
|
34
|
+
- private
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"accounts":[],"aliases":[],"channels":[],"clients":[],"contacts":[{"active":true,"iden":"ujDyIULYgfzfjz2gdna9Aq","created":1.4228159998264918e+09,"modified":1.422815999899859e+09,"name":"Letz","email":"letzdevelopment@gmail.com","email_normalized":"letzdevelopment@gmail.com","image_url":"https://lh4.googleusercontent.com/-8DrZNufiorA/AAAAAAAAAAI/AAAAAAAABBE/E2qgJVUDOVs/photo.jpg","status":"user"},{"active":false,"iden":"ujDyIULYUzHsDAsgeMFET6","created":1.422815930339784e+09,"modified":1.422815957377471e+09},{"active":false,"iden":"ujDyIULYrzUsjz7O3P0Jl6","created":1.422815385822734e+09,"modified":1.422815850765312e+09}],"devices":[],"grants":[],"pushes":[],"subscriptions":[]}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sun, 01 Feb 2015 18:40:47 GMT
|
42
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,46 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/contacts
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: name=Letz&email=letzdevelopment%40gmail.com
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Length:
|
15
|
+
- '43'
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
X-Ratelimit-Limit:
|
26
|
+
- '16384'
|
27
|
+
X-Ratelimit-Remaining:
|
28
|
+
- '16313'
|
29
|
+
X-Ratelimit-Reset:
|
30
|
+
- '1422816448'
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
Date:
|
34
|
+
- Sun, 01 Feb 2015 18:40:00 GMT
|
35
|
+
Server:
|
36
|
+
- Google Frontend
|
37
|
+
Cache-Control:
|
38
|
+
- private
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"active":true,"iden":"ujDyIULYrzUsjz2gRnO9Aq","created":1.422815999826493e+09,"modified":1.4228159998998592e+09,"name":"Letz","email":"letzdevelopment@gmail.com","email_normalized":"letzdevelopment@gmail.com","image_url":"https://lh4.googleusercontent.com/-8DrZDuQiorA/AAAAAAAAAAI/AAAAAAAAABE/E2qsJVU6OVs/photo.jpg","status":"user"}'
|
44
|
+
http_version:
|
45
|
+
recorded_at: Sun, 01 Feb 2015 18:40:00 GMT
|
46
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/contacts/ujDyIULYrzUsjAw1gZVXy0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
X-Ratelimit-Limit:
|
22
|
+
- '16384'
|
23
|
+
X-Ratelimit-Remaining:
|
24
|
+
- '16341'
|
25
|
+
X-Ratelimit-Reset:
|
26
|
+
- '1422820048'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Sun, 01 Feb 2015 19:15:21 GMT
|
31
|
+
Server:
|
32
|
+
- Google Frontend
|
33
|
+
Cache-Control:
|
34
|
+
- private
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: "{}"
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sun, 01 Feb 2015 19:15:21 GMT
|
42
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/contacts/ujDyIULYrzUsjAw1gZVXy0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: name=Another%20name
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Length:
|
15
|
+
- '19'
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
X-Ratelimit-Limit:
|
28
|
+
- '16384'
|
29
|
+
X-Ratelimit-Remaining:
|
30
|
+
- '16288'
|
31
|
+
X-Ratelimit-Reset:
|
32
|
+
- '1422820048'
|
33
|
+
Date:
|
34
|
+
- Sun, 01 Feb 2015 19:24:46 GMT
|
35
|
+
Server:
|
36
|
+
- Google Frontend
|
37
|
+
Cache-Control:
|
38
|
+
- private
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"active":true,"iden":"ujDyIULYrzUsjAw1gZVXy0","created":1.422818159713302e+09,"modified":1.422818686629124e+09,"name":"Another
|
44
|
+
name","email":"lol@lol.com","email_normalized":"lol@lol.com","status":"not_user"}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sun, 01 Feb 2015 19:24:46 GMT
|
47
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/devices
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
X-Ratelimit-Limit:
|
22
|
+
- '16384'
|
23
|
+
X-Ratelimit-Remaining:
|
24
|
+
- '16275'
|
25
|
+
X-Ratelimit-Reset:
|
26
|
+
- '1422820048'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Date:
|
30
|
+
- Sun, 01 Feb 2015 19:33:12 GMT
|
31
|
+
Server:
|
32
|
+
- Google Frontend
|
33
|
+
Cache-Control:
|
34
|
+
- private
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"accounts":[],"aliases":[],"channels":[],"clients":[],"contacts":[],"devices":[{"active":true,"iden":"ujDyIULYrzDsdAifsGndTs","created":1.422814385454507e+09,"modified":1.4228143854545121e+09,"type":"safari","kind":"safari","nickname":"Safari","manufacturer":"Apple","model":"Safari","app_version":2,"pushable":true}],"grants":[],"pushes":[],"subscriptions":[]}'
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sun, 01 Feb 2015 19:33:12 GMT
|
42
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/devices
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: nickname=Letz%20Device&type=stream
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Length:
|
15
|
+
- '34'
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
X-Ratelimit-Limit:
|
28
|
+
- '16384'
|
29
|
+
X-Ratelimit-Remaining:
|
30
|
+
- '16274'
|
31
|
+
X-Ratelimit-Reset:
|
32
|
+
- '1422820048'
|
33
|
+
Date:
|
34
|
+
- Sun, 01 Feb 2015 19:36:01 GMT
|
35
|
+
Server:
|
36
|
+
- Google Frontend
|
37
|
+
Cache-Control:
|
38
|
+
- private
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"active":true,"iden":"ujDyIULYrzUsjAlDVWxUrc","created":1.4228193610399036e+09,"modified":1.4228193610399084e+09,"type":"stream","kind":"stream","nickname":"Letz
|
44
|
+
Device","pushable":true}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sun, 01 Feb 2015 19:36:01 GMT
|
47
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,42 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/devices/ujDyIULYrzUsjAlDVWxUrc
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
X-Ratelimit-Reset:
|
22
|
+
- '1422820048'
|
23
|
+
Content-Type:
|
24
|
+
- application/json; charset=utf-8
|
25
|
+
X-Ratelimit-Limit:
|
26
|
+
- '16384'
|
27
|
+
X-Ratelimit-Remaining:
|
28
|
+
- '16268'
|
29
|
+
Date:
|
30
|
+
- Sun, 01 Feb 2015 19:39:31 GMT
|
31
|
+
Server:
|
32
|
+
- Google Frontend
|
33
|
+
Cache-Control:
|
34
|
+
- private
|
35
|
+
Transfer-Encoding:
|
36
|
+
- chunked
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: "{}"
|
40
|
+
http_version:
|
41
|
+
recorded_at: Sun, 01 Feb 2015 19:39:31 GMT
|
42
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd:@api.pushbullet.com/v2/devices/ujDyIULYrzUsjAlDVWxUrc
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: nickname=Another%20name
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*; q=0.5, application/xml"
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
Content-Length:
|
15
|
+
- '23'
|
16
|
+
Content-Type:
|
17
|
+
- application/x-www-form-urlencoded
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
X-Ratelimit-Reset:
|
26
|
+
- '1422820048'
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
X-Ratelimit-Limit:
|
30
|
+
- '16384'
|
31
|
+
X-Ratelimit-Remaining:
|
32
|
+
- '16271'
|
33
|
+
Date:
|
34
|
+
- Sun, 01 Feb 2015 19:39:03 GMT
|
35
|
+
Server:
|
36
|
+
- Google Frontend
|
37
|
+
Cache-Control:
|
38
|
+
- private
|
39
|
+
Transfer-Encoding:
|
40
|
+
- chunked
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: '{"active":true,"iden":"ujDyIULYrzUsjAlDVWxUrc","created":1.422819361039903e+09,"modified":1.422819543293327e+09,"type":"stream","kind":"stream","nickname":"Another
|
44
|
+
name","pushable":true}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Sun, 01 Feb 2015 19:39:03 GMT
|
47
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushbullet::Contact do
|
4
|
+
describe '::all' do
|
5
|
+
it 'returns all contacts' do
|
6
|
+
VCR.use_cassette('contacts_all') do
|
7
|
+
expect(described_class.all).to be_a Array
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns iterable of Contacts' do
|
12
|
+
VCR.use_cassette('contacts_all') do
|
13
|
+
described_class.all.each do |cont|
|
14
|
+
expect(cont).to be_a described_class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '::create' do
|
21
|
+
context 'given an name and a email' do
|
22
|
+
let(:name) { 'Letz' }
|
23
|
+
let(:email) { 'letzdevelopment@gmail.com' }
|
24
|
+
|
25
|
+
it 'returns a contact' do
|
26
|
+
VCR.use_cassette('contacts_create') do
|
27
|
+
expect(described_class.create name, email).to be_a described_class
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#destroy' do
|
34
|
+
context 'given a contact' do
|
35
|
+
let(:contact) { build(:contact) }
|
36
|
+
|
37
|
+
it 'removes a contact' do
|
38
|
+
VCR.use_cassette('contacts_remove') do
|
39
|
+
expect(contact.destroy).to be_truthy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#save' do
|
46
|
+
let(:contact) { build(:contact) }
|
47
|
+
before { contact.name = 'Another name' }
|
48
|
+
|
49
|
+
it 'updates the name of the contact' do
|
50
|
+
VCR.use_cassette('contacts_update') do
|
51
|
+
expect(contact.save).to be_truthy
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushbullet::Device do
|
4
|
+
describe '::all' do
|
5
|
+
it 'returns all devices' do
|
6
|
+
VCR.use_cassette('devices_all') do
|
7
|
+
expect(described_class.all).to be_a Array
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns iterable of Devices' do
|
12
|
+
VCR.use_cassette('devices_all') do
|
13
|
+
described_class.all.each do |cont|
|
14
|
+
expect(cont).to be_a described_class
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '::create' do
|
21
|
+
context 'given an nickname and a type' do
|
22
|
+
let(:nickname) { 'Letz Device' }
|
23
|
+
let(:type) { 'stream' }
|
24
|
+
|
25
|
+
it 'returns a device' do
|
26
|
+
VCR.use_cassette('devices_create') do
|
27
|
+
expect(described_class.create nickname, type).to be_a described_class
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#destroy' do
|
34
|
+
context 'given a device' do
|
35
|
+
let(:device) { build(:device) }
|
36
|
+
|
37
|
+
it 'removes a device' do
|
38
|
+
VCR.use_cassette('devices_remove') do
|
39
|
+
expect(device.destroy).to be_truthy
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#save' do
|
46
|
+
let(:device) { build(:device) }
|
47
|
+
before { device.nickname = 'Another name' }
|
48
|
+
|
49
|
+
it 'updates the name of the device' do
|
50
|
+
VCR.use_cassette('devices_update') do
|
51
|
+
expect(device.save).to be_truthy
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pushbullet do
|
4
|
+
describe '::api_token=' do
|
5
|
+
before { described_class.api_token = nil }
|
6
|
+
after { described_class.api_token = 'DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd' }
|
7
|
+
context 'given an api_token' do
|
8
|
+
let(:token) { 'nice_try' }
|
9
|
+
|
10
|
+
it 'sets the Pushbullet api token' do
|
11
|
+
expect {
|
12
|
+
described_class.api_token = token
|
13
|
+
}.to change { described_class.api_token }.from(nil).to(token)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '::client' do
|
19
|
+
it 'returns a Pushbullet::Client' do
|
20
|
+
expect(described_class.client).to be_a Pushbullet::Client
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
if ENV['SIMPLECOV']
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start 'rails'
|
4
|
+
puts 'required simplecov'
|
5
|
+
end
|
6
|
+
require 'webmock/rspec'
|
7
|
+
require 'awesome_print'
|
8
|
+
require 'factory_girl'
|
9
|
+
require 'pry'
|
10
|
+
require 'vcr'
|
11
|
+
require 'support/factories'
|
12
|
+
|
13
|
+
require 'bundler/setup'
|
14
|
+
Bundler.setup
|
15
|
+
|
16
|
+
require 'pushbullet'
|
17
|
+
|
18
|
+
VCR.configure do |c|
|
19
|
+
c.allow_http_connections_when_no_cassette = false
|
20
|
+
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
21
|
+
c.hook_into :webmock # or :fakeweb
|
22
|
+
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.raise_errors_for_deprecations!
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
config.filter_run focus: true
|
28
|
+
config.order = 'random'
|
29
|
+
config.include FactoryGirl::Syntax::Methods
|
30
|
+
end
|
31
|
+
|
32
|
+
Pushbullet.api_token = 'DhOX5Q8Fps9mq4g90yfrfioRPyo1qQRd'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'pushbullet'
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
factory :contact, class: Pushbullet::Contact do
|
5
|
+
iden 'ujDyIULYrzUsjAw1gZVXy0'
|
6
|
+
name 'Letz'
|
7
|
+
created 1.42281936103990364e+09
|
8
|
+
modified 1.4228193610399084e+09
|
9
|
+
email 'letzdevelopment@gmail.com'
|
10
|
+
email_normalized 'letzdevelopment@gmail.com'
|
11
|
+
active true
|
12
|
+
end
|
13
|
+
|
14
|
+
factory :device, class: Pushbullet::Device do
|
15
|
+
iden 'ujDyIULYrzUsjAlDVWxUrc'
|
16
|
+
nickname 'Letz Device'
|
17
|
+
created 1.42281936103990364e+09
|
18
|
+
modified 1.4228193610399084e+09
|
19
|
+
type 'stream'
|
20
|
+
pushable true
|
21
|
+
active true
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,262 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-pushbullet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo Leitao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: awesome_print
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rest-client
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.7.2
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.7.2
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: json
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: Ruby client of Pushbullet API.
|
196
|
+
email:
|
197
|
+
- letzdevelopment@gmail.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- README.md
|
203
|
+
- lib/core_ext/string.rb
|
204
|
+
- lib/pushbullet.rb
|
205
|
+
- lib/pushbullet/channel.rb
|
206
|
+
- lib/pushbullet/client.rb
|
207
|
+
- lib/pushbullet/contact.rb
|
208
|
+
- lib/pushbullet/device.rb
|
209
|
+
- lib/pushbullet/push.rb
|
210
|
+
- lib/pushbullet/pushable.rb
|
211
|
+
- lib/pushbullet/resource.rb
|
212
|
+
- spec/fixtures/vcr_cassettes/contacts_all.yml
|
213
|
+
- spec/fixtures/vcr_cassettes/contacts_create.yml
|
214
|
+
- spec/fixtures/vcr_cassettes/contacts_remove.yml
|
215
|
+
- spec/fixtures/vcr_cassettes/contacts_update.yml
|
216
|
+
- spec/fixtures/vcr_cassettes/devices_all.yml
|
217
|
+
- spec/fixtures/vcr_cassettes/devices_create.yml
|
218
|
+
- spec/fixtures/vcr_cassettes/devices_remove.yml
|
219
|
+
- spec/fixtures/vcr_cassettes/devices_update.yml
|
220
|
+
- spec/pushbullet/contact_spec.rb
|
221
|
+
- spec/pushbullet/devices_spec.rb
|
222
|
+
- spec/pushbullet_spec.rb
|
223
|
+
- spec/spec_helper.rb
|
224
|
+
- spec/support/factories.rb
|
225
|
+
homepage: https://github.com/letz/ruby-pushbullet
|
226
|
+
licenses:
|
227
|
+
- MIT
|
228
|
+
metadata: {}
|
229
|
+
post_install_message:
|
230
|
+
rdoc_options: []
|
231
|
+
require_paths:
|
232
|
+
- lib
|
233
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
requirements:
|
240
|
+
- - ">="
|
241
|
+
- !ruby/object:Gem::Version
|
242
|
+
version: '0'
|
243
|
+
requirements: []
|
244
|
+
rubyforge_project:
|
245
|
+
rubygems_version: 2.2.2
|
246
|
+
signing_key:
|
247
|
+
specification_version: 4
|
248
|
+
summary: Ruby client of Pushbullet API.
|
249
|
+
test_files:
|
250
|
+
- spec/fixtures/vcr_cassettes/contacts_all.yml
|
251
|
+
- spec/fixtures/vcr_cassettes/contacts_create.yml
|
252
|
+
- spec/fixtures/vcr_cassettes/contacts_remove.yml
|
253
|
+
- spec/fixtures/vcr_cassettes/contacts_update.yml
|
254
|
+
- spec/fixtures/vcr_cassettes/devices_all.yml
|
255
|
+
- spec/fixtures/vcr_cassettes/devices_create.yml
|
256
|
+
- spec/fixtures/vcr_cassettes/devices_remove.yml
|
257
|
+
- spec/fixtures/vcr_cassettes/devices_update.yml
|
258
|
+
- spec/pushbullet/contact_spec.rb
|
259
|
+
- spec/pushbullet/devices_spec.rb
|
260
|
+
- spec/pushbullet_spec.rb
|
261
|
+
- spec/spec_helper.rb
|
262
|
+
- spec/support/factories.rb
|