lib/washbullet/api/pushes.rb in washbullet-0.3.1 vs lib/washbullet/api/pushes.rb in washbullet-0.4.0

- old
+ new

@@ -1,71 +1,30 @@ +require 'washbullet/pushable' +require 'washbullet/pushable/file' +require 'washbullet/pushable/link' +require 'washbullet/pushable/note' + module Washbullet module API module Pushes - def push_note(device_iden, title, body) - push :note, device_iden, title: title, body: body + def push_note(receiver: nil, identifier: nil, params: {}) + Washbullet::Pushable::Note.push(self, receiver, identifier, params) end - def push_link(device_iden, title, url, body) - push :link, device_iden, title: title, url: url, body: body + def push_link(receiver: nil, identifier: nil, params: {}) + Washbullet::Pushable::Link.push(self, receiver, identifier, params) end - def push_address(device_iden, name, address) - push :address, device_iden, name: name, address: address + def push_file(receiver: nil, identifier: nil, params: {}) + Washbullet::Pushable::File.push(self, receiver, identifier, params) end - def push_list(device_iden, title, items) - push :list, device_iden, title: title, items: items + def get_pushes(modified_after = nil, cursor = nil) + raise NotImplementedError end - def push_file(device_iden, file_name, file_path, body) - upload_file(file_name, file_path) do |data| - payload = { - file_name: data['file_name'], - file_type: data['file_type'], - file_url: data['file_url'], - body: body - } - - push :file, device_iden, payload - end - end - - def pushes(modified_after = nil, cursor = nil) - params = {modified_after: modified_after, cursor: cursor} - - params = params.values.all?(&:nil?) ? {} : params - - get 'v2/pushes', params - end - def delete_push(push_iden) - delete "/v2/pushes/#{push_iden}" - end - - private - - def upload_file(file_name, file_path, &block) - mime_type = MIME::Types.type_for(file_path).first.to_s - - data = upload_request(file_name, mime_type) - - upload_url = data.body['upload_url'] - payload = data.body['data'] - - io = Faraday::UploadIO.new(file_path, mime_type) - - post upload_url, payload.merge(file: io) - - yield data.body - end - - def upload_request(file_name, mime_type) - get '/v2/upload-request', file_name: file_name, file_type: mime_type - end - - def push(type, device_iden, payload) - post '/v2/pushes', payload.merge(device_iden: device_iden, type: type) + raise NotImplementedError end end end end