Sha256: 0de1a7d7f8a496a3511974f1d6532c8fd7c58253cbfde4550bf911de901d2db0

Contents?: true

Size: 995 Bytes

Versions: 6

Compression:

Stored size: 995 Bytes

Contents

module Pushbullet
  class Client
    require 'rest_client'

    API_VERSION = 2
    END_POINT =  "https://api.pushbullet.com/v#{API_VERSION}/"

    def get(path)
      JSON.parse(generic_request(path).get(&handle_error))
    end

    def post(path, params = {})
      JSON.parse(generic_request(path).post params, &handle_error)
    end

    def put(path, params = {})
      JSON.parse(generic_request(path).put params, &handle_error)
    end

    def delete(path, params = {})
      JSON.parse(generic_request(path).delete params, &handle_error)
    end

    def generic_request(path)
      RestClient::Resource.new("#{END_POINT}#{path}", Pushbullet.api_token, '')
    end

    private

    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
  end
end

Version data entries

6 entries across 4 versions & 2 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/ruby-pushbullet-0.1.4/lib/pushbullet/client.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/ruby-pushbullet-0.1.4/lib/pushbullet/client.rb
tdiary-5.0.4 vendor/bundle/gems/ruby-pushbullet-0.1.4/lib/pushbullet/client.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/ruby-pushbullet-0.1.4/lib/pushbullet/client.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/ruby-pushbullet-0.1.4/lib/pushbullet/client.rb
ruby-pushbullet-0.1.4 lib/pushbullet/client.rb