Last active
August 29, 2015 13:56
-
-
Save coreyhaines/9183576 to your computer and use it in GitHub Desktop.
Isolate integration with Pubnub (from the Slottd.com codebase)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Isolating integration with Pubnub allowed me to swap origin in a central location. | |
# This seems like a trivial wrapping, almost not worth it at all. | |
# However, doing this allowed me to quickly fix a production issue associated with out-of-date gem's hard-coding of | |
# origin for request URL. | |
# Always worth abiding by the Eliminate Duplication (of knowledge) rule of simple design. In this case, knowledge of how | |
# to integrate with Pubnub. | |
module ManagesMessaging | |
class MessagePusher | |
def initialize(config = Config::Pubnub::Config) | |
@pusher = Pubnub.new(config[:pub_key], config[:sub_key], config[:secret], config[:ssl]) | |
# Current version of pubnub gem allows over-riding of origin through initializer. I'm not up-to-date, though. | |
# This quick fix stands in until I make time to update the gem and do my appropriate integration testing. | |
# Gotta love the freedom that Ruby gives you when you need it. | |
@pusher.instance_variable_set "@origin", "http://pubsub-napac.pubnub.com" | |
end | |
# Of course, there is a higher-level abstraction that wraps the knowledge of how to construct the message with | |
# the appropriate JSON format. Rest of system uses that abstraction. | |
def push_message(message) | |
@pusher.publish(message) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment