transistor 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/Gemfile +11 -0
- data/Gemfile.lock +57 -0
- data/README.md +96 -0
- data/Rakefile +109 -0
- data/faye-browser.js +2194 -0
- data/index.html +40 -0
- data/jake.yml +24 -0
- data/lib/transistor/binder.js +109 -0
- data/lib/transistor/control.js +62 -0
- data/lib/transistor/radio.js +67 -0
- data/lib/vendor/faye-browser-min.js +2 -0
- data/lib/vendor/jsonp.js +83 -0
- data/spec/javascripts/TransistorBinderSpec.js +273 -0
- data/spec/javascripts/helpers/AssertHelpers.js +23 -0
- data/spec/javascripts/support/jasmine.yml +9 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b5176c42b0149790524cb131b0fe4e070c775ae
|
4
|
+
data.tar.gz: 1fd188be8e56121b75c75adcda575943d9eaf5dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 601eca82ca3e84ae2a95b47949fd14ce6a2dca83fd5cada55792ee2f9df457b08c3ede7fc92d088a1df7ee9f67409f30ab4e71ac900beb5e8025faa78418ffbd
|
7
|
+
data.tar.gz: a97eb35930783a87e68d37fc52dc545310ee06723671acee136837c5d2467e32945ca0be4df2e465b9ac0e7e70ab5124178fea79030e5382966f29af070c801f
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
childprocess (0.3.9)
|
5
|
+
ffi (~> 1.0, >= 1.0.11)
|
6
|
+
diff-lcs (1.2.4)
|
7
|
+
eventful (1.0.1)
|
8
|
+
methodphitamine (= 1.0.0)
|
9
|
+
ffi (1.8.1)
|
10
|
+
gem-this (0.3.7)
|
11
|
+
jake (1.1.1)
|
12
|
+
eventful (>= 1.0.0)
|
13
|
+
oyster (>= 0.9.5)
|
14
|
+
packr (>= 3.2.0)
|
15
|
+
jasmine (1.3.2)
|
16
|
+
jasmine-core (~> 1.3.1)
|
17
|
+
rack (~> 1.0)
|
18
|
+
rspec (>= 1.3.1)
|
19
|
+
selenium-webdriver (>= 0.1.3)
|
20
|
+
jasmine-core (1.3.1)
|
21
|
+
jslint-v8 (1.1.1)
|
22
|
+
therubyracer (~> 0.10.0)
|
23
|
+
libv8 (3.3.10.4)
|
24
|
+
methodphitamine (1.0.0)
|
25
|
+
multi_json (1.7.2)
|
26
|
+
oyster (0.9.5)
|
27
|
+
packr (3.2.1)
|
28
|
+
oyster (>= 0.9.5)
|
29
|
+
rack (1.5.2)
|
30
|
+
rake (10.0.4)
|
31
|
+
rspec (2.13.0)
|
32
|
+
rspec-core (~> 2.13.0)
|
33
|
+
rspec-expectations (~> 2.13.0)
|
34
|
+
rspec-mocks (~> 2.13.0)
|
35
|
+
rspec-core (2.13.1)
|
36
|
+
rspec-expectations (2.13.0)
|
37
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
38
|
+
rspec-mocks (2.13.1)
|
39
|
+
rubyzip (0.9.9)
|
40
|
+
selenium-webdriver (2.32.1)
|
41
|
+
childprocess (>= 0.2.5)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
rubyzip
|
44
|
+
websocket (~> 1.0.4)
|
45
|
+
therubyracer (0.10.2)
|
46
|
+
libv8 (~> 3.3.10)
|
47
|
+
websocket (1.0.7)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
gem-this
|
54
|
+
jake
|
55
|
+
jasmine
|
56
|
+
jslint-v8
|
57
|
+
rake
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# Radiotower Client
|
2
|
+
|
3
|
+
The javascript client consists mainly of two parts:
|
4
|
+
|
5
|
+
* Transistor.Control
|
6
|
+
* Transistor.Radio
|
7
|
+
|
8
|
+
## Control
|
9
|
+
|
10
|
+
The Control object is used for administrative work on a station. It is initialized as following:
|
11
|
+
|
12
|
+
```javascript
|
13
|
+
var broadcaster_url = "http://broadcast.radiotower.io",
|
14
|
+
station_uid = "5a665bf153c0437bdb14a3004dad52e1",
|
15
|
+
push_token = "e29c6c92143cfaa0d5026aebf87f1a0f";
|
16
|
+
|
17
|
+
var control = Transistor.Control(broadcaster_url, station_uid, push_token);
|
18
|
+
```
|
19
|
+
|
20
|
+
The main purpose of the Control object is the administration of specific channels. It supports the following basic collection operations:
|
21
|
+
|
22
|
+
```javascript
|
23
|
+
control.set("channel/path", [{value: 'collection'}, {value: 'of'}, {value: 'entries'}]);
|
24
|
+
control.insert("channel/path", {value: 'object that gets pushed'});
|
25
|
+
control.update("channel/path", 12, {value: 'i am the new object w/ id 12'});
|
26
|
+
control.remove("channel/path", 23); // object w/ id 23 gets removed
|
27
|
+
```
|
28
|
+
|
29
|
+
The actual ids of an specific entry are retrieved through the client, which usage gets explained in the following chapter.
|
30
|
+
|
31
|
+
## Radio
|
32
|
+
|
33
|
+
The Radio object can be used --- as the name might suggest --- for listening to specific channels of a station of the Radiotower. It is initialized as following:
|
34
|
+
|
35
|
+
```javascript
|
36
|
+
var station_finder_url = "http://station_finder.radiotower.io",
|
37
|
+
station_uid = "5a665bf153c0437bdb14a3004dad52e1",
|
38
|
+
test_token = "d10cf06ecd08ff5bc0df1c8bb84d1107"
|
39
|
+
// or use the live_token, if it's a production application
|
40
|
+
|
41
|
+
var radio = Transistor.Radio(station_finder_url, station_uid, test_token);
|
42
|
+
```
|
43
|
+
|
44
|
+
Now the basic Radio is initialized. No network connections or requests are done so far. On a second step, you have to tune your radio to all the channels, you want to listen to:
|
45
|
+
|
46
|
+
```javascript
|
47
|
+
var listener = function (event, args) {
|
48
|
+
console.log("Event '"+event+"' occured with args", arg);
|
49
|
+
};
|
50
|
+
|
51
|
+
radio.tune("news", listener);
|
52
|
+
radio.tune("sports", listener);
|
53
|
+
```
|
54
|
+
|
55
|
+
Even at this point, no connections where made, the listener structure is 100% passive.
|
56
|
+
|
57
|
+
To get things startet, you have to turn on the Radio (sounds pretty clear, eh?).
|
58
|
+
|
59
|
+
This will fire a request to the StationFinder like: "Hey, here I am, at which frequency can I get my channels, and what is their current state??"
|
60
|
+
|
61
|
+
```javascript
|
62
|
+
radio.turnOn();
|
63
|
+
```
|
64
|
+
|
65
|
+
From now on, your listener will fire, whenever an specific event occures. Below is a listing of the possible events and their respective arguments:
|
66
|
+
|
67
|
+
```javascript
|
68
|
+
// These are the arguments of the called listener (event, args)
|
69
|
+
|
70
|
+
// "init", {collection: [{id: 12, object: {..}}, {id: 13, object: {..}]}
|
71
|
+
// "set", {collection: [{id: 12, object: {..}}, {id: 13, object: {..}]}
|
72
|
+
// "insert", {entry: {id: 24, object: {..}}}
|
73
|
+
// "update", {id: 13, entry: {id: 13, object: {..}}}
|
74
|
+
// "remove", {id: 13}
|
75
|
+
```
|
76
|
+
|
77
|
+
## Binders
|
78
|
+
|
79
|
+
To simplify the binding between a remote Radiotower collection and your local array, Transistor gives you a nifty little tool called Binder.
|
80
|
+
|
81
|
+
Mainly, it implements a simple and thin listener which keeps track of changes and updates an array accordingly. Use it this way:
|
82
|
+
|
83
|
+
```javascript
|
84
|
+
// radio is already initialized but not turned on yet
|
85
|
+
|
86
|
+
var news = [],
|
87
|
+
news_binder = Transistor.Binder(news);
|
88
|
+
|
89
|
+
radio.tune("the/news", news_binder);
|
90
|
+
|
91
|
+
radio.turnOn();
|
92
|
+
```
|
93
|
+
|
94
|
+
From now on, your local array `news` is an exact copy of the collection in the channel "the/news". Radio and Binder are there for you, they talk and sync and you have nothing to worry about at all while using your local array.
|
95
|
+
|
96
|
+
But keep in mind, that changes on the array itself will bring most likely inconsitencies in your data. All updates, inserts, a.s.o. *MUST* bew made through the Control object.
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'jslint-v8'
|
3
|
+
|
4
|
+
namespace :js do
|
5
|
+
JSLintV8::RakeTask.new do |task|
|
6
|
+
task.name = "lint"
|
7
|
+
task.description = "runs jslint against all important javascript files"
|
8
|
+
|
9
|
+
task.output_stream = STDOUT
|
10
|
+
|
11
|
+
task.include_pattern = "lib/transistor/*.js"
|
12
|
+
|
13
|
+
task.browser = true # predefine Browser globals
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'jasmine'
|
19
|
+
load 'jasmine/tasks/jasmine.rake'
|
20
|
+
rescue LoadError
|
21
|
+
task :jasmine do
|
22
|
+
abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
require "rubygems"
|
28
|
+
require "rubygems/package_task"
|
29
|
+
require "rdoc/task"
|
30
|
+
|
31
|
+
require "rspec"
|
32
|
+
require "rspec/core/rake_task"
|
33
|
+
RSpec::Core::RakeTask.new do |t|
|
34
|
+
t.rspec_opts = %w(--format documentation --colour)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => ["spec"]
|
39
|
+
|
40
|
+
# This builds the actual gem. For details of what all these options
|
41
|
+
# mean, and other ones you can add, check the documentation here:
|
42
|
+
#
|
43
|
+
# http://rubygems.org/read/chapter/20
|
44
|
+
#
|
45
|
+
spec = Gem::Specification.new do |s|
|
46
|
+
|
47
|
+
# Change these as appropriate
|
48
|
+
s.name = "transistor"
|
49
|
+
s.version = "0.1.0"
|
50
|
+
s.summary = "Client for the radiotower.io service"
|
51
|
+
s.author = "Jakob Holderbaum"
|
52
|
+
s.email = "jakob@featurefabrik.de"
|
53
|
+
s.homepage = "http://featurefabrik.com"
|
54
|
+
|
55
|
+
s.has_rdoc = true
|
56
|
+
s.extra_rdoc_files = %w(README.md)
|
57
|
+
s.rdoc_options = %w(--main README.md)
|
58
|
+
|
59
|
+
# Add any extra files to include in the gem
|
60
|
+
s.files = %w(Gemfile.lock index.html Rakefile Gemfile faye-browser.js README.md jake.yml) + Dir.glob("{spec,lib}/**/*")
|
61
|
+
s.require_paths = ["lib"]
|
62
|
+
|
63
|
+
# If you want to depend on other gems, add them here, along with any
|
64
|
+
# relevant versions
|
65
|
+
# s.add_dependency("some_other_gem", "~> 0.1.0")
|
66
|
+
|
67
|
+
# If your tests use any gems, include them here
|
68
|
+
s.add_development_dependency('jasmine')
|
69
|
+
s.add_development_dependency('jslint-v8')
|
70
|
+
s.add_development_dependency('jake')
|
71
|
+
s.add_development_dependency('rake')
|
72
|
+
s.add_development_dependency('gem-this')
|
73
|
+
end
|
74
|
+
|
75
|
+
# This task actually builds the gem. We also regenerate a static
|
76
|
+
# .gemspec file, which is useful if something (i.e. GitHub) will
|
77
|
+
# be automatically building a gem for this project. If you're not
|
78
|
+
# using GitHub, edit as appropriate.
|
79
|
+
#
|
80
|
+
# To publish your gem online, install the 'gemcutter' gem; Read more
|
81
|
+
# about that here: http://gemcutter.org/pages/gem_docs
|
82
|
+
Gem::PackageTask.new(spec) do |pkg|
|
83
|
+
pkg.gem_spec = spec
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Build the gemspec file #{spec.name}.gemspec"
|
87
|
+
task :gemspec do
|
88
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
89
|
+
File.open(file, "w") {|f| f << spec.to_ruby }
|
90
|
+
end
|
91
|
+
|
92
|
+
# If you don't want to generate the .gemspec file, just remove this line. Reasons
|
93
|
+
# why you might want to generate a gemspec:
|
94
|
+
# - using bundler with a git source
|
95
|
+
# - building the gem without rake (i.e. gem build blah.gemspec)
|
96
|
+
# - maybe others?
|
97
|
+
task :package => :gemspec
|
98
|
+
|
99
|
+
# Generate documentation
|
100
|
+
RDoc::Task.new do |rd|
|
101
|
+
rd.main = "README.md"
|
102
|
+
rd.rdoc_files.include("README.md", "lib/**/*.rb")
|
103
|
+
rd.rdoc_dir = "rdoc"
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'Clear out RDoc and generated packages'
|
107
|
+
task :clean => [:clobber_rdoc, :clobber_package] do
|
108
|
+
rm "#{spec.name}.gemspec"
|
109
|
+
end
|