grape-hypertext_application_language 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +74 -0
- data/Rakefile +1 -0
- data/grape-hypertext_application_language.gemspec +18 -0
- data/lib/grape-hypertext_application_language.rb +2 -0
- data/lib/grape/formatter/hal/json.rb +45 -0
- data/lib/grape/hal/content_types.rb +3 -0
- data/lib/grape/hal/formatter.rb +3 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b245bf5afb49fb907aad0b188ab89afee06abda
|
4
|
+
data.tar.gz: dd47cc9a8a73b730f6ab26fcf07c3af905b51c65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5145c5bb772a3a1d9067a8416c651b6e463249ee3a0170256642033a5917ade612b91f551b57c5785a064499d807dd3dcbb493742acb72d9f4d8df7f38b1514d
|
7
|
+
data.tar.gz: 1635e2f63cb76132bed732fbd73e788d792063e381e0a840b27b45e8fcbd5fec0f7385e363ece17a63ad9020198e451156b2b2783c03d2ec5c1fd5a6f4eafed3
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
grape-hypertext_application_language (0.0.0)
|
5
|
+
addressable
|
6
|
+
grape
|
7
|
+
hypertext_application_language
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (4.2.4)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
addressable (2.3.8)
|
19
|
+
axiom-types (0.1.1)
|
20
|
+
descendants_tracker (~> 0.0.4)
|
21
|
+
ice_nine (~> 0.11.0)
|
22
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
23
|
+
builder (3.2.2)
|
24
|
+
coercible (1.0.0)
|
25
|
+
descendants_tracker (~> 0.0.1)
|
26
|
+
descendants_tracker (0.0.4)
|
27
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
28
|
+
equalizer (0.0.11)
|
29
|
+
grape (0.13.0)
|
30
|
+
activesupport
|
31
|
+
builder
|
32
|
+
hashie (>= 2.1.0)
|
33
|
+
multi_json (>= 1.3.2)
|
34
|
+
multi_xml (>= 0.5.2)
|
35
|
+
rack (>= 1.3.0)
|
36
|
+
rack-accept
|
37
|
+
rack-mount
|
38
|
+
virtus (>= 1.0.0)
|
39
|
+
hashie (3.4.3)
|
40
|
+
hypertext_application_language (0.0.1)
|
41
|
+
i18n (0.7.0)
|
42
|
+
ice_nine (0.11.1)
|
43
|
+
json (1.8.3)
|
44
|
+
json (1.8.3-java)
|
45
|
+
minitest (5.8.2)
|
46
|
+
multi_json (1.11.2)
|
47
|
+
multi_xml (0.5.5)
|
48
|
+
rack (1.6.4)
|
49
|
+
rack-accept (0.4.5)
|
50
|
+
rack (>= 0.4)
|
51
|
+
rack-mount (0.8.3)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rake (10.4.2)
|
54
|
+
thread_safe (0.3.5)
|
55
|
+
thread_safe (0.3.5-java)
|
56
|
+
tzinfo (1.2.2)
|
57
|
+
thread_safe (~> 0.1)
|
58
|
+
virtus (1.0.5)
|
59
|
+
axiom-types (~> 0.1)
|
60
|
+
coercible (~> 1.0)
|
61
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
62
|
+
equalizer (~> 0.0, >= 0.0.9)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
java
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
bundler
|
70
|
+
grape-hypertext_application_language!
|
71
|
+
rake
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
1.10.6
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'grape-hypertext_application_language'
|
3
|
+
spec.version = '0.0.0'
|
4
|
+
spec.summary = %q{Grape extensions for Hypertext Application Language}
|
5
|
+
spec.description = %q{}
|
6
|
+
spec.homepage = 'http://stateless.co/hal_specification.html'
|
7
|
+
spec.authors = ['Roy Ratcliffe']
|
8
|
+
spec.email = ['roy@pioneeringsoftware.co.uk']
|
9
|
+
spec.files = `git ls-files -z`.split("\x0")
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
spec.add_dependency 'grape'
|
13
|
+
spec.add_dependency 'hypertext_application_language'
|
14
|
+
spec.add_dependency 'addressable'
|
15
|
+
|
16
|
+
spec.add_development_dependency 'bundler'
|
17
|
+
spec.add_development_dependency 'rake'
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'grape'
|
2
|
+
require 'hypertext_application_language'
|
3
|
+
require 'addressable/uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Grape::Formatter::Hal
|
7
|
+
class Json
|
8
|
+
# Formats a Grape end-point body using JSON-formatted hypertext application
|
9
|
+
# language. Assumes that the body is a hypertext-application-language
|
10
|
+
# representation, either a resource or collection of resources.
|
11
|
+
#
|
12
|
+
# Derives the end-point's request URL using only the plain Rack environment
|
13
|
+
# if necessary; doing so assumes nothing about any higher-level framework,
|
14
|
+
# e.g. Grape or Sinatra. Uses the base URL to adjust all the relative
|
15
|
+
# hypertext references. They become absolute references; meaning not
|
16
|
+
# relative, i.e. the reference does not include a scheme. Applies this
|
17
|
+
# adjustment to the representation itself as well as all the embedded
|
18
|
+
# representations if any.
|
19
|
+
#
|
20
|
+
# Automatically converts the body to a hypertext-application-language
|
21
|
+
# representation unless the body is already such a HAL
|
22
|
+
# representation. Passes the Rack environment to the HAL
|
23
|
+
# converter. Converters can use the environment to extract addressing
|
24
|
+
# information for the representation's links, including the self link.
|
25
|
+
def self.call(body, env)
|
26
|
+
unless body.is_a?(HypertextApplicationLanguage::Representation)
|
27
|
+
return body unless body.respond_to?(:to_hal)
|
28
|
+
body = body.to_hal(env: env)
|
29
|
+
end
|
30
|
+
|
31
|
+
endpoint = env['api.endpoint']
|
32
|
+
request = endpoint ? endpoint.request : Rack::Request.new(env)
|
33
|
+
base_uri = Addressable::URI.parse(request.base_url + request.script_name + '/')
|
34
|
+
|
35
|
+
representations = [body] + body.representations
|
36
|
+
representations.map(&:links).flatten.each do |link|
|
37
|
+
uri = Addressable::URI.parse(link.href)
|
38
|
+
link.href = base_uri.join(uri).to_s unless uri.absolute?
|
39
|
+
end
|
40
|
+
|
41
|
+
renderer = HypertextApplicationLanguage::HashRepresentationRenderer.new
|
42
|
+
JSON.pretty_generate(renderer.render(body))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grape-hypertext_application_language
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Roy Ratcliffe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: grape
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: hypertext_application_language
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
name: addressable
|
48
|
+
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
name: rake
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- roy@pioneeringsoftware.co.uk
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- Gemfile.lock
|
93
|
+
- Rakefile
|
94
|
+
- grape-hypertext_application_language.gemspec
|
95
|
+
- lib/grape-hypertext_application_language.rb
|
96
|
+
- lib/grape/formatter/hal/json.rb
|
97
|
+
- lib/grape/hal/content_types.rb
|
98
|
+
- lib/grape/hal/formatter.rb
|
99
|
+
homepage: http://stateless.co/hal_specification.html
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.4.8
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Grape extensions for Hypertext Application Language
|
123
|
+
test_files: []
|