Class: PushbulletRuby::Pushable

Inherits:
Object
  • Object
show all
Defined in:
lib/pushbullet_ruby/pushable.rb,
lib/pushbullet_ruby/pushable/file.rb,
lib/pushbullet_ruby/pushable/link.rb,
lib/pushbullet_ruby/pushable/note.rb

Direct Known Subclasses

File, Link, Note

Defined Under Namespace

Classes: File, Link, MissingParameter, Note

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, receiver, identifier, params) ⇒ Pushable

Returns a new instance of Pushable.



13
14
15
16
17
18
# File 'lib/pushbullet_ruby/pushable.rb', line 13

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/pushbullet_ruby/pushable.rb', line 7

def client
  @client
end

#identifierObject (readonly)

Returns the value of attribute identifier.



7
8
9
# File 'lib/pushbullet_ruby/pushable.rb', line 7

def identifier
  @identifier
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/pushbullet_ruby/pushable.rb', line 7

def params
  @params
end

#receiverObject (readonly)

Returns the value of attribute receiver.



7
8
9
# File 'lib/pushbullet_ruby/pushable.rb', line 7

def receiver
  @receiver
end

Class Method Details

.push(client, receiver, identifier, params) ⇒ Object



9
10
11
# File 'lib/pushbullet_ruby/pushable.rb', line 9

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

Instance Method Details

#pushObject

Raises:



20
21
22
23
24
25
26
# File 'lib/pushbullet_ruby/pushable.rb', line 20

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

#receiver_typeObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/pushbullet_ruby/pushable.rb', line 36

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

#specify_receiver(payload) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/pushbullet_ruby/pushable.rb', line 28

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