Class: Rhoconnect::RhoconnectPush
- Inherits:
-
Object
- Object
- Rhoconnect::RhoconnectPush
- Defined in:
- lib/rhoconnect/ping/rhoconnect_push.rb
Defined Under Namespace
Classes: InvalidPushRequest, InvalidPushServer
Class Method Summary collapse
- .ping(params) ⇒ Object
-
.push_message(params) ⇒ Object
Generates push package.
Class Method Details
.ping(params) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rhoconnect/ping/rhoconnect_push.rb', line 8 def self.ping(params) begin settings = get_config(Rhoconnect.base_directory)[Rhoconnect.environment] if settings and settings[:push_server] server = URI.join(settings[:push_server], "/messageQueue/#{params['device_pin']}") RestClient.post( server.to_s,self.(params),:content_type => :json ) do |response, request, result, &block| case response.code when 200, 204 response.return!(request, result, &block) when 400 raise InvalidPushRequest.new("Invalid push request.") end end else raise InvalidPushServer.new("Missing or invalid `:push_server` in settings/settings.yml.") end rescue Exception => error log "RhoConnect Push Error: #{error}" log error.backtrace.join("\n") raise error end end |
.push_message(params) ⇒ Object
Generates push package
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rhoconnect/ping/rhoconnect_push.rb', line 34 def self.(params) data = {} data['collapseId'] = params['badge'].to_i if params['badge'] data['data'] = {} data['data']['alert'] = params['message'] if params['message'] data['data']['sound'] = params['sound'] if params['sound'] data['data']['vibrate'] = params['vibrate'] if params['vibrate'] data['data']['do_sync'] = params['sources'] if params['sources'] data.to_json end |