class Pushbullet::Client

Constants

API_VERSION
END_POINT

Public Instance Methods

delete(path, params = {}) click to toggle source
# File lib/pushbullet/client.rb, line 20
def delete(path, params = {})
  JSON.parse(generic_request(path).delete params, &handle_error)
end
generic_request(path) click to toggle source
# File lib/pushbullet/client.rb, line 24
def generic_request(path)
  RestClient::Resource.new("#{END_POINT}#{path}", Pushbullet.api_token, '')
end
get(path) click to toggle source
# File lib/pushbullet/client.rb, line 8
def get(path)
  JSON.parse(generic_request(path).get(&handle_error))
end
post(path, params = {}) click to toggle source
# File lib/pushbullet/client.rb, line 12
def post(path, params = {})
  JSON.parse(generic_request(path).post params, &handle_error)
end
put(path, params = {}) click to toggle source
# File lib/pushbullet/client.rb, line 16
def put(path, params = {})
  JSON.parse(generic_request(path).put params, &handle_error)
end

Private Instance Methods

handle_error() click to toggle source
# File lib/pushbullet/client.rb, line 30
def handle_error
  proc do |response, request, result, &block|
    if response.code >= 400 && response.code <= 500
      fail Pushbullet::Error, JSON.parse(response)['error']['message']
    else
      response.return!(request, result, &block)
    end
  end
end