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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d0fba4a759155935e050a30431e65427f220f4d
4
- data.tar.gz: 0137552efcd8d64f3d9539938542b27ea2ab3544
3
+ metadata.gz: 71dd81ac255c7701b1676aa6f0e57d6c9913789e
4
+ data.tar.gz: 1ddc1f6954fe7302e9c87aba60ea0d1daee40b3d
5
5
  SHA512:
6
- metadata.gz: 4c0855c51f3d4d04f68b5772709f2d6174cdee95b15cb7e09198df64060b7c03ef66a323a3fd668e6f565cd96ccc2896c1be41a8086fbf7cb35940a478d387dd
7
- data.tar.gz: a025fa90065324a15f51be05633239bbfa0fe212cdd3b425c1e3ebc5ff8ee099acceec0dfc965139a6065df4412f5d1aa9f02e0a6961c9e6a50bd94403631aaf
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 stored in S3
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
- $ bundle
15
+ bundle install
18
16
 
19
17
  Or install it yourself as:
20
18
 
21
- $ gem install alephant-broker
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
- request = Alephant::Broker::Request.new('/component/id', 'variant=hello')
31
- config = {
32
- :bucket_id => "s3-render-example",
33
- :path => "foo",
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
- broker = Alephant::Broker.handle(request, config)
39
+ request = {
40
+ 'PATH_INFO' => '/component/foo',
41
+ 'QUERY_STRING' => 'variant=bar',
42
+ 'REQUEST_METHOD' => 'GET'
43
+ }
38
44
 
39
- # => #<Alephant::Broker::Response:0x5215005d
40
- # @content="<p>some HTML response</p>",
41
- # @content_type="text/html",
42
- # @status=200>
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
- ### Simple App
54
+ ##### HTML Load Strategy
46
55
 
47
56
  ```ruby
48
- require 'alephant/broker/app'
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
- config = {
51
- :bucket_id => "s3-render-example",
52
- :path => "foo",
53
- :lookup_table_name => "example_lookup"
66
+ request = {
67
+ 'PATH_INFO' => '/component/foo',
68
+ 'QUERY_STRING' => 'variant=bar',
69
+ 'REQUEST_METHOD' => 'GET'
54
70
  }
55
71
 
56
- app = Alephant::Broker::Application.new(config)
57
- request = app.request_from('/component/id', 'variant=hello')
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
- app.handle(request)
83
+ ### Rack App
60
84
 
61
- # => #<Alephant::Broker::Response:0x5215005d
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
- ### Rack
87
+ rackup config.ru
68
88
 
69
89
  ```ruby
70
- require 'alephant/broker/app/rack'
71
- require 'configuration'
72
-
73
- module Foo
74
- class Bar < Alephant::Broker::RackApplication
75
- def initialize
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
- ## Pry'ing
105
+ ## Contributing
83
106
 
84
- If you're using Pry to debug this gem...
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
- ```ruby
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
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'alephant/logger'
3
+ require 'rack'
3
4
 
4
5
  module Alephant
5
6
  module Broker
@@ -5,7 +5,6 @@ module Alephant
5
5
  require 'alephant/broker/request/batch'
6
6
  require 'alephant/broker/request/factory'
7
7
  require 'alephant/broker/request/handler'
8
- require 'alephant/broker/request/multi'
9
8
 
10
9
  class NotFound; end
11
10
  class Status; end
@@ -13,8 +13,6 @@ module Alephant
13
13
  component_factory = ComponentFactory.new load_strategy
14
14
 
15
15
  case request_type_from(env)
16
- when 'multi'
17
- Multi.new(env)
18
16
  when 'component'
19
17
  Asset.new(component_factory, env)
20
18
  when 'components'
@@ -4,7 +4,6 @@ module Alephant
4
4
  require 'alephant/broker/response/base'
5
5
  require 'alephant/broker/response/asset'
6
6
  require 'alephant/broker/response/batch'
7
- require 'alephant/broker/response/multi'
8
7
  require 'alephant/broker/response/factory'
9
8
 
10
9
  class NotFound < Base
@@ -10,8 +10,6 @@ module Alephant
10
10
  Asset.new(request.component)
11
11
  when Request::Batch
12
12
  Batch.new(request.components, request.batch_id)
13
- when Request::Multi
14
- Multi.new(request.requests)
15
13
  when Request::Status
16
14
  Status.new
17
15
  else
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Broker
3
- VERSION = "2.1.3"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
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: 2.1.3
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-06 00:00:00.000000000 Z
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