rails_bridge 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.rdoc +45 -30
- data/VERSION +1 -1
- data/rails_bridge.gemspec +2 -2
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -11,20 +11,24 @@ Easy embedding of remote content into your Rails app, plus exporting of your Rai
|
|
11
11
|
RailsBridge has two components.
|
12
12
|
|
13
13
|
=== RailsBridge::ContentBridge
|
14
|
-
Allows for easy embedding of content from
|
14
|
+
Allows for easy embedding of content from remote servers directly into the HTML, XML, or Javascript returned by your Rails application. The remote server may be an external application, a web service, or any other resource available via HTTP on the network.
|
15
15
|
=== RailsBridge::LayoutBridge
|
16
|
-
Allows easy exporting of your Rails HTML layouts as templates for other applications.
|
16
|
+
Allows for easy exporting of your Rails HTML layouts as templates for other applications.
|
17
|
+
|
17
18
|
---
|
19
|
+
|
18
20
|
== INSTALLATION
|
19
21
|
|
20
22
|
rails_bridge is installed as a Ruby gem.
|
21
23
|
|
22
24
|
gem install rails_bridge
|
23
|
-
|
25
|
+
|
24
26
|
Include the gem in your Gemfile.
|
25
27
|
|
26
28
|
gem 'rails_bridge'
|
27
29
|
|
30
|
+
(Note: RailsBridge depends on the Typhoeus gem. See CREDITS for more information about installation requirements for Typhoeus if you have difficulty with installation.)
|
31
|
+
|
28
32
|
---
|
29
33
|
|
30
34
|
== CONTENT BRIDGE
|
@@ -37,20 +41,23 @@ The content bridge is used to retrieve and cache content from external HTTP serv
|
|
37
41
|
* Generate a content bridge using the provided Rails generator
|
38
42
|
rails g content_bridge twitter_status_cacher
|
39
43
|
|
40
|
-
* Edit the generated class file (app/rails_bridge/content_bridges/twitter_status_cacher.rb).
|
44
|
+
* Edit the generated class file (app/rails_bridge/content_bridges/twitter_status_cacher.rb).
|
45
|
+
|
46
|
+
The following shows an example.
|
47
|
+
|
48
|
+
require 'json'
|
49
|
+
|
50
|
+
class TwitterStatusCacher < RailsBridge::ContentBridge
|
51
|
+
self.request_timeout = 1000 # miliseconds
|
52
|
+
self.cache_timeout = 60 # seconds
|
53
|
+
self.host = 'api.twitter.com'
|
54
|
+
self.path = '/statuses/user_timeline.json'
|
55
|
+
self.default_content = '<<Twitter unavailable>>'
|
56
|
+
self.on_success {|content| JSON.parse(content).first["text"]}
|
57
|
+
end
|
58
|
+
|
59
|
+
In your controller:
|
41
60
|
|
42
|
-
require 'json'
|
43
|
-
|
44
|
-
class TwitterStatusCacher < RailsBridge::ContentBridge
|
45
|
-
self.request_timeout = 1000 # miliseconds
|
46
|
-
self.cache_timeout = 60 # seconds
|
47
|
-
self.host = 'api.twitter.com'
|
48
|
-
self.path = '/statuses/user_timeline.json'
|
49
|
-
self.default_content = '<<Twitter unavailable>>'
|
50
|
-
self.on_success {|content| JSON.parse(content).first["text"]}
|
51
|
-
end
|
52
|
-
|
53
|
-
* In your controller:
|
54
61
|
@soopa_latest_tweet = TwitterStatusCacher.get_remote_content(:params=>{:screen_name => 'soopa'})
|
55
62
|
|
56
63
|
That's it! If the request time's out before 1 second, "<<Twitter unavailable>>" will be returned instead.
|
@@ -94,13 +101,13 @@ You can also simply use the url method to define the +protocol+, +host+, +port+,
|
|
94
101
|
|
95
102
|
You may pre-process the content returned by a request by defining an +on_success+ block. The remote content is passed as a parameter and the return value of the block is used in place of the original content.
|
96
103
|
|
97
|
-
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
+
RailsBridge::ContentBridge.content_request( :server_com ) do |request|
|
105
|
+
request.url = "http://server.com:8080/some/path"
|
106
|
+
request.params = {:param1=>'a value', :param2=>'another value'}
|
107
|
+
request.default_content = "Content unavailable at this time."
|
108
|
+
request.request_timeout = 1000 # miliseconds
|
109
|
+
request.on_success {|content| JSON.parse(content)}
|
110
|
+
end
|
104
111
|
|
105
112
|
=== Caching
|
106
113
|
|
@@ -176,11 +183,6 @@ eg.
|
|
176
183
|
|
177
184
|
will create a class named +MyContentBridge+ containing a prototype request definition named +my_request+ and place it under _app/rails_bridge/content_bridges.
|
178
185
|
|
179
|
-
=== Loading your content bridge classes
|
180
|
-
|
181
|
-
All classes under app/rails_bridge/content_bridges will be loaded automatically during application initialization and reloaded when in running in development.
|
182
|
-
|
183
|
-
|
184
186
|
=== Batching requests for parallel execution
|
185
187
|
|
186
188
|
You can also queue up a batch of multiple requests and execute them in parallel to minimize the time it takes to execute them all. In order to assign the results, you must use the request_<request_name> method and pass a block accepting the result as a parameter which assigns the result to a variable in your context. When you have scheduled all of your requests, call +execute_requests+ to execute them in parallel. When +execute_requests+ returns, all of the blocks passed to your request methods will have been executed.
|
@@ -213,6 +215,10 @@ You can also queue up a batch of multiple requests and execute them in parallel
|
|
213
215
|
|
214
216
|
# soopa_latest_tweet and hoonpark_latest_tweet will now be assigned
|
215
217
|
|
218
|
+
=== Loading your content bridge classes
|
219
|
+
|
220
|
+
All classes under app/rails_bridge/content_bridges will be loaded automatically during application initialization and reloaded when in running in development.
|
221
|
+
|
216
222
|
---
|
217
223
|
|
218
224
|
== LAYOUT BRIDGE
|
@@ -238,7 +244,7 @@ Also, any partials that exist under app/rails_bridge/views will take precedence
|
|
238
244
|
|
239
245
|
== DEVELOPMENT
|
240
246
|
|
241
|
-
RailsBridge was developed and tested using Ruby v1.9.2 and Rails v3.0.3.
|
247
|
+
RailsBridge was developed and tested using Ruby v1.9.2 and Rails v3.0.3.
|
242
248
|
|
243
249
|
You may download the source from Github at http://github.com/capitalthought/rails_bridge.
|
244
250
|
|
@@ -256,10 +262,19 @@ RSpec 2.x is used for the Rails Bridge test suite. To run the suite:
|
|
256
262
|
or
|
257
263
|
rake spec
|
258
264
|
|
259
|
-
NOTE: The test suite has an additional dependency on the eventmachine gem to to implement
|
265
|
+
NOTE: The test suite has an additional dependency on the eventmachine gem to to implement a test HTTP server.
|
260
266
|
|
261
267
|
---
|
262
268
|
|
269
|
+
== CREDITS
|
270
|
+
|
271
|
+
The ContentBridge component of RailsBridge is fundamentally a wrapper around the excellent Typhoeus gem; packaged as a Rails engine with conveniences added for managing content in the context of Rails. Typhoeus, in turn, depends on a native installation of curl.
|
272
|
+
|
273
|
+
Typhoeus usually installs nicely if you already have curl installed on your OS. If you have difficulty installing Typhoeus, please refer to the following sources.
|
274
|
+
|
275
|
+
* https://github.com/dbalatero/typhoeus
|
276
|
+
* http://groups.google.com/group/typhoeus
|
277
|
+
|
263
278
|
== LICENSE
|
264
279
|
|
265
280
|
Copyright 2010 Capital Thought, LLC
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/rails_bridge.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rails_bridge}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["shock"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-11}
|
13
13
|
s.description = %q{Allows for easy embedding of content from a remote HTTP server and exporting of the Rails HTML layout into another template.}
|
14
14
|
s.email = %q{billdoughty@capitalthought.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 10
|
9
|
+
version: 0.0.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- shock
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-11 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -331,7 +331,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
331
331
|
requirements:
|
332
332
|
- - ">="
|
333
333
|
- !ruby/object:Gem::Version
|
334
|
-
hash:
|
334
|
+
hash: 3821419645836613859
|
335
335
|
segments:
|
336
336
|
- 0
|
337
337
|
version: "0"
|