pushofy 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/pushofy/payload.rb +60 -0
 - data/lib/pushofy/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4a84db1ba394a0ad2062cab8812a05971c4a7f18
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8b3471d5e69459c35cf4c2bab20981b8b7554bd1
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9b21bd61079fa1d05c07ba287d3c2c95f5f225208bcc33f2b13dcc4f86b12711db415b99355b156cc405a1fc4d5b32c20109ae0fd65f98ac440aff600d1b7969
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c714af6c0ba1fe609d7a81b875d1f6b76b608c5805427421e737ee0cde2e59e47ae120594e0a761362234852151b21b9b9696a0ddf35e2ecb805509009ec8ffd
         
     | 
    
        data/lib/pushofy/payload.rb
    CHANGED
    
    | 
         @@ -1,4 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'socket'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'applepayload'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'ssl_helper'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'openssl'
         
     | 
| 
       1 
6 
     | 
    
         
             
            module Pushofy
         
     | 
| 
       2 
7 
     | 
    
         
             
              class Payload
         
     | 
| 
      
 8 
     | 
    
         
            +
                def initialize(args = {})
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @id = args[:id]
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @message = args[:message]
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @app = args[:app]
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @from = args[:from]
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def send_push
         
     | 
| 
      
 18 
     | 
    
         
            +
                  device = Device.find(@id)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  device_type = device.device_type
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if device_type == 'IOS'
         
     | 
| 
      
 21 
     | 
    
         
            +
                    send_to_ios(device)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  elsif device_type == 'Android'
         
     | 
| 
      
 23 
     | 
    
         
            +
                    send_to_android(device)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def send_to_ios(device)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  payload_hash = {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    aps: {
         
     | 
| 
      
 32 
     | 
    
         
            +
                      alert: {
         
     | 
| 
      
 33 
     | 
    
         
            +
                        body: "You have a new #{@app}, form #{@from}"
         
     | 
| 
      
 34 
     | 
    
         
            +
                      },
         
     | 
| 
      
 35 
     | 
    
         
            +
                      sound: 'default',
         
     | 
| 
      
 36 
     | 
    
         
            +
                      badge: 1,
         
     | 
| 
      
 37 
     | 
    
         
            +
                    },
         
     | 
| 
      
 38 
     | 
    
         
            +
                    app: @app,
         
     | 
| 
      
 39 
     | 
    
         
            +
                    url: @message
         
     | 
| 
      
 40 
     | 
    
         
            +
                  }
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                  ApplePush.new(payload_hash, device_token_hex).push
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                def send_to_android(device)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  body = {}
         
     | 
| 
      
 47 
     | 
    
         
            +
                  arr = []
         
     | 
| 
      
 48 
     | 
    
         
            +
                  arr << device.registration_id
         
     | 
| 
      
 49 
     | 
    
         
            +
                  body['registration_ids'] = arr
         
     | 
| 
      
 50 
     | 
    
         
            +
                  # body['collapse_key'] = 'Updates Available'
         
     | 
| 
      
 51 
     | 
    
         
            +
                  #    body['registration_ids'] = registration_ids
         
     | 
| 
      
 52 
     | 
    
         
            +
                  #    body['data'] = 'Hi this is my first push message'
         
     | 
| 
      
 53 
     | 
    
         
            +
                  #    body['delay_while_idle'] = # true or false
         
     | 
| 
      
 54 
     | 
    
         
            +
                  #    body['time_to_live'] = # number in seconds
         
     | 
| 
      
 55 
     | 
    
         
            +
                  android_payload = { 'message' =>  "You have a new #{app} from #{from}" }
         
     | 
| 
      
 56 
     | 
    
         
            +
                  android_payload['app'] = @app
         
     | 
| 
      
 57 
     | 
    
         
            +
                  android_payload['url'] = @message
         
     | 
| 
      
 58 
     | 
    
         
            +
                  body['data'] = android_payload
         
     | 
| 
      
 59 
     | 
    
         
            +
                  a = AndroidPush.new
         
     | 
| 
      
 60 
     | 
    
         
            +
                  a.push(body)
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
       3 
62 
     | 
    
         
             
              end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       4 
64 
     | 
    
         
             
            end
         
     | 
    
        data/lib/pushofy/version.rb
    CHANGED