viaduct-api 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/viaduct/api/client.rb +16 -0
- data/lib/viaduct/api/push_client.rb +49 -0
- data/lib/viaduct/api/version.rb +1 -1
- data/lib/viaduct/api.rb +5 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb00a240bc610a40492bb2ba7c9b7e7d5f6e05c8
|
4
|
+
data.tar.gz: 0fa62e1faf2ce0d684041cb75919198e6defe41a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1acfb380ed0e2094620cab1c372e824470375ccdb1876a139efd64c20578ec4dd6bf9b561ef0fd81bfdeb0cb4c83aa6835d7b91aba69b1c6d9dc3dda05abd3a1
|
7
|
+
data.tar.gz: df56aa672060f7c7abdd52d07a28461d93aba1fce57d4441b5b36290efb22cd0b0bce7f78ba3876bc5d19c39ff9f9da94e340a48d661d9d0740616919a827eca
|
data/lib/viaduct/api/client.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'moonrope_client'
|
2
|
+
require 'viaduct/api/push_client'
|
2
3
|
|
3
4
|
module Viaduct
|
4
5
|
module API
|
5
6
|
class Client
|
6
7
|
|
8
|
+
attr_reader :token
|
9
|
+
attr_reader :secret
|
10
|
+
|
7
11
|
def initialize(token = nil, secret = nil)
|
8
12
|
@token, @secret = token, secret
|
9
13
|
end
|
@@ -16,6 +20,18 @@ module Viaduct
|
|
16
20
|
moonrope.controller(*args)
|
17
21
|
end
|
18
22
|
|
23
|
+
def push
|
24
|
+
@push_client ||= PushClient.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def token
|
28
|
+
@token
|
29
|
+
end
|
30
|
+
|
31
|
+
def secret
|
32
|
+
@secret
|
33
|
+
end
|
34
|
+
|
19
35
|
def method_missing(name, value = nil)
|
20
36
|
value.nil? ? controller(name) : super
|
21
37
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faye/websocket'
|
3
|
+
|
4
|
+
module Viaduct
|
5
|
+
module API
|
6
|
+
class PushClient
|
7
|
+
|
8
|
+
attr_reader :url
|
9
|
+
attr_reader :ws
|
10
|
+
|
11
|
+
def initialize(api_client)
|
12
|
+
@url = "#{Viaduct::API.ssl ? 'wss' : 'ws'}://#{Viaduct::API.host}:#{Viaduct::API.push_port}/push.ws/api:#{api_client.token}:#{api_client.secret}"
|
13
|
+
@ws = Faye::WebSocket::Client.new(@url)
|
14
|
+
end
|
15
|
+
|
16
|
+
def connected(&block)
|
17
|
+
@ws.on :open do |event|
|
18
|
+
block.call(event)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def receive(&block)
|
23
|
+
@ws.on :message do |event|
|
24
|
+
json = JSON.parse(event.data)
|
25
|
+
if json['type'] == 'push'
|
26
|
+
block.call(json['exchange'].to_sym, json['routing_key'].to_s, json['body'])
|
27
|
+
else
|
28
|
+
block.call(:global, nil, json)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def disconnected(&block)
|
34
|
+
@ws.on :close do |event|
|
35
|
+
block.call(event)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def send(type, data = {})
|
40
|
+
@ws.send(data.merge(:type => type).to_json)
|
41
|
+
end
|
42
|
+
|
43
|
+
def subscribe(exchange, routing_key)
|
44
|
+
send(:subscribe, :exchange => exchange, :routing_key => routing_key.to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/viaduct/api/version.rb
CHANGED
data/lib/viaduct/api.rb
CHANGED
@@ -8,6 +8,7 @@ module Viaduct
|
|
8
8
|
attr_accessor :application_token
|
9
9
|
attr_accessor :host
|
10
10
|
attr_accessor :port
|
11
|
+
attr_accessor :push_port
|
11
12
|
attr_accessor :ssl
|
12
13
|
|
13
14
|
def host
|
@@ -22,6 +23,10 @@ module Viaduct
|
|
22
23
|
@port || ENV['VIADUCT_API_PORT'] || (self.ssl ? 443 : 80)
|
23
24
|
end
|
24
25
|
|
26
|
+
def push_port
|
27
|
+
@push_port || ENV['VIADUCT_API_PUSH_PORT'] || self.port
|
28
|
+
end
|
29
|
+
|
25
30
|
def application_token
|
26
31
|
@application_token || ENV['VIADUCT_API_APP']
|
27
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: viaduct-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: moonrope-client
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faye-websocket
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.5
|
27
41
|
description: A full client library allows requests to made to the Viaduct API.
|
28
42
|
email:
|
29
43
|
- adam@viaduct.io
|
@@ -33,6 +47,7 @@ extra_rdoc_files: []
|
|
33
47
|
files:
|
34
48
|
- lib/viaduct/api.rb
|
35
49
|
- lib/viaduct/api/client.rb
|
50
|
+
- lib/viaduct/api/push_client.rb
|
36
51
|
- lib/viaduct/api/version.rb
|
37
52
|
homepage: http://viaduct.io
|
38
53
|
licenses:
|