Sha256: ad51aa705f14405590ce4a7525587201d0f77bca1fc2e8890ea67b0b52b58cda

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

require 'pushbullet_ruby/push'

module PushbulletRuby
  class Pushable
    class MissingParameter < StandardError; end

    attr_reader :client, :receiver, :identifier, :params

    def self.push(client, receiver, identifier, params)
      Push.new(new(client, receiver, identifier, params).push.body)
    end

    def initialize(client, receiver, identifier, params)
      @client = client
      @receiver = receiver
      @identifier = identifier
      @params = params
    end

    def push
      raise MissingParameter unless required_parameters.all? { |e| params.keys.include?(e) }

      payload = params.merge(type: type)
      payload = specify_receiver(payload)
      client.post('/v2/pushes', payload)
    end

    def specify_receiver(payload)
      if receiver && identifier
        payload.merge(receiver_type => identifier)
      else
        payload
      end
    end

    def receiver_type
      case receiver
        when :device then :device_iden
        when :email then receiver
        when :channel then :channel_tag
        when :client then :client_iden
        else
          raise NotImplementedError
      end
    end
  end
end

Version data entries

14 entries across 13 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/pushbullet_ruby-1.1.4/lib/pushbullet_ruby/pushable.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/pushbullet_ruby-1.1.4/lib/pushbullet_ruby/pushable.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/pushbullet_ruby-1.1.4/lib/pushbullet_ruby/pushable.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/pushbullet_ruby-1.1.4/lib/pushbullet_ruby/pushable.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/pushbullet_ruby-1.1.4/lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.1.4 lib/pushbullet_ruby/pushable.rb
tdiary-5.0.8 vendor/bundle/gems/pushbullet_ruby-1.1.3/lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.1.3 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.1.2 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.1.1 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.1.0 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.0.4.1 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.0.4 lib/pushbullet_ruby/pushable.rb
pushbullet_ruby-1.0.3 lib/pushbullet_ruby/pushable.rb