pushbullet 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/pushbullet.rb +1 -1
- data/lib/pushbullet/api.rb +36 -0
- data/lib/pushbullet/client.rb +19 -0
- data/lib/pushbullet/connection.rb +22 -0
- data/lib/pushbullet/http_exception.rb +31 -0
- data/lib/pushbullet/parse_json.rb +9 -0
- data/lib/pushbullet/request.rb +24 -0
- data/lib/pushbullet/secret_api.rb +30 -0
- data/lib/pushbullet/version.rb +1 -1
- metadata +20 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca5dffc1d979f6492e41a045f313d5f4b207200f
|
4
|
+
data.tar.gz: c5c6952bd980cbb7654a0bff3e9f31f4960cdcb9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e09b88dcb69a6fbcf4123e7cbe870c722b511fa01111272391161a5e7ec7273d4271f927aec855d00f51e8b4947c28eb5d808c8d2b8298431b592d5f3d3f325
|
7
|
+
data.tar.gz: 8d675ada929594ee2dc7a58c3a6a75bcbe30c9594ddf75d43d8e2868fc84fe359557455ce9996f4d20b96aad3ec9d1c9c3113f81efbe316b61d7b9ea5bda9145
|
data/README.md
CHANGED
@@ -59,7 +59,7 @@ client.push_note_to('a@b.c', 'title', 'full message')
|
|
59
59
|
```
|
60
60
|
## Contributing
|
61
61
|
|
62
|
-
1. Fork it ( http://github.com/vajapravin/
|
62
|
+
1. Fork it ( http://github.com/vajapravin/pushbullet/fork )
|
63
63
|
2. Create your feature branch (`git checkout -b my-pushbullet`)
|
64
64
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
65
|
4. Push to the branch (`git push origin my-pushbullet`)
|
data/lib/pushbullet.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
module API
|
3
|
+
def devices
|
4
|
+
get('/api/devices')
|
5
|
+
end
|
6
|
+
|
7
|
+
def push_note(device_id, title, body)
|
8
|
+
push :note, device_id, title: title, body: body
|
9
|
+
end
|
10
|
+
|
11
|
+
def push_link(device_id, title, url)
|
12
|
+
push :link, device_id, title: title, url: url
|
13
|
+
end
|
14
|
+
|
15
|
+
def push_address(device_id, title, address)
|
16
|
+
push :address, device_id, title: title, address: address
|
17
|
+
end
|
18
|
+
|
19
|
+
def push_list(device_id, title, items)
|
20
|
+
push :list, device_id, title: title, items: items
|
21
|
+
end
|
22
|
+
|
23
|
+
def push_file(device_id, file_path)
|
24
|
+
mime_type = MIME::Types.type_for(file_path).first.to_s
|
25
|
+
io = Faraday::UploadIO.new(file_path, mime_type)
|
26
|
+
|
27
|
+
push :file, device_id, file: io
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def push(type, device_id, payload)
|
33
|
+
post '/api/pushes', payload.merge(device_id: device_id, type: type)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'mime/types'
|
3
|
+
require 'pushbullet/request.rb'
|
4
|
+
require 'pushbullet/api.rb'
|
5
|
+
require 'pushbullet/secret_api.rb'
|
6
|
+
|
7
|
+
module Pushbullet
|
8
|
+
class Client
|
9
|
+
include Request
|
10
|
+
include API
|
11
|
+
include SecretAPI
|
12
|
+
|
13
|
+
attr_reader :api_key
|
14
|
+
|
15
|
+
def initialize(api_key)
|
16
|
+
@api_key = api_key
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pushbullet/http_exception.rb'
|
2
|
+
require 'pushbullet/parse_json.rb'
|
3
|
+
|
4
|
+
module Pushbullet
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
def connection
|
8
|
+
@connection ||= Faraday.new(url: 'https://api.pushbullet.com/') do |f|
|
9
|
+
f.request :basic_auth, api_key, ''
|
10
|
+
f.request :multipart
|
11
|
+
f.request :url_encoded
|
12
|
+
|
13
|
+
f.response :logger
|
14
|
+
|
15
|
+
f.use Pushbullet::ParseJSON
|
16
|
+
f.use Pushbullet::HttpException
|
17
|
+
|
18
|
+
f.adapter :net_http
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Pushbullet
|
4
|
+
class BadRequest < StandardError; end
|
5
|
+
class Unauthorized < StandardError; end
|
6
|
+
class RequestFailed < StandardError; end
|
7
|
+
class Forbidden < StandardError; end
|
8
|
+
class NotFound < StandardError; end
|
9
|
+
class ServerError < StandardError; end
|
10
|
+
|
11
|
+
class HttpException < Faraday::Response::Middleware
|
12
|
+
def call(env)
|
13
|
+
@app.call(env).on_complete do |response|
|
14
|
+
case response[:status].to_i
|
15
|
+
when 400
|
16
|
+
raise Pushbullet::BadRequest, 'Often missing a required parameter'
|
17
|
+
when 401
|
18
|
+
raise Pushbullet::Unauthorized, 'No valid API key provided'
|
19
|
+
when 402
|
20
|
+
raise Pushbullet::RequestFailed, 'Parameters were valid but the request failed'
|
21
|
+
when 403
|
22
|
+
raise Pushbullet::Forbidden, 'The API key is not valid for that request'
|
23
|
+
when 404
|
24
|
+
raise Pushbullet::NotFound, 'The requested item doesn\'t exist'
|
25
|
+
when 500..505
|
26
|
+
raise Pushbullet::ServerError, 'Something went wrong on PushBullet\'s side'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'pushbullet/connection.rb'
|
2
|
+
|
3
|
+
module Pushbullet
|
4
|
+
module Request
|
5
|
+
include Connection
|
6
|
+
|
7
|
+
def get(path)
|
8
|
+
request(:get, path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(path, payload)
|
12
|
+
request(:post, path, payload)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def request(method, path, payload = {})
|
18
|
+
response = connection.send(method) {|request|
|
19
|
+
request.url path
|
20
|
+
request.body = payload if method == :post
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pushbullet
|
2
|
+
module SecretAPI
|
3
|
+
def contacts
|
4
|
+
get('/v2/contacts')
|
5
|
+
end
|
6
|
+
|
7
|
+
def push_note_to(target_email, title, body)
|
8
|
+
push_to :note, target_email, title: title, body: body
|
9
|
+
end
|
10
|
+
|
11
|
+
def push_link_to(target_email, title, url)
|
12
|
+
push_to :link, target_email, title: title, url: url
|
13
|
+
end
|
14
|
+
|
15
|
+
def push_address_to(target_email, title, address)
|
16
|
+
push_to :address, target_email, title: title, address: address
|
17
|
+
end
|
18
|
+
|
19
|
+
# FIXME Now, can send *only* one item
|
20
|
+
def push_list_to(target_email, title, items)
|
21
|
+
push_to :list, target_email, title: title, items: items
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def push_to(type, target_email, payload)
|
27
|
+
post '/api/pushes', payload.merge(target_email: target_email, type: type)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/pushbullet/version.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushbullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vajapravin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mime-types
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: PushBullet's API enables developers to push to devices that have installed
|
@@ -76,12 +76,19 @@ executables: []
|
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
78
78
|
files:
|
79
|
-
- .gitignore
|
79
|
+
- ".gitignore"
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- lib/pushbullet.rb
|
85
|
+
- lib/pushbullet/api.rb
|
86
|
+
- lib/pushbullet/client.rb
|
87
|
+
- lib/pushbullet/connection.rb
|
88
|
+
- lib/pushbullet/http_exception.rb
|
89
|
+
- lib/pushbullet/parse_json.rb
|
90
|
+
- lib/pushbullet/request.rb
|
91
|
+
- lib/pushbullet/secret_api.rb
|
85
92
|
- lib/pushbullet/version.rb
|
86
93
|
- pushbullet.gemspec
|
87
94
|
homepage: https://github.com/vajapravin/pushbullet
|
@@ -94,12 +101,12 @@ require_paths:
|
|
94
101
|
- lib
|
95
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
103
|
requirements:
|
97
|
-
- -
|
104
|
+
- - ">="
|
98
105
|
- !ruby/object:Gem::Version
|
99
106
|
version: '0'
|
100
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
108
|
requirements:
|
102
|
-
- -
|
109
|
+
- - ">="
|
103
110
|
- !ruby/object:Gem::Version
|
104
111
|
version: '0'
|
105
112
|
requirements: []
|