opal-pusher 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/bin/setup +7 -0
- data/lib/opal/pusher.rb +10 -0
- data/lib/opal/pusher/version.rb +5 -0
- data/opal-pusher.gemspec +24 -0
- data/opal/pusher.rb +27 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d40afbbb64eb993531724868b477c1e47fbb6da8
|
4
|
+
data.tar.gz: 525c37dabe776a93ea678f00874ff6f2b11f625c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad4636965c0bdf6fe9816ddaf5a5e8b948312ad11d015916b2fe1b08edbd4d64b950e928a8311b3c4e6c944d5c0721f47c47e4e22bd4ed820a06d2203783a81d
|
7
|
+
data.tar.gz: de3b3af4d03d20ab47cf5d318f101ac1fa73ce805605c38c79677aead2e1027e940908c3214b98f89c8d21ca0f610a20d21b6e70e54fbc60f2ffa9e691956106
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Opal-Pusher
|
2
|
+
|
3
|
+
Opal-Pusher is a set of Ruby bindings for the Pusher API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'opal-pusher'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install opal-pusher
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You'll need to pass your Pusher API key into your front-end app somehow. In Rails apps, I usually use the `gon` gem for this:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gon.push pusher_api_key: ENV.fetch('PUSHER_API_KEY')
|
27
|
+
```
|
28
|
+
|
29
|
+
Once you have that accessible from the front-end, you can open up a Pusher connection in your Opal app like this:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'pusher' # Load this library
|
33
|
+
|
34
|
+
pusher = Pusher.new(`gon.pusher_api_key`)
|
35
|
+
channel = pusher.subscribe("my-pusher-channel")
|
36
|
+
channel.bind "my-pusher-event" do |data|
|
37
|
+
puts data # data is a hash
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
I've been using this to set the attributes of models in Clearwater apps:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
foo_channel.bind 'update' do |data|
|
45
|
+
FooRepository[data[:id]].set_attributes data
|
46
|
+
App.render # Rerender the app with new data
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( https://github.com/jgaskins/opal-pusher/fork )
|
53
|
+
2. Branch it (`git checkout -b brand-new-thing`)
|
54
|
+
3. Hack it
|
55
|
+
4. Save it
|
56
|
+
5. Commit it (`git commit -am 'Do the thing'`)
|
57
|
+
6. Push it (`git push origin brand-new-thing`)
|
58
|
+
7. Pull-request it
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/setup
ADDED
data/lib/opal/pusher.rb
ADDED
data/opal-pusher.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opal/pusher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "opal-pusher"
|
8
|
+
spec.version = Opal::Pusher::VERSION
|
9
|
+
spec.authors = ["Jamie Gaskins"]
|
10
|
+
spec.email = ["jgaskins@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Opal bindings for the Pusher JS API}
|
13
|
+
spec.homepage = "https://github.com/jgaskins/opal-pusher"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
|
23
|
+
spec.add_runtime_dependency "opal", "~> 0.7"
|
24
|
+
end
|
data/opal/pusher.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Pusher
|
2
|
+
def initialize(api_key)
|
3
|
+
if `!window.Pusher`
|
4
|
+
raise NotImplementedError, 'Pusher is not yet loaded. Make sure you load the Pusher JS library from the Pusher site before trying to instantiate it from your Opal app.'
|
5
|
+
end
|
6
|
+
|
7
|
+
@pusher = `new Pusher(api_key)`
|
8
|
+
end
|
9
|
+
|
10
|
+
def subscribe channel
|
11
|
+
Channel.new(`#@pusher.subscribe(channel)`)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Channel
|
15
|
+
def initialize channel
|
16
|
+
@channel = channel
|
17
|
+
end
|
18
|
+
|
19
|
+
def bind event
|
20
|
+
handler = proc do |data|
|
21
|
+
yield Hash.new(data) if block_given?
|
22
|
+
end
|
23
|
+
`#@channel.bind(event, handler)`
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal-pusher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamie Gaskins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.7'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jgaskins@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- bin/setup
|
67
|
+
- lib/opal/pusher.rb
|
68
|
+
- lib/opal/pusher/version.rb
|
69
|
+
- opal-pusher.gemspec
|
70
|
+
- opal/pusher.rb
|
71
|
+
homepage: https://github.com/jgaskins/opal-pusher
|
72
|
+
licenses: []
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.4.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Opal bindings for the Pusher JS API
|
94
|
+
test_files: []
|