alephant-publisher-request 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/README.md +20 -8
- data/lib/alephant/publisher/request.rb +3 -1
- data/lib/alephant/publisher/request/data_mapper.rb +8 -0
- data/lib/alephant/publisher/request/data_mapper_factory.rb +7 -0
- data/lib/alephant/publisher/request/processor.rb +1 -0
- data/lib/alephant/publisher/request/version.rb +1 -1
- metadata +64 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 636d57a2d11137dff5db768d01ca82ecb182d16b
|
4
|
+
data.tar.gz: 967fcecc92c5208f88247ee5b9ea3f32c23336b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39927e50459406de2270cac19444387d5964d19f51f075268a0cadb8dde2341a1d1dad1656a00d7f444a996b08ed724de89f498a30750a93da83b9d04f1de7e8
|
7
|
+
data.tar.gz: c56b87f5bbe539d9f3beac9284ba9eb524a02fcec128ce89bb1a2d4ec7f594bccf3e9fb3dee561298230d4f401d21a06492f8b5c01c7f9cb792f322d35b8a88e
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-1.7
|
data/README.md
CHANGED
@@ -10,10 +10,20 @@ Dynamic publishing based on data from an API.
|
|
10
10
|
|
11
11
|
## Migrating from [Alephant::Publisher](https://github.com/BBC-News/alephant-publisher)
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
Add the new gem to your Gemfile:
|
14
|
+
|
15
|
+
gem 'alephant-publisher-request'
|
16
|
+
|
17
|
+
Run:
|
18
|
+
|
19
|
+
bundle install
|
20
|
+
|
21
|
+
Require the new gem in your app:
|
22
|
+
|
23
|
+
require 'alephant/publisher/request'
|
24
|
+
|
25
|
+
|
26
|
+
**Note** - the namespace has changed from `Alephant::Publisher` to `Alephant::Publisher::Request`.
|
17
27
|
|
18
28
|
## Installation
|
19
29
|
|
@@ -31,7 +41,7 @@ Or install it yourself as:
|
|
31
41
|
|
32
42
|
## Setup
|
33
43
|
|
34
|
-
You need to run the gem as a rack application, and pass it the
|
44
|
+
You need to run the gem as a rack application, and pass it the necessary dependencies. Below is a simple example of the minimum needed to run the server:
|
35
45
|
|
36
46
|
### Folder structure
|
37
47
|
|
@@ -56,7 +66,7 @@ The model must extend either the JSON or HTML base from the [alephant-renderer](
|
|
56
66
|
require 'alephant/renderer/views/html'
|
57
67
|
|
58
68
|
module SomeNameSpace
|
59
|
-
class MyTestComponent Alephant::Renderer::Views::Html
|
69
|
+
class MyTestComponent < Alephant::Renderer::Views::Html
|
60
70
|
|
61
71
|
def some_method
|
62
72
|
@body.some_method
|
@@ -127,7 +137,7 @@ end
|
|
127
137
|
The server is a simple rack server, so you just need to run:
|
128
138
|
|
129
139
|
```bash
|
130
|
-
|
140
|
+
rackup
|
131
141
|
```
|
132
142
|
|
133
143
|
in the `src` directory where the `config.ru` file is.
|
@@ -187,4 +197,6 @@ PREVIEW_TEMPLATE_URL="http://yourapp.com/template"
|
|
187
197
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
188
198
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
189
199
|
4. Push to the branch (`git push origin my-new-feature`)
|
190
|
-
5. Create new Pull Request
|
200
|
+
5. Create new [Pull Request](https://github.com/BBC-News/alephant-publisher-request/pulls).
|
201
|
+
|
202
|
+
Feel free to create an [issue](https://github.com/BBC-News/alephant-publisher-request/issues/new) if you find a bug.
|
@@ -8,13 +8,14 @@ require 'alephant/publisher/request/error'
|
|
8
8
|
module Alephant
|
9
9
|
module Publisher
|
10
10
|
module Request
|
11
|
-
include Logger
|
12
11
|
|
13
12
|
def self.create(processor, data_mapper_factory, opts = {})
|
14
13
|
Request.new(processor, data_mapper_factory, opts)
|
15
14
|
end
|
16
15
|
|
17
16
|
class Request
|
17
|
+
include Logger
|
18
|
+
|
18
19
|
attr_reader :processor, :data_mapper_factory, :opts
|
19
20
|
|
20
21
|
DEFAULT_CONTENT_TYPE = { "Content-Type" => "text/html" }
|
@@ -65,6 +66,7 @@ module Alephant
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def error_response(e = '', code = 500)
|
69
|
+
logger.metric(:name => "PublisherRequestErrorResponseStatus#{code}", :unit => "Count", :value => 1)
|
68
70
|
message = opts.fetch(:debug, false) ? e.message : ''
|
69
71
|
Rack::Response.new(message, code, DEFAULT_CONTENT_TYPE).finish
|
70
72
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
+
require 'alephant/logger'
|
1
2
|
require 'json'
|
2
3
|
|
3
4
|
module Alephant
|
4
5
|
module Publisher
|
5
6
|
module Request
|
6
7
|
class DataMapper
|
8
|
+
include Logger
|
9
|
+
|
7
10
|
attr_reader :connection, :context
|
8
11
|
|
9
12
|
def initialize(connection, context = {})
|
@@ -18,14 +21,19 @@ module Alephant
|
|
18
21
|
protected
|
19
22
|
|
20
23
|
def get(uri)
|
24
|
+
before = Time.new
|
21
25
|
response = connection.get(uri)
|
22
26
|
raise InvalidApiResponse, "Status: #{response.status}" unless response.status == 200
|
27
|
+
logger.metric(:name => "PublisherRequestDataMapperRequestHTTPTime", :unit => 'Seconds', :value => Time.new - before)
|
23
28
|
JSON::parse(response.body, :symbolize_names => true)
|
24
29
|
rescue Faraday::ConnectionFailed
|
30
|
+
logger.metric(:name => "PublisherRequestDataMapperConnectionFailed", :unit => "Count", :value => 1)
|
25
31
|
raise ConnectionFailed
|
26
32
|
rescue JSON::ParserError
|
33
|
+
logger.metric(:name => "PublisherRequestDataMapperInvalidApiResponse", :unit => "Count", :value => 1)
|
27
34
|
raise InvalidApiResponse, "JSON parsing error: #{response.body}"
|
28
35
|
rescue StandardError => e
|
36
|
+
logger.metric(:name => "PublisherRequestDataMapperApiError", :unit => "Count", :value => 1)
|
29
37
|
raise ApiError, e.message
|
30
38
|
end
|
31
39
|
|
@@ -1,7 +1,11 @@
|
|
1
|
+
require 'alephant/logger'
|
2
|
+
|
1
3
|
module Alephant
|
2
4
|
module Publisher
|
3
5
|
module Request
|
4
6
|
class DataMapperFactory
|
7
|
+
include Logger
|
8
|
+
|
5
9
|
attr_reader :connection, :base_path
|
6
10
|
|
7
11
|
def initialize(connection, base_path)
|
@@ -16,10 +20,13 @@ module Alephant
|
|
16
20
|
klass = mapper_class_for(component_id)
|
17
21
|
klass.new(connection, context)
|
18
22
|
rescue LoadError
|
23
|
+
logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponentName", :unit => "Count", :value => 1)
|
19
24
|
raise InvalidComponentName, "Invalid component name: #{component_id}"
|
20
25
|
rescue NameError
|
26
|
+
logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponentClassName", :unit => "Count", :value => 1)
|
21
27
|
raise InvalidComponentClassName, "Invalid class name #{klass}"
|
22
28
|
rescue
|
29
|
+
logger.metric(:name => "PublisherRequestDataMapperFactoryInvalidComponent", :unit => "Count", :value => 1)
|
23
30
|
raise InvalidComponent, "Name: #{component_id}, Class: #{klass}"
|
24
31
|
end
|
25
32
|
|
metadata
CHANGED
@@ -1,239 +1,239 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-publisher-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
|
-
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
|
-
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
23
21
|
requirements:
|
24
22
|
- - ~>
|
25
23
|
- !ruby/object:Gem::Version
|
26
24
|
version: '1.5'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
29
34
|
requirement: !ruby/object:Gem::Requirement
|
30
35
|
requirements:
|
31
36
|
- - '>='
|
32
37
|
- !ruby/object:Gem::Version
|
33
38
|
version: '0'
|
34
|
-
type: :development
|
35
39
|
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-nc
|
36
43
|
version_requirements: !ruby/object:Gem::Requirement
|
37
44
|
requirements:
|
38
45
|
- - '>='
|
39
46
|
- !ruby/object:Gem::Version
|
40
47
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec-nc
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
44
49
|
requirements:
|
45
50
|
- - '>='
|
46
51
|
- !ruby/object:Gem::Version
|
47
52
|
version: '0'
|
48
|
-
type: :development
|
49
53
|
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
50
57
|
version_requirements: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: guard
|
57
62
|
requirement: !ruby/object:Gem::Requirement
|
58
63
|
requirements:
|
59
64
|
- - '>='
|
60
65
|
- !ruby/object:Gem::Version
|
61
66
|
version: '0'
|
62
|
-
type: :development
|
63
67
|
prerelease: false
|
68
|
+
type: :development
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rake
|
64
71
|
version_requirements: !ruby/object:Gem::Requirement
|
65
72
|
requirements:
|
66
73
|
- - '>='
|
67
74
|
- !ruby/object:Gem::Version
|
68
75
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard-rake
|
71
76
|
requirement: !ruby/object:Gem::Requirement
|
72
77
|
requirements:
|
73
78
|
- - '>='
|
74
79
|
- !ruby/object:Gem::Version
|
75
80
|
version: '0'
|
76
|
-
type: :development
|
77
81
|
prerelease: false
|
82
|
+
type: :development
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
78
85
|
version_requirements: !ruby/object:Gem::Requirement
|
79
86
|
requirements:
|
80
87
|
- - '>='
|
81
88
|
- !ruby/object:Gem::Version
|
82
89
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: pry
|
85
90
|
requirement: !ruby/object:Gem::Requirement
|
86
91
|
requirements:
|
87
92
|
- - '>='
|
88
93
|
- !ruby/object:Gem::Version
|
89
94
|
version: '0'
|
90
|
-
type: :development
|
91
95
|
prerelease: false
|
96
|
+
type: :development
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rack-test
|
92
99
|
version_requirements: !ruby/object:Gem::Requirement
|
93
100
|
requirements:
|
94
101
|
- - '>='
|
95
102
|
- !ruby/object:Gem::Version
|
96
103
|
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rack-test
|
99
104
|
requirement: !ruby/object:Gem::Requirement
|
100
105
|
requirements:
|
101
106
|
- - '>='
|
102
107
|
- !ruby/object:Gem::Version
|
103
108
|
version: '0'
|
104
|
-
type: :development
|
105
109
|
prerelease: false
|
110
|
+
type: :development
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: spurious-ruby-awssdk-helper
|
106
113
|
version_requirements: !ruby/object:Gem::Requirement
|
107
114
|
requirements:
|
108
115
|
- - '>='
|
109
116
|
- !ruby/object:Gem::Version
|
110
117
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: spurious-ruby-awssdk-helper
|
113
118
|
requirement: !ruby/object:Gem::Requirement
|
114
119
|
requirements:
|
115
120
|
- - '>='
|
116
121
|
- !ruby/object:Gem::Version
|
117
122
|
version: '0'
|
118
|
-
type: :development
|
119
123
|
prerelease: false
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rake-rspec
|
120
127
|
version_requirements: !ruby/object:Gem::Requirement
|
121
128
|
requirements:
|
122
129
|
- - '>='
|
123
130
|
- !ruby/object:Gem::Version
|
124
131
|
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rake-rspec
|
127
132
|
requirement: !ruby/object:Gem::Requirement
|
128
133
|
requirements:
|
129
134
|
- - '>='
|
130
135
|
- !ruby/object:Gem::Version
|
131
136
|
version: '0'
|
132
|
-
type: :development
|
133
137
|
prerelease: false
|
138
|
+
type: :development
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rack
|
134
141
|
version_requirements: !ruby/object:Gem::Requirement
|
135
142
|
requirements:
|
136
143
|
- - '>='
|
137
144
|
- !ruby/object:Gem::Version
|
138
145
|
version: '0'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rack
|
141
146
|
requirement: !ruby/object:Gem::Requirement
|
142
147
|
requirements:
|
143
148
|
- - '>='
|
144
149
|
- !ruby/object:Gem::Version
|
145
150
|
version: '0'
|
146
|
-
type: :runtime
|
147
151
|
prerelease: false
|
152
|
+
type: :runtime
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rake
|
148
155
|
version_requirements: !ruby/object:Gem::Requirement
|
149
156
|
requirements:
|
150
157
|
- - '>='
|
151
158
|
- !ruby/object:Gem::Version
|
152
159
|
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rake
|
155
160
|
requirement: !ruby/object:Gem::Requirement
|
156
161
|
requirements:
|
157
162
|
- - '>='
|
158
163
|
- !ruby/object:Gem::Version
|
159
164
|
version: '0'
|
160
|
-
type: :runtime
|
161
165
|
prerelease: false
|
166
|
+
type: :runtime
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: faraday
|
162
169
|
version_requirements: !ruby/object:Gem::Requirement
|
163
170
|
requirements:
|
164
171
|
- - '>='
|
165
172
|
- !ruby/object:Gem::Version
|
166
173
|
version: '0'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: faraday
|
169
174
|
requirement: !ruby/object:Gem::Requirement
|
170
175
|
requirements:
|
171
176
|
- - '>='
|
172
177
|
- !ruby/object:Gem::Version
|
173
178
|
version: '0'
|
174
|
-
type: :runtime
|
175
179
|
prerelease: false
|
176
|
-
|
177
|
-
requirements:
|
178
|
-
- - '>='
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
180
|
+
type: :runtime
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: aws-sdk
|
183
|
-
|
183
|
+
version_requirements: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
185
|
- - ~>
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '1.0'
|
188
|
-
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
188
|
+
requirement: !ruby/object:Gem::Requirement
|
191
189
|
requirements:
|
192
190
|
- - ~>
|
193
191
|
- !ruby/object:Gem::Version
|
194
192
|
version: '1.0'
|
193
|
+
prerelease: false
|
194
|
+
type: :runtime
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: mustache
|
197
|
-
|
197
|
+
version_requirements: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - '>='
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: 0.99.5
|
202
|
-
|
203
|
-
prerelease: false
|
204
|
-
version_requirements: !ruby/object:Gem::Requirement
|
202
|
+
requirement: !ruby/object:Gem::Requirement
|
205
203
|
requirements:
|
206
204
|
- - '>='
|
207
205
|
- !ruby/object:Gem::Version
|
208
206
|
version: 0.99.5
|
207
|
+
prerelease: false
|
208
|
+
type: :runtime
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: alephant-logger
|
211
|
-
|
211
|
+
version_requirements: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - '>='
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
|
-
|
217
|
-
prerelease: false
|
218
|
-
version_requirements: !ruby/object:Gem::Requirement
|
216
|
+
requirement: !ruby/object:Gem::Requirement
|
219
217
|
requirements:
|
220
218
|
- - '>='
|
221
219
|
- !ruby/object:Gem::Version
|
222
220
|
version: '0'
|
221
|
+
prerelease: false
|
222
|
+
type: :runtime
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: alephant-renderer
|
225
|
-
|
225
|
+
version_requirements: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - '>='
|
228
228
|
- !ruby/object:Gem::Version
|
229
229
|
version: '0'
|
230
|
-
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
230
|
+
requirement: !ruby/object:Gem::Requirement
|
233
231
|
requirements:
|
234
232
|
- - '>='
|
235
233
|
- !ruby/object:Gem::Version
|
236
234
|
version: '0'
|
235
|
+
prerelease: false
|
236
|
+
type: :runtime
|
237
237
|
description: '...'
|
238
238
|
email:
|
239
239
|
- mark.mcdx@gmail.com
|
@@ -242,6 +242,7 @@ extensions: []
|
|
242
242
|
extra_rdoc_files: []
|
243
243
|
files:
|
244
244
|
- .gitignore
|
245
|
+
- .ruby-version
|
245
246
|
- .travis.yml
|
246
247
|
- Gemfile
|
247
248
|
- Guardfile
|
@@ -272,7 +273,7 @@ homepage: https://github.com/BBC-News/alephant-publisher-request
|
|
272
273
|
licenses:
|
273
274
|
- MIT
|
274
275
|
metadata: {}
|
275
|
-
post_install_message:
|
276
|
+
post_install_message:
|
276
277
|
rdoc_options: []
|
277
278
|
require_paths:
|
278
279
|
- lib
|
@@ -287,9 +288,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
288
|
- !ruby/object:Gem::Version
|
288
289
|
version: '0'
|
289
290
|
requirements: []
|
290
|
-
rubyforge_project:
|
291
|
-
rubygems_version: 2.
|
292
|
-
signing_key:
|
291
|
+
rubyforge_project:
|
292
|
+
rubygems_version: 2.1.9
|
293
|
+
signing_key:
|
293
294
|
specification_version: 4
|
294
295
|
summary: '...'
|
295
296
|
test_files:
|