Class: CloudFivePush::Message
- Inherits:
-
Object
- Object
- CloudFivePush::Message
- Includes:
- HTTParty
- Defined in:
- lib/cloud_five_push/message.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#broadcast ⇒ Object
Returns the value of attribute broadcast.
-
#message ⇒ Object
Returns the value of attribute message.
-
#scheduled_at ⇒ Object
Returns the value of attribute scheduled_at.
-
#user_identifiers ⇒ Object
Returns the value of attribute user_identifiers.
Instance Method Summary collapse
-
#initialize(api_key = nil) ⇒ Message
constructor
debug_output $stderr.
- #send! ⇒ Object
Constructor Details
#initialize(api_key = nil) ⇒ Message
debug_output $stderr
10 11 12 13 14 15 16 17 |
# File 'lib/cloud_five_push/message.rb', line 10 def initialize(api_key=nil) @api_key = api_key || CloudFivePush.api_key if @api_key.nil? raise "api_key is required (or set CloudFivePush.api_key)" end @broadcast = false @user_identifiers = [] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def api_key @api_key end |
#badge ⇒ Object
Returns the value of attribute badge.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def badge @badge end |
#broadcast ⇒ Object
Returns the value of attribute broadcast.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def broadcast @broadcast end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def @message end |
#scheduled_at ⇒ Object
Returns the value of attribute scheduled_at.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def scheduled_at @scheduled_at end |
#user_identifiers ⇒ Object
Returns the value of attribute user_identifiers.
4 5 6 |
# File 'lib/cloud_five_push/message.rb', line 4 def user_identifiers @user_identifiers end |
Instance Method Details
#send! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cloud_five_push/message.rb', line 19 def send! if blank_param?(@user_identifiers) && (@broadcast == false) raise "Please set user_identifiers or set broadcast=true" end if blank_param?(@message) && blank_param?(@badge) raise "Please set message or badge" end params = { api_key: @api_key, alert: @message, badge: @badge } if @scheduled_at params[:when] = @scheduled_at.iso8601 end if @broadcast params[:audience] = "broadcast" else params[:user_identifiers] = @user_identifiers end self.class.post('/push/notify', body: params) end |