Class: PushbulletRuby::Pushable
- Inherits:
-
Object
- Object
- PushbulletRuby::Pushable
- 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
Defined Under Namespace
Classes: File, Link, MissingParameter, Note
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, receiver, identifier, params) ⇒ Pushable
constructor
A new instance of Pushable.
- #push ⇒ Object
- #receiver_type ⇒ Object
- #specify_receiver(payload) ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/pushbullet_ruby/pushable.rb', line 7 def client @client end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
7 8 9 |
# File 'lib/pushbullet_ruby/pushable.rb', line 7 def identifier @identifier end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/pushbullet_ruby/pushable.rb', line 7 def params @params end |
#receiver ⇒ Object (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
Instance Method Details
#push ⇒ Object
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_type ⇒ Object
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 |