washbullet 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rspec +1 -1
  4. data/.travis.yml +3 -0
  5. data/README.md +61 -24
  6. data/Rakefile +6 -1
  7. data/lib/washbullet.rb +5 -0
  8. data/lib/washbullet/api.rb +3 -1
  9. data/lib/washbullet/api/contacts.rb +13 -3
  10. data/lib/washbullet/api/devices.rb +9 -3
  11. data/lib/washbullet/api/me.rb +1 -1
  12. data/lib/washbullet/api/pushes.rb +14 -55
  13. data/lib/washbullet/api/subscriptions.rb +17 -0
  14. data/lib/washbullet/{basic_authentication.rb → authorization.rb} +1 -1
  15. data/lib/washbullet/channel.rb +29 -0
  16. data/lib/washbullet/client.rb +18 -18
  17. data/lib/washbullet/contact.rb +35 -0
  18. data/lib/washbullet/device.rb +27 -0
  19. data/lib/washbullet/entity.rb +27 -0
  20. data/lib/washbullet/http_exception.rb +19 -14
  21. data/lib/washbullet/push.rb +27 -0
  22. data/lib/washbullet/pushable.rb +59 -0
  23. data/lib/washbullet/pushable/file.rb +55 -0
  24. data/lib/washbullet/pushable/link.rb +13 -0
  25. data/lib/washbullet/pushable/note.rb +13 -0
  26. data/lib/washbullet/request.rb +1 -1
  27. data/lib/washbullet/user.rb +9 -0
  28. data/lib/washbullet/version.rb +1 -1
  29. data/spec/fixtures/green.png +0 -0
  30. data/spec/spec_helper.rb +48 -68
  31. data/spec/vcr/Washbullet_API_Contacts/_contacts/Get_own_active_contacts.yml +48 -0
  32. data/spec/vcr/Washbullet_API_Devices/_devices/Get_own_active_devices.yml +50 -0
  33. data/spec/vcr/Washbullet_API_Me/_me/Get_the_self_information.yml +50 -0
  34. data/spec/vcr/Washbullet_API_Subscriptions/_channel_info/when_channel_is_existing/Get_information_about_a_channel.yml +49 -0
  35. data/spec/vcr/Washbullet_API_Subscriptions/_channel_info/when_channel_is_not_existing/raise_error.yml +49 -0
  36. data/spec/vcr/Washbullet_API_Subscriptions/_subscriptions/Get_list_subscriptions.yml +50 -0
  37. data/spec/vcr/Washbullet_Pushable_File/_push/.yml +170 -0
  38. data/spec/vcr/Washbullet_Pushable_Link/_push/.yml +52 -0
  39. data/spec/vcr/Washbullet_Pushable_Note/_push/.yml +51 -0
  40. data/spec/washbullet/api/contacts_spec.rb +15 -0
  41. data/spec/washbullet/api/devices_spec.rb +14 -0
  42. data/spec/washbullet/api/me_spec.rb +11 -0
  43. data/spec/washbullet/api/subscriptions_spec.rb +31 -0
  44. data/spec/washbullet/pushable/file_spec.rb +23 -0
  45. data/spec/washbullet/pushable/link_spec.rb +24 -0
  46. data/spec/washbullet/pushable/note_spec.rb +20 -0
  47. data/washbullet.gemspec +5 -1
  48. metadata +107 -29
  49. data/spec/fixtures/contacts.json +0 -16
  50. data/spec/fixtures/devices.json +0 -19
  51. data/spec/fixtures/push.json +0 -18
  52. data/spec/fixtures/pushes.json +0 -24
  53. data/spec/fixtures/upload_request.json +0 -14
  54. data/spec/fixtures/users.json +0 -31
  55. data/spec/washbullet/client_spec.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2cb3c774ded8d13781c34ebb0679f6f028aecd32
4
- data.tar.gz: 38d52e341ca5f16617249780224b0c12281befc5
3
+ metadata.gz: 04b00def53d0001c2857430d0125e2804e39c4cb
4
+ data.tar.gz: 18d2a8debae29e33f43d02e02b3668110cfe61f2
5
5
  SHA512:
6
- metadata.gz: 08844feca60a92007c068d504b1656d1e547e42aafdd3a1c1ac7c6e4f162e32404cbe8fdb205073228fe8358bb1f2caa6efa3dc67c61011600d445ea04a546f6
7
- data.tar.gz: 5e6b593a93445ef4c19f00f8e69b5bcefd42b0543af804ad4acbb24d0b5507e1e6fa113a20c3a24806af53ad88a1077ed97d4122b488adb643985695953e32cf
6
+ metadata.gz: e332376572793ddc8ed5f411f921d77c73bbfef5c40275d0ba653cdb266eee6cfaf26fe93bb7d7c5b08d43a951782f8f4a2929b9c011dc505d0c77450b270e5a
7
+ data.tar.gz: efc87efe004731cd662c6599652dc2e25bc798bd5106615b2fd55edb7cd19bc4b21b97d23b245ada80ccdf7d1db04eb40f57198767ed894f41e3dd7cdb3a269e
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .gems
7
+ .rbenv-gemsets
6
8
  Gemfile.lock
