alephant-broker 2.1.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +69 -67
- data/lib/alephant/broker/environment.rb +1 -0
- data/lib/alephant/broker/request.rb +0 -1
- data/lib/alephant/broker/request/factory.rb +0 -2
- data/lib/alephant/broker/response.rb +0 -1
- data/lib/alephant/broker/response/factory.rb +0 -2
- data/lib/alephant/broker/version.rb +1 -1
- metadata +2 -4
- data/lib/alephant/broker/request/multi.rb +0 -40
- data/lib/alephant/broker/response/multi.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71dd81ac255c7701b1676aa6f0e57d6c9913789e
|
4
|
+
data.tar.gz: 1ddc1f6954fe7302e9c87aba60ea0d1daee40b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adf9b7900d4723e2f7686c26848b856cc43d440c1e12d0e5fe524461939aab2950aba64ca3c7adf8bc69036c952e7a55c21a41371655605294274668e4d1a80c
|
7
|
+
data.tar.gz: 25553c80bb8a7c8c25c330d728df926fc9662d46df3349dd8491064c4c8babc56996fc47aa90cb5b885e2b109f6a1adbc0d1e6f326bfc3cf7c3f3c5e5ee2de48
|
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# Alephant::Broker
|
2
2
|
|
3
|
-
Brokers requests for rendered templates
|
3
|
+
Brokers requests for rendered templates, retrieved from S3 or a HTML endpoint.
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/BBC-News/alephant-broker.png?branch=master)](https://travis-ci.org/BBC-News/alephant-broker)
|
6
|
-
|
7
|
-
[![Gem Version](https://badge.fury.io/rb/alephant-broker.png)](http://badge.fury.io/rb/alephant-broker)
|
5
|
+
[![Build Status](https://travis-ci.org/BBC-News/alephant-broker.png?branch=master)](https://travis-ci.org/BBC-News/alephant-broker)[![Gem Version](https://badge.fury.io/rb/alephant-broker.png)](http://badge.fury.io/rb/alephant-broker)
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -14,101 +12,105 @@ Add this line to your application's Gemfile:
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
|
15
|
+
bundle install
|
18
16
|
|
19
17
|
Or install it yourself as:
|
20
18
|
|
21
|
-
|
19
|
+
gem install alephant-broker
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
23
|
+
The **Broker** is capable of retrieving rendered templates from either [S3](http://aws.amazon.com/s3/) or a HTML endpoint (e.g. [alephant-publisher-request](https://github.com/BBC-News/alephant-publisher-request)). This must be decided when creating an instance of the **Broker**, as a **load strategy** is given as a parameter (see below for examples).
|
24
|
+
|
25
25
|
### Barebones
|
26
26
|
|
27
|
+
##### S3 Load Strategy
|
28
|
+
|
27
29
|
```ruby
|
28
30
|
require 'alephant/broker'
|
31
|
+
require 'alephant/broker/load_strategy/s3'
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:lookup_table_name => "example_lookup"
|
33
|
+
config = {
|
34
|
+
:bucket_id => 'test_bucket',
|
35
|
+
:path => 'foo',
|
36
|
+
:lookup_table_name => 'test_lookup'
|
35
37
|
}
|
36
38
|
|
37
|
-
|
39
|
+
request = {
|
40
|
+
'PATH_INFO' => '/component/foo',
|
41
|
+
'QUERY_STRING' => 'variant=bar',
|
42
|
+
'REQUEST_METHOD' => 'GET'
|
43
|
+
}
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
Alephant::Broker::Application.new(
|
46
|
+
Alephant::Broker::LoadStrategy::S3.new,
|
47
|
+
config
|
48
|
+
).call(request).tap do |response|
|
49
|
+
puts "status: #{response.status}"
|
50
|
+
puts "content: #{response.content}"
|
51
|
+
end
|
43
52
|
```
|
44
53
|
|
45
|
-
|
54
|
+
##### HTML Load Strategy
|
46
55
|
|
47
56
|
```ruby
|
48
|
-
require 'alephant/broker
|
57
|
+
require 'alephant/broker'
|
58
|
+
require 'alephant/broker/load_strategy/http'
|
59
|
+
|
60
|
+
class UrlGenerator < Alephant::Broker::LoadStrategy::HTTP::URL
|
61
|
+
def generate(id, options)
|
62
|
+
"http://example-api.com/data?id=#{id}"
|
63
|
+
end
|
64
|
+
end
|
49
65
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
66
|
+
request = {
|
67
|
+
'PATH_INFO' => '/component/foo',
|
68
|
+
'QUERY_STRING' => 'variant=bar',
|
69
|
+
'REQUEST_METHOD' => 'GET'
|
54
70
|
}
|
55
71
|
|
56
|
-
|
57
|
-
|
72
|
+
Alephant::Broker::Application.new(
|
73
|
+
Alephant::Broker::LoadStrategy::HTTP.new(UrlGenerator.new),
|
74
|
+
{}
|
75
|
+
).call(request).tap do |response|
|
76
|
+
puts "status: #{response.status}"
|
77
|
+
puts "content: #{response.content}"
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
**Note**: the HTML load strategy relies upon being given a [URLGenerator](https://github.com/BBC-News/alephant-broker/blob/master/lib/alephant/broker/load_strategy/http.rb#L9-L13). This must be implemented within your own application, and extend `Alephant::Broker::LoadStrategy::HTTP::URL` (see above for an example). It is used to generate the URL which will act as the HTML endpoint.
|
58
82
|
|
59
|
-
|
83
|
+
### Rack App
|
60
84
|
|
61
|
-
|
62
|
-
# @content="<p>some HTML response</p>",
|
63
|
-
# @content_type="text/html",
|
64
|
-
# @status=200>
|
65
|
-
```
|
85
|
+
Create **config.ru** using example below, and then run:
|
66
86
|
|
67
|
-
|
87
|
+
rackup config.ru
|
68
88
|
|
69
89
|
```ruby
|
70
|
-
require 'alephant/broker
|
71
|
-
require '
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
super(Configuration.new)
|
77
|
-
end
|
90
|
+
require 'alephant/broker'
|
91
|
+
require 'alephant/broker/load_strategy/http'
|
92
|
+
|
93
|
+
class UrlGenerator < Alephant::Broker::LoadStrategy::HTTP::URL
|
94
|
+
def generate(id, options)
|
95
|
+
"http://example-api.com/data?id=#{id}"
|
78
96
|
end
|
79
97
|
end
|
98
|
+
|
99
|
+
run Alephant::Broker::Application.new(
|
100
|
+
Alephant::Broker::LoadStrategy::HTTP.new(UrlGenerator.new),
|
101
|
+
{}
|
102
|
+
)
|
80
103
|
```
|
81
104
|
|
82
|
-
##
|
105
|
+
## Contributing
|
83
106
|
|
84
|
-
|
107
|
+
1. [Fork it!]( http://github.com/bbc-news/alephant-broker/fork)
|
108
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
109
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
110
|
+
4. Push to the branch: `git push origin my-new-feature`
|
111
|
+
5. Create a new [Pull Request](https://github.com/BBC-News/alephant-broker/pulls).
|
85
112
|
|
86
|
-
|
87
|
-
export AWS_ACCESS_KEY_ID='xxxx'
|
88
|
-
export AWS_SECRET_ACCESS_KEY='xxxx'
|
89
|
-
export AWS_REGION='eu-west-1'
|
113
|
+
Feel free to create a new [issue](https://github.com/BBC-News/alephant-broker/issues/new) if you find a bug.
|
90
114
|
|
91
|
-
config = {
|
92
|
-
:bucket_id => "s3-render-example",
|
93
|
-
:path => "foo",
|
94
|
-
:lookup_table_name => "example_lookup"
|
95
|
-
}
|
96
|
-
|
97
|
-
env = {
|
98
|
-
"PATH_INFO" => "/component/england_council_header",
|
99
|
-
"QUERY_STRING" => ""
|
100
|
-
}
|
101
|
-
|
102
|
-
require 'alephant/broker/app/rack'
|
103
|
-
|
104
|
-
app = Alephant::Broker::RackApplication.new(config)
|
105
|
-
app.call(env)
|
106
|
-
```
|
107
115
|
|
108
|
-
## Contributing
|
109
116
|
|
110
|
-
1. Fork it ( http://github.com/<my-github-username>/alephant-broker/fork )
|
111
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
-
5. Create new Pull Request
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Jack
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -309,13 +309,11 @@ files:
|
|
309
309
|
- lib/alephant/broker/request/batch.rb
|
310
310
|
- lib/alephant/broker/request/factory.rb
|
311
311
|
- lib/alephant/broker/request/handler.rb
|
312
|
-
- lib/alephant/broker/request/multi.rb
|
313
312
|
- lib/alephant/broker/response.rb
|
314
313
|
- lib/alephant/broker/response/asset.rb
|
315
314
|
- lib/alephant/broker/response/base.rb
|
316
315
|
- lib/alephant/broker/response/batch.rb
|
317
316
|
- lib/alephant/broker/response/factory.rb
|
318
|
-
- lib/alephant/broker/response/multi.rb
|
319
317
|
- lib/alephant/broker/version.rb
|
320
318
|
- spec/component_meta_spec.rb
|
321
319
|
- spec/fixtures/json/batch.json
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'alephant/logger'
|
2
|
-
require 'alephant/broker/component'
|
3
|
-
|
4
|
-
module Alephant
|
5
|
-
module Broker
|
6
|
-
module Request
|
7
|
-
class Multi
|
8
|
-
include Logger
|
9
|
-
|
10
|
-
attr_reader :requests
|
11
|
-
|
12
|
-
def initialize(env)
|
13
|
-
logger.debug("Request::Multi#initialize(#{env.settings})")
|
14
|
-
@requests = requests_for env
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def requests_for(env)
|
20
|
-
env.data['requests'].map do |c|
|
21
|
-
case c['type']
|
22
|
-
when 'asset'
|
23
|
-
asset = Asset.new
|
24
|
-
|
25
|
-
component_id = c['payload']['component_id']
|
26
|
-
options = c['payload']['options']
|
27
|
-
|
28
|
-
component = Component.new(component_id, nil, options)
|
29
|
-
asset.tap { |a| a.component = component }
|
30
|
-
else
|
31
|
-
raise StandardError.new "request type not identified"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Alephant
|
4
|
-
module Broker
|
5
|
-
module Response
|
6
|
-
class Multi < Base
|
7
|
-
attr_reader :requests
|
8
|
-
|
9
|
-
POLLING_DELAY = 2
|
10
|
-
|
11
|
-
def initialize(requests)
|
12
|
-
@requests = requests
|
13
|
-
|
14
|
-
super()
|
15
|
-
end
|
16
|
-
|
17
|
-
def raw_response
|
18
|
-
requests.reduce(:delay => POLLING_DELAY, :responses => []) do |m,request|
|
19
|
-
response = Factory.response_for request
|
20
|
-
|
21
|
-
case response
|
22
|
-
when Asset
|
23
|
-
m[:responses] << {
|
24
|
-
:type => response.class.to_s.downcase,
|
25
|
-
:datatype => response.content_type,
|
26
|
-
:payload => {
|
27
|
-
:component_id => response.component.id,
|
28
|
-
:options => response.component.options,
|
29
|
-
:body => response.to_h
|
30
|
-
}
|
31
|
-
}
|
32
|
-
when NotFound
|
33
|
-
# Do nothing
|
34
|
-
else
|
35
|
-
raise StandardError.new "response type not identified"
|
36
|
-
end
|
37
|
-
|
38
|
-
m
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def setup
|
43
|
-
@content_type = 'application/json'
|
44
|
-
@content = JSON.generate(raw_response)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|