opencomponents 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/LICENSE +22 -0
- data/README.md +41 -0
- data/lib/opencomponents.rb +22 -0
- data/lib/opencomponents/component.rb +71 -0
- data/lib/opencomponents/prerendered_component.rb +22 -0
- data/lib/opencomponents/rendered_component.rb +17 -0
- data/lib/opencomponents/renderer.rb +9 -0
- data/lib/opencomponents/version.rb +3 -0
- data/opencomponents.gemspec +23 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8ad282648e755c0c28348bb1b2c243892bc4c100
|
4
|
+
data.tar.gz: bbee3ca89a7c5b264a7e8b17872efed62f711989
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0bbfa189e576fd2e24ac401f159adf483d78e67e16a57ba44e87c598e1e493e7d0d87abdb5e121ca58d67adf5b358274c0bcbb4106e48246ec5dbf0c503a77cb
|
7
|
+
data.tar.gz: 03b8c7878cb230499a3f6c5a4e0f1c79684eff6c222c8c76525af770f2267b749eca7f2efef535517c18adb87c27bc334d9318464928342e15c67a7ccd7aed94
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 OpenTable
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# opencomponents
|
2
|
+
[![Build Status](https://travis-ci.org/opentable/ruby-oc.svg?branch=master)](https://travis-ci.org/opentable/ruby-oc)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/opentable/ruby-oc/badge.svg)](https://coveralls.io/r/opentable/ruby-oc)
|
4
|
+
|
5
|
+
[OpenComponents][1] for Ruby
|
6
|
+
|
7
|
+
[1]:https://github.com/opentable/oc
|
8
|
+
|
9
|
+
## Important
|
10
|
+
This gem is still under heavy development and the API is likely to change at any
|
11
|
+
time.
|
12
|
+
|
13
|
+
## Getting Started
|
14
|
+
Add the gem to your Gemfile and run `bundle install` (prerelease versions aren't
|
15
|
+
on RubyGems):
|
16
|
+
```ruby
|
17
|
+
gem 'opencomponents', github: 'opentable/ruby-oc'
|
18
|
+
```
|
19
|
+
|
20
|
+
By default, the gem will attempt to use a component registry located at
|
21
|
+
`http://localhost:3030`.
|
22
|
+
If you want to use a different registry, you can configure OpenComponents to use
|
23
|
+
it with:
|
24
|
+
```ruby
|
25
|
+
OpenComponents.configure { |config| config.registry = 'http://some.other.host' }
|
26
|
+
```
|
27
|
+
|
28
|
+
## Integrations
|
29
|
+
Individual integrations for rendering components in Rails and Sinatra are
|
30
|
+
available.
|
31
|
+
* [opencomponents-rails][2]
|
32
|
+
* [sinatra-opencomponents][3]
|
33
|
+
|
34
|
+
[2]:https://github.com/opentable/opencomponents-rails
|
35
|
+
[3]:https://github.com/opentable/sinatra-opencomponents
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
Would be rad. Open a PR or Issue if you have an idea for improvements.
|
39
|
+
|
40
|
+
## License
|
41
|
+
Copyright 2015 OpenTable. See LICENSE for details.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'opencomponents/component'
|
2
|
+
require 'opencomponents/prerendered_component'
|
3
|
+
require 'opencomponents/rendered_component'
|
4
|
+
require 'opencomponents/renderer'
|
5
|
+
require 'opencomponents/version'
|
6
|
+
|
7
|
+
module OpenComponents
|
8
|
+
DEFAULT_REGISTRY = 'http://localhost:3030'
|
9
|
+
|
10
|
+
ComponentNotFound = Class.new(RuntimeError)
|
11
|
+
|
12
|
+
Configuration = Struct.new(:registry)
|
13
|
+
Template = Struct.new(:src, :type, :key)
|
14
|
+
|
15
|
+
def self.config
|
16
|
+
@@_config ||= Configuration.new(DEFAULT_REGISTRY)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
yield self.config
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module OpenComponents
|
4
|
+
class Component
|
5
|
+
attr_reader :name, :version, :params, :href, :registry_version,
|
6
|
+
:type, :render_mode
|
7
|
+
|
8
|
+
def initialize(name, params = {}, version = '')
|
9
|
+
@name = name
|
10
|
+
@params = params
|
11
|
+
@version = version
|
12
|
+
end
|
13
|
+
|
14
|
+
def request_version
|
15
|
+
@request_version == '' ? nil : @request_version
|
16
|
+
end
|
17
|
+
|
18
|
+
def flush!
|
19
|
+
flush_variables_whitelist.each do |var|
|
20
|
+
instance_variable_set(var, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def reload!
|
27
|
+
flush!
|
28
|
+
load
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def load
|
34
|
+
@href = response_data['href']
|
35
|
+
@registry_version = response_data['version']
|
36
|
+
@request_version = response_data['requestVersion']
|
37
|
+
@type = response_data['type']
|
38
|
+
@render_mode = response_data['renderMode']
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def url
|
44
|
+
File.join(OpenComponents.config.registry, name, version)
|
45
|
+
end
|
46
|
+
|
47
|
+
def response
|
48
|
+
RestClient::Request.execute(
|
49
|
+
method: :get,
|
50
|
+
url: url,
|
51
|
+
timeout: 10,
|
52
|
+
headers: {
|
53
|
+
accept: accept_header,
|
54
|
+
params: params,
|
55
|
+
}
|
56
|
+
)
|
57
|
+
rescue RestClient::ResourceNotFound => e
|
58
|
+
fail ComponentNotFound, e.message
|
59
|
+
end
|
60
|
+
|
61
|
+
def response_data
|
62
|
+
@_response_data ||= JSON.parse(response)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def flush_variables_whitelist
|
68
|
+
instance_variables - [:@name, :@version, :@params]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module OpenComponents
|
2
|
+
class PrerenderedComponent < Component
|
3
|
+
attr_reader :data, :template
|
4
|
+
|
5
|
+
def load
|
6
|
+
template_data = response_data['template']
|
7
|
+
|
8
|
+
@data = response_data['data']
|
9
|
+
@template = Template.new(
|
10
|
+
template_data['src'], template_data['type'], template_data['key']
|
11
|
+
)
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def accept_header
|
19
|
+
'application/vnd.oc.prerendered+json'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'opencomponents/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.required_ruby_version = '>= 1.9.3'
|
8
|
+
|
9
|
+
spec.add_dependency 'rest-client', '~> 1.8'
|
10
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
11
|
+
|
12
|
+
spec.authors = ['Todd Bealmear']
|
13
|
+
spec.description = %q{Consume OpenComponents in Ruby}
|
14
|
+
spec.email = ['tbealmear@opentable.com']
|
15
|
+
spec.files = %w(LICENSE README.md opencomponents.gemspec)
|
16
|
+
spec.files += Dir.glob('lib/**/*.rb')
|
17
|
+
spec.homepage = 'https://github.com/opentable/ruby-oc'
|
18
|
+
spec.licenses = ['MIT']
|
19
|
+
spec.name = 'opencomponents'
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
spec.summary = spec.description
|
22
|
+
spec.version = OpenComponents::VERSION
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opencomponents
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Bealmear
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
description: Consume OpenComponents in Ruby
|
42
|
+
email:
|
43
|
+
- tbealmear@opentable.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- lib/opencomponents.rb
|
51
|
+
- lib/opencomponents/component.rb
|
52
|
+
- lib/opencomponents/prerendered_component.rb
|
53
|
+
- lib/opencomponents/rendered_component.rb
|
54
|
+
- lib/opencomponents/renderer.rb
|
55
|
+
- lib/opencomponents/version.rb
|
56
|
+
- opencomponents.gemspec
|
57
|
+
homepage: https://github.com/opentable/ruby-oc
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.9.3
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Consume OpenComponents in Ruby
|
81
|
+
test_files: []
|