pushbullet 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/pushbullet.rb +4 -0
- 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 +3 -0
- data/pushbullet.gemspec +26 -0
- metadata +33 -30
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: be35afddb98a01ce58725c0ccd0604c4df67b855
|
4
|
+
data.tar.gz: c5da93a111ae4936f2e0fa11a6674c0794a25cc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f701623a37f71d08481c010e34f2190fcced2e38ba6fdeedd6a41238d9066028d99422e98ae9d7c18044618142d69cb436974edb2e36e6766cee2d15ecc3ea8
|
7
|
+
data.tar.gz: 7aec7c154b887eb86b8eded3353a0d4fe871bfedbffab948c778ec491c00a0431cd114a92d998e72874d702ab55ade91cf309e13217c1301c662a180350f08ee
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Hiroshi Yoshida
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Pushbullet
|
2
|
+
PushBullet's API enables developers to push to devices that have installed the PushBullet Android app. Authentication is provided by a user's API key, found in their Account Settings. By using an API key, users can allow third party software built on this API without needing to provide their Google account and password.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
gem 'pushbullet'
|
6
|
+
|
7
|
+
#### Setup Client
|
8
|
+
copy following content and paste into config/initializers/pushbullet.rb
|
9
|
+
|
10
|
+
PUSHBULLET_API_KEY = 'YOUR_PUSHBULLET_KEY_HERE'
|
11
|
+
|
12
|
+
#### Usage
|
13
|
+
client = Pushbullet::Client.new(PUSHBULLET_API_KEY)
|
14
|
+
|
15
|
+
#### Push to own device
|
16
|
+
|
17
|
+
You can send following list:
|
18
|
+
- note
|
19
|
+
- link
|
20
|
+
- address
|
21
|
+
- list
|
22
|
+
- file
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
# get json about own device list
|
26
|
+
client.devices
|
27
|
+
|
28
|
+
client.push_note(DEVICE_ID, 'title', 'message')
|
29
|
+
client.push_file(DEVICE_ID, 'File Name', 'path/to/file')
|
30
|
+
```
|
31
|
+
|
32
|
+
#### :secret: Push to Friend's device :secret:
|
33
|
+
|
34
|
+
You can send following list:
|
35
|
+
- note
|
36
|
+
- link
|
37
|
+
- address
|
38
|
+
- list
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# get json about friend list of Pushbullet
|
42
|
+
client.contacts
|
43
|
+
|
44
|
+
client.push_note_to('a@b.c', 'title', 'full message')
|
45
|
+
```
|
46
|
+
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( http://github.com/vajapravin/pushbullet/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-pushbullet`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-pushbullet`)
|
54
|
+
5. Create new Pull Request
|
55
|
+
|
56
|
+
Don't hesitate to write problems [vajapravin23@gmail.com]
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/pushbullet.rb
ADDED
@@ -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'
|
4
|
+
require 'pushbullet/api'
|
5
|
+
require 'pushbullet/secret_api'
|
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'
|
2
|
+
require 'pushbullet/parse_json'
|
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'
|
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/pushbullet.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pushbullet/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'pushbullet'
|
7
|
+
gem.version = '0.0.4'
|
8
|
+
gem.authors = ['vajapravin']
|
9
|
+
gem.email = ['vajapravin23@gmail.com']
|
10
|
+
gem.summary = %q{Ruby client of Pushbullet API.}
|
11
|
+
gem.description = %q{Ruby client of Pushbullet API.}
|
12
|
+
gem.homepage = 'http://vajapravin.com'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'bundler'
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'pry'
|
23
|
+
|
24
|
+
gem.add_dependency 'faraday'
|
25
|
+
gem.add_dependency 'mime-types'
|
26
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pushbullet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- vajapravin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-06-17 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: pry
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: faraday
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: mime-types
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :runtime
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Ruby client of Pushbullet API.
|
@@ -97,30 +86,44 @@ email:
|
|
97
86
|
executables: []
|
98
87
|
extensions: []
|
99
88
|
extra_rdoc_files: []
|
100
|
-
files:
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/pushbullet.rb
|
96
|
+
- lib/pushbullet/api.rb
|
97
|
+
- lib/pushbullet/client.rb
|
98
|
+
- lib/pushbullet/connection.rb
|
99
|
+
- lib/pushbullet/http_exception.rb
|
100
|
+
- lib/pushbullet/parse_json.rb
|
101
|
+
- lib/pushbullet/request.rb
|
102
|
+
- lib/pushbullet/secret_api.rb
|
103
|
+
- lib/pushbullet/version.rb
|
104
|
+
- pushbullet.gemspec
|
101
105
|
homepage: http://vajapravin.com
|
102
106
|
licenses:
|
103
107
|
- MIT
|
108
|
+
metadata: {}
|
104
109
|
post_install_message:
|
105
110
|
rdoc_options: []
|
106
111
|
require_paths:
|
107
112
|
- lib
|
108
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
114
|
requirements:
|
111
|
-
- -
|
115
|
+
- - ">="
|
112
116
|
- !ruby/object:Gem::Version
|
113
117
|
version: '0'
|
114
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
-
none: false
|
116
119
|
requirements:
|
117
|
-
- -
|
120
|
+
- - ">="
|
118
121
|
- !ruby/object:Gem::Version
|
119
122
|
version: '0'
|
120
123
|
requirements: []
|
121
124
|
rubyforge_project:
|
122
|
-
rubygems_version:
|
125
|
+
rubygems_version: 2.2.2
|
123
126
|
signing_key:
|
124
|
-
specification_version:
|
127
|
+
specification_version: 4
|
125
128
|
summary: Ruby client of Pushbullet API.
|
126
129
|
test_files: []
|