codegears 0.0.17.pre → 0.0.18.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/cg/api.rb +9 -1
  2. data/lib/cg/app.rb +61 -1
  3. data/lib/cg/version.rb +1 -1
  4. metadata +2 -2
data/lib/cg/api.rb CHANGED
@@ -3,7 +3,8 @@ require "httparty"
3
3
  module CG
4
4
  class API
5
5
  include HTTParty
6
- ROOT_URL = "http://codegears.co"
6
+ ROOT_URL = "http://codegears.co"
7
+ PUSHER_URL = "http://codegears.co:9292/stream"
7
8
 
8
9
  def self.create_app_request(email)
9
10
  self.post("#{ROOT_URL}/apps", :body => { :application => { :email => email } })
@@ -12,5 +13,12 @@ module CG
12
13
  def self.show_app_request(id)
13
14
  self.get("#{ROOT_URL}/apps/#{id}")
14
15
  end
16
+
17
+ def self.push_message_request(channel, message)
18
+ message = { :channel => channel,
19
+ :message => message,
20
+ :ext => { :secret_id => CG::APP.secret_id, :secret_token => CG::APP.secret_token } }.to_json
21
+ Net::HTTP.post_form(URI.parse(PUSHER_URL), :message => message)
22
+ end
15
23
  end
16
24
  end
data/lib/cg/app.rb CHANGED
@@ -1,13 +1,73 @@
1
1
  require "singleton"
2
+ require "cg/api"
2
3
 
3
4
  module CG
4
5
  class APP
5
6
  include Singleton
6
7
 
7
- attr_accessor :secret_id, :secret_token, :id
8
+ attr_accessor :secret_id, :secret_token, :id, :channel, :message, :sent, :response
8
9
 
9
10
  def self.configure
10
11
  yield(self.instance)
11
12
  end
13
+
14
+ def self.secret_id
15
+ self.instance.secret_id
16
+ end
17
+
18
+ def self.secret_token
19
+ self.instance.secret_token
20
+ end
21
+
22
+ def self.init_message
23
+ yield(self.instance)
24
+ self.instance
25
+ end
26
+
27
+ def self.message
28
+ self.instance.message
29
+ end
30
+
31
+ def self.channel
32
+ self.instance.channel
33
+ end
34
+
35
+ def self.sent?
36
+ !!self.instance.sent
37
+ end
38
+
39
+ def self.response
40
+ self.instance.response
41
+ end
42
+
43
+ def self.push(channel)
44
+ instance = self.instance
45
+
46
+ instance.channel = channel
47
+ instance.message = yield
48
+
49
+ instance.response = CG::API.push_message_request(instance.channel, instance.message)
50
+ end
51
+
52
+ def self.push(channel, message)
53
+ instance = self.instance
54
+
55
+ instance.channel = instance.perform(channel)
56
+ instance.message = message
57
+
58
+ instance.response = CG::API.push_message_request(instance.channel, instance.message)
59
+ end
60
+
61
+ def channel=(ch)
62
+ @channel = perform(ch)
63
+ end
64
+
65
+ def push
66
+ instance.response = CG::API.push_message_request(channel, message)
67
+ end
68
+
69
+ def perform(channel)
70
+ channel[0] == "/" ? channel : "/#{channel}"
71
+ end
12
72
  end
13
73
  end
data/lib/cg/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CG
2
- VERSION = "0.0.17.pre"
2
+ VERSION = "0.0.18.pre"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codegears
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17.pre
4
+ version: 0.0.18.pre
5
5
  prerelease: 7
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails