Sha256: fc501d6e47a63b45d2b3e7629231fd73c96a066c3493977bc7a95b3c29c3836c

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'faraday'
require 'mime/types'

require 'pushbullet_ruby/api'
require 'pushbullet_ruby/request'
require 'pushbullet_ruby/authorization'
require 'pushbullet_ruby/parse_json'
require 'pushbullet_ruby/http_exeption'

module PushbulletRuby
  class Client
    include Request
    include API

    attr_reader :key

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

    def initialize(key)
      @key = key
    end

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

    def connection_options
      @connection_options ||= {
          builder: middleware,
          headers: {
              accept: 'application/json',
              user_agent: 'Pushbullet Gem'
          },
          ssl: {
              verify: false
          }
      }
    end

    def middleware
      @middleware ||= Faraday::RackBuilder.new do |f|
        f.request :multipart
        f.request :url_encoded
        f.use PushbulletRuby::Authorization, 'Bearer', key
        f.use PushbulletRuby::ParseJSON
        f.use PushbulletRuby::HttpException
        f.adapter :net_http
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pushbullet_ruby-1.0.2.1 lib/pushbullet_ruby/client.rb
pushbullet_ruby-1.0.2 lib/pushbullet_ruby/client.rb
pushbullet_ruby-1.0.1 lib/pushbullet_ruby/client.rb