[RFC] add APNS class and PushNotification interface

Review Request #11 — Created Nov. 5, 2012 and discarded

olivier
Lunr
personal/olivier/apns
7310
lunr
APNS class implemented with PushNotification interface

No test made, just as RFC


  • 12
  • 0
  • 12
  • 0
  • 24
Description From Last Updated
what's the penalty if we don't do this? pprkut pprkut
I wonder if we can come up with a better name :) pprkut pprkut
IMHO this is the wrong way. We're not really interested in the message here, but rather the the response code. ... pprkut pprkut
no pass by reference anymore pprkut pprkut
style pprkut pprkut
mktime() without parameters throws a E_STRICT error according to the docs. Use time() instead. pprkut pprkut
styling pprkut pprkut
what's the exact purpose of this? What does the user of this library get from defining his own process id? pprkut pprkut
IMHO this is of no use to anyone. The only point of this would be for logging, and in that ... pprkut pprkut
this starts an awefully pointless chain of function calls. I do se the point of structuring it, but I'm not ... pprkut pprkut
styling pprkut pprkut
this is a log message, not a result. pprkut pprkut
olivier
pprkut
  1. 
      
  2. Move from constructor to dedicated methods using fluid interface
  3. can probably split up as well into
    - push()
    - set_destination()
    - set_payload()
  4. system/libraries/network/notifications/class.apns.inc.php (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    I think this should be part of the payload generation, not the push transport
  5. system/libraries/network/notifications/class.apns.inc.php (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    early exit
  6. system/libraries/network/notifications/class.apns.inc.php (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    early exit
  7. 
      
olivier
olivier
olivier
Felipe
  1. Ship It!
  2. 
      
pprkut
  1. 
      
  2. system/libraries/network/notifications/class.apns.inc.php (Diff revision 3)
     
     
     
     
     
     
    what is this? characters? bytes? lines?
    1. This is the length in byte of the returned message.
    2. Ok, this is not obvious from the comment. Please clarify that in the code.
  3. you probably want to do this by reference
    1. The idea was to provide to the APNS class a string, in the way it is made now,
      it even has the payloao length packed with.
    2. sure, and? What's that got to do with passing by reference or not?
  4. system/libraries/network/notifications/class.apns.inc.php (Diff revision 3)
     
     
     
     
     
     
     
    what's the penalty if we don't do this?
    1. The message will not be sent cause the token doesn't match the criterias.
    2. which will produce an error that the user later can check for, rather than eating it silently, right?
    3. See the push method, it sets an error message when there is no destination to push to.
      
      If you provide a token with invalid size, APNS will answer that the payload has an invalid size
      which is not more convenient than refusing the token and then returning error while trying to push.
      
      
      public function push()
          {
              if($this->device_token === NULL)
              {
                  $this->result = 'No destination provided.';
                  $this->response_code = '-1';
                  return FALSE;
              }
              $data = $this->push_header.$token.$payload;
      
              $write = $this->stream_socket_client->write($data);
      
              return $this->parse_result($write) ;
          }
    4. I like better Olivier idea here, but I would make the error something like: "Invalid or no destination provided" since it can be both.
      We could also set $this->device_token to FALSE when it's invalid and NULL when it's not set, so we can differentiate both cases and provide a better error message
    5. My point is that we need to have the post error handling anyway. If we want pre error handling we need to write extra code for something that's already handled in the post checks.
      The only downside I can see be doing the check post pushing is that a failed push somehow still counts for the quota (of there is one).
    6. But with the post error handling you don't know if the destination was invalid or the message, there is no way to provide meaningful errors after pushing
    7. The whole point of this rewrite was that we /can/ do that.
      If you see the return value constants at the beginning you see one that says:
      
      The APNS status code 5, Invalid token size.
    8. If I didn't understand Olivier wrong, he can't determine if the error was 5, 6 or 7 after pushing, he gets the same error with the three of them, so he needs to check for this upfront.
    9. I doubt that. What I can imagine is that if all three of them or any combination of two of them happen, one takes precedence over the others. That's fine though and common practice.
    10. I propose this then:
      
          public function push()
          {
              if($this->device_token === NULL)
              {
                  $this->result = 'Invalid token size.';
                  $this->response_code = '5';
                  return FALSE;
              }
              $data = $this->push_header.$token.$payload;
      
              $write = $this->stream_socket_client->write($data);
      
              return $this->parse_result($write) ;
          }
    11. Quoting olivier: If you provide a token with invalid size, APNS will answer that the payload has an invalid size
      Which means that you can't know if the payload, the token, or the topic had an invalid size without the pre checks. Also if a wrong push request affects the quota, I would like to prevent those.
    12. Fair enough, so why didn't olivier answer that /here/ in the first place....
      Anyway, if that is the behaviour from APNS, then we need unit tests checking that behaviour and making sure our work-arounds are functional.
      Otherwise someone (read: me) may come along in a year or so, see unnecessary code and remove it.
    13. Maybe his explanation was not detailed enough, I got it just with that sentence I quoted before... (Ok, and the cigarette we just smoked :P)
    14. Argh, silly me, I must have overread this statement before. My point with the unit tests remains though
  5. system/libraries/network/notifications/class.apns.inc.php (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Please use existing terminology and move it into a __get() method
    1. It is part of the interace
    2. The Push Notification Interface? Hmm, ok, in that case it's fine.
  6. There's gotta be a more reasonable name for this...
    1. name changed to $push_written
    2. still weird. I'd use "push_sent".
    3. Will be done so
  7. system/libraries/network/notifications/class.apns.inc.php (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
     
     
     
    So we really need a separate method for this?
  8. nitpick. I'd prefer endpoint over destination
    1. method renamed to set_endpoint, interface updated as well
  9. 
      
olivier
Felipe
  1. Looks good to me, I'd say go for the unit-tests
  2. 
      
olivier
pprkut
  1. Make sure your code complies with the latest coding standard
  2. src/Lunr/Network/Notifications/Apns.php (Diff revision 5)
     
     
    I thought about this and I think it's better to move push notifications out of Network into a new namespace.
    1. A good idea by itself, I think the namespace Push is good enough...
      Just let me know
      
  3. 
      
Felipe
  1. Looks good to me
    
  2. 
      
olivier
pprkut
  1. 
      
  2. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
    I wonder if we can come up with a better name :)
    1. PubSub could be a generic naming and it is also a design pattern :)
      IMHO from the point that we are pushing notifications it matches, even if we push to a specific device (subscribed) or broadcasting to all connected.
  3. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
     
     
     
    IMHO this is the wrong way. We're not really interested in the message here, but rather the the response code. Think outside the class: If you call push and to a check on the return value, the code is much easier to read if you have
    
    if ($error_number = APNS_NO_ERROR)
    
    rather than
    
    if ($error_number = 0)
  4. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
    no pass by reference anymore
  5. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
     
     
     
  6. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
    mktime() without parameters throws a E_STRICT error according to the docs. Use time() instead.
  7. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
     
    styling
  8. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    what's the exact purpose of this? What does the user of this library get from defining his own process id?
  9. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
     
     
     
     
     
     
     
    IMHO this is of no use to anyone. The only point of this would be for logging, and in that case you can do that here directly.
  10. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
    this starts an awefully pointless chain of function calls. I do se the point of structuring it, but I'm not a big fan of creating functions for the sake of creating functions.
  11. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
    styling
  12. src/Lunr/Push/Apns.php (Diff revision 6)
     
     
     
    this is a log message, not a result.
  13. 
      
olivier
Review request changed

Status: Discarded

Loading...