live_resource-pubnub 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/lib/live_resource/pubnub/pubnub_protocol.rb +37 -0
- data/lib/live_resource/pubnub/version.rb +5 -0
- data/lib/live_resource/pubnub.rb +8 -0
- data/live_resource-pubnub.gemspec +26 -0
- data/spec/live_resource/pubnub/pubnub_protocol_spec.rb +81 -0
- data/spec/live_resource/pubnub_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +133 -0
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2013 Will Madden
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            MIT License
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining
         | 
| 6 | 
            +
            a copy of this software and associated documentation files (the
         | 
| 7 | 
            +
            "Software"), to deal in the Software without restriction, including
         | 
| 8 | 
            +
            without limitation the rights to use, copy, modify, merge, publish,
         | 
| 9 | 
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         | 
| 10 | 
            +
            permit persons to whom the Software is furnished to do so, subject to
         | 
| 11 | 
            +
            the following conditions:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            The above copyright notice and this permission notice shall be
         | 
| 14 | 
            +
            included in all copies or substantial portions of the Software.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         | 
| 17 | 
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         | 
| 18 | 
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         | 
| 19 | 
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         | 
| 20 | 
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         | 
| 21 | 
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         | 
| 22 | 
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            # LiveResource::Pubnub
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Provides LiveResource integration with Pubnub.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'live_resource-pubnub'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install live_resource-pubnub
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Instantiate and supply a PubnubProtocol to the LiveResource::Builder.
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Rails
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            (Requires [live_resource-rails](http://github.com/live-resource/rails)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ```ruby
         | 
| 28 | 
            +
            # application.rb
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ...
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            config.live_resource[:protocol] = LiveResource::Pubnub::PubnubProtocol.new(
         | 
| 33 | 
            +
              Pubnub.new(
         | 
| 34 | 
            +
                publish_key:   Education::Application.config.pubnub[:publish_key],
         | 
| 35 | 
            +
                subscribe_key: Education::Application.config.pubnub[:subscribe_key],
         | 
| 36 | 
            +
                secret_key:    Education::Application.config.pubnub[:secret_key],
         | 
| 37 | 
            +
                cipher_key:    Education::Application.config.pubnub[:cipher_key],
         | 
| 38 | 
            +
                ssl:           false
         | 
| 39 | 
            +
              ))
         | 
| 40 | 
            +
            ```
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            ## Contributing
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            1. Fork it
         | 
| 45 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 46 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 47 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 48 | 
            +
            5. Create new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require 'live_resource/protocol'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module LiveResource
         | 
| 4 | 
            +
              module Pubnub
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                class PubnubProtocol
         | 
| 7 | 
            +
                  include LiveResource::Protocol
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def initialize(pubnub)
         | 
| 10 | 
            +
                    @pubnub = pubnub
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def publish_message(resource_identifier, type, params = nil)
         | 
| 14 | 
            +
                    params     ||= {}
         | 
| 15 | 
            +
                    channel_id = channel_for(resource_identifier)
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                    message = params.merge(
         | 
| 18 | 
            +
                        :type           => type,
         | 
| 19 | 
            +
                        :':resource_id' => resource_identifier,
         | 
| 20 | 
            +
                    )
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    @pubnub.publish(
         | 
| 23 | 
            +
                        params.merge(
         | 
| 24 | 
            +
                            :channel  => channel_id,
         | 
| 25 | 
            +
                            :message  => message,
         | 
| 26 | 
            +
                            :callback => ->(x) {}
         | 
| 27 | 
            +
                        ))
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def channel_for(resource_id)
         | 
| 31 | 
            +
                    resource_id
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'live_resource/pubnub/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "live_resource-pubnub"
         | 
| 8 | 
            +
              spec.version       = LiveResource::Pubnub::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Will Madden"]
         | 
| 10 | 
            +
              spec.email         = ["will@letsgeddit.com"]
         | 
| 11 | 
            +
              spec.description   = %q{Provides LiveResource integration with Pubnub.}
         | 
| 12 | 
            +
              spec.summary       = %q{Provides LiveResource integration with Pubnub.}
         | 
| 13 | 
            +
              spec.homepage      = ""
         | 
| 14 | 
            +
              spec.license       = "MIT"
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              spec.files         = `git ls-files`.split($/)
         | 
| 17 | 
            +
              spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
         | 
| 18 | 
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 | 
            +
              spec.require_paths = ["lib"]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              spec.add_dependency 'live_resource'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              spec.add_development_dependency "bundler", "~> 1.3"
         | 
| 24 | 
            +
              spec.add_development_dependency "rake"
         | 
| 25 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,81 @@ | |
| 1 | 
            +
            require "spec_helper"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            include LiveResource::Pubnub
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe PubnubProtocol do
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              it 'should include the Protocol module' do
         | 
| 8 | 
            +
                expect(PubnubProtocol).to include(LiveResource::Protocol)
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              let(:pubnub_protocol) { PubnubProtocol.new(pubnub) }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              let(:pubnub) { double('Pubnub', publish: nil) }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              describe "#publish_message" do
         | 
| 16 | 
            +
                subject { pubnub_protocol.publish_message(resource_id, message_type, params) }
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                let(:resource_id) { :some_resource }
         | 
| 19 | 
            +
                let(:message_type) { 'resource:reset' }
         | 
| 20 | 
            +
                let(:params) {}
         | 
| 21 | 
            +
                let(:channel) { 'hashed-channel-ID' }
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                before do
         | 
| 24 | 
            +
                  pubnub_protocol.stub(channel_for: channel)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it 'should get the channel ID for the resource' do
         | 
| 28 | 
            +
                  pubnub_protocol.should_receive(:channel_for).with(resource_id)
         | 
| 29 | 
            +
                  subject
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it 'should publish a message to pubnub' do
         | 
| 33 | 
            +
                  pubnub.should_receive(:publish)
         | 
| 34 | 
            +
                  subject
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                describe 'the message' do
         | 
| 38 | 
            +
                  subject { pubnub_message }
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  let(:pubnub_message) { @pubnub_argument[:message] }
         | 
| 41 | 
            +
                  let(:pubnub_channel) { @pubnub_argument[:channel] }
         | 
| 42 | 
            +
                  let(:pubnub_callback) { @pubnub_argument[:callback] }
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  before do
         | 
| 45 | 
            +
                    _arg = nil
         | 
| 46 | 
            +
                    pubnub.stub(:publish) { |arg| _arg = arg }
         | 
| 47 | 
            +
                    pubnub_protocol.publish_message(resource_id, message_type, params)
         | 
| 48 | 
            +
                    @pubnub_argument = _arg
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  it 'should be published on the channel for the resource' do
         | 
| 52 | 
            +
                    expect(channel).to be(channel)
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  it 'should supply a callback' do
         | 
| 56 | 
            +
                    expect(pubnub_callback).to_not be_nil
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  its([:type]) { should == message_type }
         | 
| 60 | 
            +
                  its([:':resource_id']) { should == resource_id }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  context 'when some params are given' do
         | 
| 63 | 
            +
                    let(:params) { { a: 'b', c: 1, d: true } }
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    its([:a]) { should == 'b' }
         | 
| 66 | 
            +
                    its([:c]) { should == 1 }
         | 
| 67 | 
            +
                    its([:d]) { should == true }
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              describe "#channel_for" do
         | 
| 73 | 
            +
                subject { pubnub_protocol.channel_for(resource_id) }
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                let(:resource_id) { '/a/b/c' }
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                it 'should return the channel ID to use to publish messages for the given resource' do
         | 
| 78 | 
            +
                  expect(subject).to eq resource_id
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,12 @@ | |
| 1 | 
            +
            $:.unshift File.expand_path('../../lib', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            def require_tree(path)
         | 
| 4 | 
            +
              path = File.expand_path(path, File.dirname(__FILE__))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              files = Dir.glob(File.join(path, '**/*.rb'))
         | 
| 7 | 
            +
              raise "Directory '#{path}' is empty" unless files.length > 0
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              files.each { |file| puts "  require #{file}"; require file }
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            require_tree '../lib'
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,133 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: live_resource-pubnub
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Will Madden
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2013-05-08 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies:
         | 
| 14 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 15 | 
            +
              name: live_resource
         | 
| 16 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            +
                none: false
         | 
| 18 | 
            +
                requirements:
         | 
| 19 | 
            +
                - - ! '>='
         | 
| 20 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 21 | 
            +
                    version: '0'
         | 
| 22 | 
            +
              type: :runtime
         | 
| 23 | 
            +
              prerelease: false
         | 
| 24 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            +
                none: false
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - ! '>='
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '0'
         | 
| 30 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 31 | 
            +
              name: bundler
         | 
| 32 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            +
                none: false
         | 
| 34 | 
            +
                requirements:
         | 
| 35 | 
            +
                - - ~>
         | 
| 36 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 37 | 
            +
                    version: '1.3'
         | 
| 38 | 
            +
              type: :development
         | 
| 39 | 
            +
              prerelease: false
         | 
| 40 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            +
                none: false
         | 
| 42 | 
            +
                requirements:
         | 
| 43 | 
            +
                - - ~>
         | 
| 44 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 45 | 
            +
                    version: '1.3'
         | 
| 46 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 47 | 
            +
              name: rake
         | 
| 48 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            +
                none: false
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - ! '>='
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '0'
         | 
| 54 | 
            +
              type: :development
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                none: false
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ! '>='
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 63 | 
            +
              name: rspec
         | 
| 64 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                none: false
         | 
| 66 | 
            +
                requirements:
         | 
| 67 | 
            +
                - - ! '>='
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: '0'
         | 
| 70 | 
            +
              type: :development
         | 
| 71 | 
            +
              prerelease: false
         | 
| 72 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            +
                none: false
         | 
| 74 | 
            +
                requirements:
         | 
| 75 | 
            +
                - - ! '>='
         | 
| 76 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            +
                    version: '0'
         | 
| 78 | 
            +
            description: Provides LiveResource integration with Pubnub.
         | 
| 79 | 
            +
            email:
         | 
| 80 | 
            +
            - will@letsgeddit.com
         | 
| 81 | 
            +
            executables: []
         | 
| 82 | 
            +
            extensions: []
         | 
| 83 | 
            +
            extra_rdoc_files: []
         | 
| 84 | 
            +
            files:
         | 
| 85 | 
            +
            - .gitignore
         | 
| 86 | 
            +
            - .rspec
         | 
| 87 | 
            +
            - .travis.yml
         | 
| 88 | 
            +
            - Gemfile
         | 
| 89 | 
            +
            - LICENSE.txt
         | 
| 90 | 
            +
            - README.md
         | 
| 91 | 
            +
            - Rakefile
         | 
| 92 | 
            +
            - lib/live_resource/pubnub.rb
         | 
| 93 | 
            +
            - lib/live_resource/pubnub/pubnub_protocol.rb
         | 
| 94 | 
            +
            - lib/live_resource/pubnub/version.rb
         | 
| 95 | 
            +
            - live_resource-pubnub.gemspec
         | 
| 96 | 
            +
            - spec/live_resource/pubnub/pubnub_protocol_spec.rb
         | 
| 97 | 
            +
            - spec/live_resource/pubnub_spec.rb
         | 
| 98 | 
            +
            - spec/spec_helper.rb
         | 
| 99 | 
            +
            homepage: ''
         | 
| 100 | 
            +
            licenses:
         | 
| 101 | 
            +
            - MIT
         | 
| 102 | 
            +
            post_install_message: 
         | 
| 103 | 
            +
            rdoc_options: []
         | 
| 104 | 
            +
            require_paths:
         | 
| 105 | 
            +
            - lib
         | 
| 106 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
              none: false
         | 
| 108 | 
            +
              requirements:
         | 
| 109 | 
            +
              - - ! '>='
         | 
| 110 | 
            +
                - !ruby/object:Gem::Version
         | 
| 111 | 
            +
                  version: '0'
         | 
| 112 | 
            +
                  segments:
         | 
| 113 | 
            +
                  - 0
         | 
| 114 | 
            +
                  hash: -2026245229616821162
         | 
| 115 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 116 | 
            +
              none: false
         | 
| 117 | 
            +
              requirements:
         | 
| 118 | 
            +
              - - ! '>='
         | 
| 119 | 
            +
                - !ruby/object:Gem::Version
         | 
| 120 | 
            +
                  version: '0'
         | 
| 121 | 
            +
                  segments:
         | 
| 122 | 
            +
                  - 0
         | 
| 123 | 
            +
                  hash: -2026245229616821162
         | 
| 124 | 
            +
            requirements: []
         | 
| 125 | 
            +
            rubyforge_project: 
         | 
| 126 | 
            +
            rubygems_version: 1.8.25
         | 
| 127 | 
            +
            signing_key: 
         | 
| 128 | 
            +
            specification_version: 3
         | 
| 129 | 
            +
            summary: Provides LiveResource integration with Pubnub.
         | 
| 130 | 
            +
            test_files:
         | 
| 131 | 
            +
            - spec/live_resource/pubnub/pubnub_protocol_spec.rb
         | 
| 132 | 
            +
            - spec/live_resource/pubnub_spec.rb
         | 
| 133 | 
            +
            - spec/spec_helper.rb
         |