7
9
  InstalledFiles
8
10
  _yardoc
@@ -15,3 +17,4 @@ spec/reports
15
17
  test/tmp
16
18
  test/version_tmp
17
19
  tmp
20
+ .envrc
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
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
- #### Setup Client
15
+ ### Setup Client
14
16
 
15
17
  ```ruby
16
18
  client = Washbullet::Client.new('YOUR_API_KEY')
17
19
  ```
18
20
 
19
- #### Push to own device
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
- # Get own device list
30
- client.devices
31
-
32
- # note
33
- client.push_note(device_iden, 'Title of note', 'A note\'s content')
34
-
35
- # link
36
- client.push_link(device_iden, 'Title of link', 'https://www.pushbullet.com', 'This website is awesome.')
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
- # address
39
- client.push_address(device_iden, 'Name of address', 'Addrss of place')
40
+ ### Devices
40
41
 
41
- # list
42
- client.push_list(device_iden, 'Title of lists', [{text: 'Buy milk', checked: true}, {text: 'Buy Soy milk', checked: false}])
42
+ ```ruby
43
+ # Get own active devices
44
+ client.devices
45
+ ```
43
46
 
44
- # file
45
- client.push_file(device_iden, 'File name', 'path/to/file', 'An optional message')
47
+ ### Contacts
46
48
 
47
- # Get friend list of Pushbullet
49
+ ```ruby
50
+ # Get friends list
48
51
  client.contacts
52
+ ```
49
53
 
50
- # Get self info
54
+ ### Get self info
55
+
56
+ ```
51
57
  client.me
52
58
  ```
53
59
 
54
- ## TODO
55
-
56
- - push friend's device
57
- - test...
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
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,4 +1,9 @@
1
1
  require 'washbullet/client'
2
+ require 'washbullet/pushable'
3
+ require 'washbullet/channel'
4
+ require 'washbullet/contact'
5
+ require 'washbullet/device'
6
+ require 'washbullet/user'
2
7
 
3
8
  module Washbullet
4
9
  end
@@ -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 '/v2/contacts'
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(contact_iden)
9
- delete "/v2/contacts/#{contact_iden}"
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 '/v2/devices'
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(device_iden)
9
- delete "/v2/devices/#{device_iden}"
14
+ def delete_device
15
+ raise NotImplementedError
10
16
  end
11
17
  end
12
18
  end
@@ -2,7 +2,7 @@ module Washbullet
2
2
  module API
3
3
  module Me
4
4
  def me
5
- get '/v2/users/me'
5
+ User.new(get('/v2/users/me').body)
6
6
  end
7
7
  end
8
8
  end
@@ -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(device_iden, title, body)
5
- push :note, device_iden, title: title, body: body
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 push_list(device_iden, title, items)
17
- push :list, device_iden, title: title, items: items
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(device_iden, file_name, file_path, body)
21
- upload_file(file_name, file_path) do |data|
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 pushes(modified_after = nil, cursor = nil)
34
- params = {modified_after: modified_after, cursor: cursor}
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
- delete "/v2/pushes/#{push_iden}"
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
@@ -1,5 +1,5 @@
1
1
  module Washbullet
2
- class BasicAuthentication < Faraday::Request::BasicAuthentication
2
+ class Authorization < Faraday::Request::Authorization
3
3
  def call(env)
4
4
  if env.url.to_s.match(Washbullet::Client::ENDPOINT)
5
5
  env.request_headers[KEY] = @header_value
@@ -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
@@ -2,7 +2,7 @@ require 'faraday'
2
2
  require 'mime/types'
3
3
 
4
4
  require 'washbullet/api'
5
- require 'washbullet/basic_authentication'
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
- def middleware
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
- f.adapter :net_http
34
- end
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
- :builder => middleware,
40
- :headers => {
41
- :accept => 'application/json',
42
- :user_agent => "Washbullet Ruby Gem #{Washbullet::VERSION}",
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
- private
40
+ def middleware
41
+ @middleware ||= Faraday::RackBuilder.new do |f|
42
+ f.request :multipart
43
+ f.request :url_encoded
48
44
 
49
- def connection
50
- @connection ||= Faraday.new(ENDPOINT, connection_options)
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