Sha256: eca9080d52112fa656eaa77265b2a037f07a9e9cecd7a7917498a3812e709ae4

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'faraday'
require 'mime/types'

require 'washbullet/api'
require 'washbullet/basic_authentication'
require 'washbullet/http_exception'
require 'washbullet/parse_json'
require 'washbullet/request'
require 'washbullet/version'

module Washbullet
  class Client
    include Request
    include API

    ENDPOINT = 'https://api.pushbullet.com'

    attr_reader :api_key

    def initialize(api_key)
      @api_key = api_key
    end

    def middleware
      @middleware ||= Faraday::RackBuilder.new do |f|
        f.request :multipart
        f.request :url_encoded

        f.use Washbullet::BasicAuthentication, @api_key, ''
        f.use Washbullet::ParseJSON
        f.use Washbullet::HttpException

        f.adapter :net_http
      end
    end

    def connection_options
      @connection_options ||= {
        :builder => middleware,
        :headers => {
          :accept     => 'application/json',
          :user_agent => "Washbullet Ruby Gem #{Washbullet::VERSION}",
        }
      }
    end

    private

    def connection
      @connection ||= Faraday.new(ENDPOINT, connection_options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
washbullet-0.3.1 lib/washbullet/client.rb