foreign_office 0.0.6 → 0.0.7
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/app/assets/javascripts/foreign_office.js +10 -11
- data/app/assets/javascripts/pubnub_bus.js +17 -0
- data/app/assets/javascripts/pusher_bus.js +11 -0
- data/lib/foreign_office.rb +8 -1
- data/lib/foreign_office/busses/pubnub_bus.rb +6 -0
- data/lib/foreign_office/busses/pusher_bus.rb +47 -1
- data/lib/foreign_office/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1ea1f080a84fe5cd99fa101db37262bf0fa8e48
|
4
|
+
data.tar.gz: 6332d013e2db46090c59c6dbe6c4b3832b931de4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7616e1147b548a44bea060431c8080d086a390a929d0ccbfbb0afa4a528380fb6588d79b59fba8160acc0b356d301d94a712f7a19175883758bd63b3e6cc2e30
|
7
|
+
data.tar.gz: f3ea362d256d732df3cfb57342b0994c2a7e4e115f49a387e3daf4e68f2dd7ed5b63a83f5f2f4d8196583625e7ddc0ba08a01707ca83c9a473997d4c0474fdf9
|
@@ -1,16 +1,15 @@
|
|
1
1
|
//= require debug_logger
|
2
|
+
//= require pubnub_bus
|
3
|
+
//= require pusher_bus
|
4
|
+
|
2
5
|
var ForeignOffice = Class.extend({
|
3
6
|
init: function(){
|
4
|
-
this.pubnub = PUBNUB.init({
|
5
|
-
publish_key : 'pub-c-1146120f-14f7-4649-9dee-3b21a519d573',
|
6
|
-
subscribe_key : 'sub-c-9d1b308c-a5f1-11e2-87b3-12313f022c90',
|
7
|
-
ssl : true
|
8
|
-
});
|
9
7
|
this.channels = [];
|
10
8
|
this.channels_by_name = [];
|
11
9
|
},
|
12
|
-
|
13
|
-
|
10
|
+
config: function(config){
|
11
|
+
bus_class = eval(config.bus_name);
|
12
|
+
this.bus = new bus_class(config);
|
14
13
|
},
|
15
14
|
addListener: function($listener){
|
16
15
|
var listener_class = eval(getSubClass($listener.data('listener'),'ForeignOfficeListener'));
|
@@ -35,10 +34,11 @@ foreign_office = new ForeignOffice();
|
|
35
34
|
var ForeignOfficeChannel = Class.extend({
|
36
35
|
init: function(channel_name){
|
37
36
|
var foreign_office_channel = this;
|
38
|
-
foreign_office.
|
37
|
+
foreign_office.bus.subscribe({
|
39
38
|
channel : channel_name,
|
40
|
-
|
41
|
-
|
39
|
+
callback : function(m){
|
40
|
+
foreign_office_channel.handleMessage(m)
|
41
|
+
}
|
42
42
|
});
|
43
43
|
this.channel_name = channel_name;
|
44
44
|
this.listeners = [];
|
@@ -46,7 +46,6 @@ var ForeignOfficeChannel = Class.extend({
|
|
46
46
|
handleMessage: function(m){
|
47
47
|
debug_logger.log("Got a message: ");
|
48
48
|
debug_logger.log(m);
|
49
|
-
console.log(this);
|
50
49
|
$.each(this.listeners,function(i,listener){
|
51
50
|
debug_logger.log("sending message to listener: ");
|
52
51
|
debug_logger.log(listener);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
var PubnubBus = Class.extend({
|
2
|
+
init: function(config){
|
3
|
+
this.pubnub = PUBNUB.init({
|
4
|
+
publish_key : config.publish_key,
|
5
|
+
subscribe_key : config.subscribe_key,
|
6
|
+
ssl : config.ssl
|
7
|
+
});
|
8
|
+
},
|
9
|
+
subscribe: function(subscription){
|
10
|
+
this.pubnub.subscribe({
|
11
|
+
channel : subscription.channel,
|
12
|
+
backfill: true,
|
13
|
+
message : function(m){subscription.callback(m)}
|
14
|
+
});
|
15
|
+
|
16
|
+
}
|
17
|
+
})
|
@@ -0,0 +1,11 @@
|
|
1
|
+
var PusherBus = Class.extend({
|
2
|
+
init: function(config){
|
3
|
+
this.pusher = new Pusher(config.key);
|
4
|
+
},
|
5
|
+
subscribe: function(subscription){
|
6
|
+
this.channel = this.pusher.subscribe(subscription.channel);
|
7
|
+
this.channel.bind('publish', function(data){
|
8
|
+
subscription.callback(data);
|
9
|
+
})
|
10
|
+
}
|
11
|
+
})
|
data/lib/foreign_office.rb
CHANGED
@@ -10,6 +10,12 @@ module ForeignOffice
|
|
10
10
|
autoload :FakeForeignOffice, 'foreign_office/test/fake_foreign_office'
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.config(config)
|
14
|
+
self.bus = config[:bus][:klass]
|
15
|
+
self.bus.config(config[:bus])
|
16
|
+
@publish_method = config[:publish_method]
|
17
|
+
end
|
18
|
+
|
13
19
|
def self.bus=(bus)
|
14
20
|
@bus = bus
|
15
21
|
end
|
@@ -68,4 +74,5 @@ module ForeignOffice
|
|
68
74
|
|
69
75
|
end
|
70
76
|
require 'foreign_office/busses/generic_bus'
|
71
|
-
require 'foreign_office/busses/pubnub_bus'
|
77
|
+
require 'foreign_office/busses/pubnub_bus'
|
78
|
+
require 'foreign_office/busses/pusher_bus'
|
@@ -1,5 +1,11 @@
|
|
1
1
|
class ForeignOffice::Busses::PubnubBus < ForeignOffice::Busses::GenericBus
|
2
2
|
|
3
|
+
def self.config(config)
|
4
|
+
self.publish_key = config[:publish_key]
|
5
|
+
self.subscribe_key = config[:subscribe_key]
|
6
|
+
self.secret_key = config[:secret_key]
|
7
|
+
end
|
8
|
+
|
3
9
|
def self.publish_key=(publish_key)
|
4
10
|
@publish_key = publish_key
|
5
11
|
end
|
@@ -1,2 +1,48 @@
|
|
1
|
-
class PusherBus < GenericBus
|
1
|
+
class ForeignOffice::Busses::PusherBus < ForeignOffice::Busses::GenericBus
|
2
|
+
def self.config(config)
|
3
|
+
self.app_id = config[:app_id]
|
4
|
+
self.key = config[:key]
|
5
|
+
self.secret = config[:secret]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.app_id=(app_id)
|
9
|
+
@app_id = app_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.app_id
|
13
|
+
@app_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.key=(key)
|
17
|
+
@key = key
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.key
|
21
|
+
@key
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.secret=(secret)
|
25
|
+
@secret = secret
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.secret
|
29
|
+
@secret
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.connection
|
33
|
+
@pusher ||= Pusher::Client.new({
|
34
|
+
app_id: self.app_id,
|
35
|
+
key: self.key,
|
36
|
+
secret: self.secret
|
37
|
+
})
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.publish(message)
|
41
|
+
message.symbolize_keys!
|
42
|
+
self.connection.trigger(
|
43
|
+
message[:channel],
|
44
|
+
'publish',
|
45
|
+
message
|
46
|
+
)
|
47
|
+
end
|
2
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreign_office
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Draut
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08-
|
12
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- app/assets/javascripts/debug_logger.js
|
81
81
|
- app/assets/javascripts/foreign_office.js
|
82
|
+
- app/assets/javascripts/pubnub_bus.js
|
83
|
+
- app/assets/javascripts/pusher_bus.js
|
82
84
|
- lib/foreign_office.rb
|
83
85
|
- lib/foreign_office/busses/generic_bus.rb
|
84
86
|
- lib/foreign_office/busses/pubnub_bus.rb
|