Class: Washbullet::Pushable

Inherits:
Object
  • Object
show all
Defined in:
lib/washbullet/pushable.rb,
lib/washbullet/pushable/file.rb,
lib/washbullet/pushable/link.rb,
lib/washbullet/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.



15
16
17
18
19
20
# File 'lib/washbullet/pushable.rb', line 15

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/washbullet/pushable.rb', line 7

def client
  @client
end

#identifierObject (readonly)

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#receiverObject (readonly)

Returns the value of attribute receiver.



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

def receiver
  @receiver
end

Class Method Details

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



9
10
11
12
13
# File 'lib/washbullet/pushable.rb', line 9

def self.push(client, receiver, identifier, params)
  response = new(client, receiver, identifier, params).push

  Push.new(response.body)
end

Instance Method Details

#pushObject

Raises:



22
23
24
25
26
27
28
29
30
# File 'lib/washbullet/pushable.rb', line 22

def push
  raise MissingParameter unless params.keys == required_parameters

  payload = params.merge(type: type)

  payload = specify_receiver(payload)

  client.post('/v2/pushes', payload)
end

#receiver_typeObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/washbullet/pushable.rb', line 48

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

#required_parametersObject

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/washbullet/pushable.rb', line 36

def required_parameters
  raise NotImplementedError
end

#specify_receiver(payload) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/washbullet/pushable.rb', line 40

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

#typeObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/washbullet/pushable.rb', line 32

def type
  raise NotImplementedError
end