foreign_office 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5dc54e45b5f8ad26dc7fd81bfe6fb22f7d288e0
4
- data.tar.gz: 9fca354069d71f858748e472519f38e0eb7801a3
3
+ metadata.gz: a1ea1f080a84fe5cd99fa101db37262bf0fa8e48
4
+ data.tar.gz: 6332d013e2db46090c59c6dbe6c4b3832b931de4
5
5
  SHA512:
6
- metadata.gz: f7b8c668c82b18e387b7854051b238c9ae15eb31d83e079dcffc4ed712fd706dbb4bab459d99900f852ceb5cdda449e808c63dad1b69428aecd46bb4839412a7
7
- data.tar.gz: 5e02f7f7e9801f21598fffe41a71207666cf289080eb759998dcf1736998a59e3ec1830edffbf107ab246521bc0e8d9e09a6f49d9a1e3387f6c7a872af87af59
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
- connection: function(){
13
- return this.pubnub;
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.connection().subscribe({
37
+ foreign_office.bus.subscribe({
39
38
  channel : channel_name,
40
- backfill: true,
41
- message : function(m){foreign_office_channel.handleMessage(m)}
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
+ })
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ForeignOffice
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  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.6
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-26 00:00:00.000000000 Z
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