braque 0.1.8 → 0.1.9

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: 1301ea8c8cb20ba8d4bf8785c56d43483e39f5c9
4
- data.tar.gz: a105f99e589ed6be0ed3a5144b8c0ed3e83d08c2
3
+ metadata.gz: a0ddfaefee109436ddbfe02b0a024edbe5e0830e
4
+ data.tar.gz: ee7bcc93c2b425356f9554d9677854f745306419
5
5
  SHA512:
6
- metadata.gz: ede1d3e637ae1b3dd5f2830c4043bfbf1762c624040ab2d047c3ce2b00fb9d09cc38ee3641ca0906457fdb4a4c69d4526038b46960cc007bbe52007f651e7b5e
7
- data.tar.gz: 34aa058fdc69bc3668315ad6a2b6d31d10eaf11b8bb93031264731a5275e9f5502f35a78244a3f3f5abb80e92f2cd8d18b681534e1560d8f6d50b00e8be1e6cf
6
+ metadata.gz: 4895d854ef8cdcf5d81e4f364a975dd23c613a6a8d4605e632494c6b105b8662d77bdbd2c0585be41936dc59bbb4136008396bd415eb824906d7ea39c69f5e1b
7
+ data.tar.gz: a5c60d89dfdf39e9bb873874d75d8c6d99785f6c79bfe24f1f11e5f2410023e3cf9aadfee248d63fd96cd7b59bf7fe322c836ca3e49e6b14a0b1ddc65879cc9e
@@ -1,3 +1,3 @@
1
1
  module Braque
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-06 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hyperclient
@@ -64,14 +64,11 @@ files:
64
64
  - README.md
65
65
  - lib/braque.rb
66
66
  - lib/braque/collection.rb
67
- - lib/braque/helpers.rb
68
- - lib/braque/helpers/hypermedia_responses_helper.rb
69
67
  - lib/braque/model.rb
70
68
  - lib/braque/version.rb
71
69
  - spec/braque/api_root_spec.rb
72
70
  - spec/braque/client_headers_spec.rb
73
71
  - spec/braque/collection_spec.rb
74
- - spec/braque/helpers/hypermedia_responses_helper_spec.rb
75
72
  - spec/braque/model_attributes_spec.rb
76
73
  - spec/braque/model_spec.rb
77
74
  - spec/braque/multiple_model_spec.rb
@@ -1,56 +0,0 @@
1
- module Braque
2
- module Helpers
3
- module HypermediaResponsesHelper
4
- def hypermedia_root_json_for(hyperclient_model_class, options = {})
5
- collection_query_options = options[:collection_query] || '{?page,size}'
6
- resource_path_options = options[:resource_path] || '{id}'
7
- root_hash = {}
8
- root_hash[:_links] = {}
9
- root_hash[:_links][:self] = { href: hyperclient_model_class.config[:api_root_url] }
10
- root_hash[:_links][hyperclient_model_class.collection_method_name] = { href: "#{hyperclient_model_class.config[:api_root_url]}/#{hyperclient_model_class.collection_method_name}#{collection_query_options}", templated: true }
11
- root_hash[:_links][hyperclient_model_class.instance_method_name] = { href: "#{hyperclient_model_class.config[:api_root_url]}/#{hyperclient_model_class.collection_method_name}/#{resource_path_options}", templated: true }
12
- JSON.parse root_hash.to_json
13
- end
14
-
15
- def hypermedia_collection_json_for(hyperclient_model_collection, options = {})
16
- hyperclient_model = hyperclient_model_collection.first
17
- collection_hash = {}
18
- collection_hash[:total_count] = 1
19
- collection_hash[:total_pages] = 1
20
- collection_hash[:current_page] = 1
21
- collection_hash[:_links] = {}
22
- collection_hash[:_links][:self] = { href: "#{hyperclient_model.class.config[:api_root_url]}/#{hyperclient_model.class.collection_method_name}" }
23
- collection_hash[:_links][:next] = { href: "#{hyperclient_model.class.config[:api_root_url]}/#{hyperclient_model.class.collection_method_name}" }
24
- collection_hash[:_links][:prev] = { href: "#{hyperclient_model.class.config[:api_root_url]}/#{hyperclient_model.class.collection_method_name}" }
25
- collection_hash[:_embedded] = {}
26
- collection_hash[:_embedded][hyperclient_model.class.collection_method_name] = embedded_elements_for_collection(hyperclient_model_collection, options)
27
- JSON.parse collection_hash.to_json
28
- end
29
-
30
- def hypermedia_resource_json_for(hyperclient_model, options = {})
31
- resource_hash = embedded_element(hyperclient_model, options)
32
- JSON.parse resource_hash.to_json
33
- end
34
-
35
- def embedded_elements_for_collection(hyperclient_model_collection, options = {})
36
- embedded_elements = []
37
- hyperclient_model_collection.each do |model|
38
- embedded_elements << embedded_element(model, options)
39
- end
40
- embedded_elements
41
- end
42
-
43
- def embedded_element(model, options = {})
44
- resource_path_str = eval(options[:resource_path].to_s) if options[:resource_path]
45
- resource_path = resource_path_str || model.id
46
- hyperclient_element = {}
47
- model.attributes.each_key do |key|
48
- hyperclient_element[key] = model.send(key)
49
- end
50
- hyperclient_element[:_links] = {}
51
- hyperclient_element[:_links][:self] = { href: "#{model.class.config[:api_root_url]}/#{model.class.collection_method_name}/#{resource_path}" }
52
- hyperclient_element
53
- end
54
- end
55
- end
56
- end
@@ -1,6 +0,0 @@
1
- require 'braque/helpers/hypermedia_responses_helper'
2
-
3
- module Braque
4
- module Helpers
5
- end
6
- end
@@ -1,147 +0,0 @@
1
- require 'spec_helper'
2
- require 'braque/helpers'
3
-
4
- RSpec.describe Braque::Helpers::HypermediaResponsesHelper do
5
- include Braque::Helpers::HypermediaResponsesHelper
6
-
7
- context 'with a Braque::Model class' do
8
- let(:article) { Article.new(id: 1, title: 'Sculpture in the Expanded Field', key: 'october-spring-1979') }
9
-
10
- before(:all) do
11
- class Article
12
- include ::Braque::Model
13
- api_root_url 'http://localhost:9292'
14
- http_authorization_header 'replace-me'
15
- attribute :id
16
- attribute :title
17
- attribute :key
18
- end
19
- end
20
-
21
- context 'hypermedia_root_json_for' do
22
- context 'defaults' do
23
- before(:each) do
24
- @root_json = hypermedia_root_json_for Article
25
- end
26
-
27
- it 'returns the self link' do
28
- expect(@root_json['_links']['self']['href']).to eq Article.config[:api_root_url]
29
- end
30
-
31
- it 'returns the collection link' do
32
- expect(@root_json['_links']['articles']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}{?page,size}"
33
- end
34
-
35
- it 'returns the resource link' do
36
- expect(@root_json['_links']['article']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/{id}"
37
- end
38
- end
39
- context 'options' do
40
- before(:each) do
41
- @root_json = hypermedia_root_json_for Article, collection_query: '{?page}', resource_path: '{id}?key={key}'
42
- end
43
-
44
- it 'returns the self link' do
45
- expect(@root_json['_links']['self']['href']).to eq Article.config[:api_root_url]
46
- end
47
-
48
- it 'returns the collection link using the collection_query option' do
49
- expect(@root_json['_links']['articles']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}{?page}"
50
- end
51
-
52
- it 'returns the resource link using the resource_path option' do
53
- expect(@root_json['_links']['article']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/{id}?key={key}"
54
- end
55
- end
56
- end
57
-
58
- context 'hypermedia_collection_json_for' do
59
- context 'defaults' do
60
- before(:each) do
61
- @collection_json = hypermedia_collection_json_for [article]
62
- end
63
-
64
- it 'returns the _links node' do
65
- expect(@collection_json['_links']['self']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
66
- expect(@collection_json['_links']['next']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
67
- expect(@collection_json['_links']['prev']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
68
- end
69
-
70
- it 'returns the _embedded node' do
71
- expect(@collection_json['_embedded']['articles']).to eq [{ 'id' => article.id, 'title' => article.title, 'key' => article.key, '_links' => { 'self' => { 'href' => "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/#{article.id}" } } }]
72
- end
73
-
74
- it 'returns the current_page' do
75
- expect(@collection_json['current_page']).to eq 1
76
- end
77
-
78
- it 'returns the total_count' do
79
- expect(@collection_json['total_count']).to eq 1
80
- end
81
-
82
- it 'returns the total_pages' do
83
- expect(@collection_json['total_pages']).to eq 1
84
- end
85
- end
86
- context 'options' do
87
- before(:each) do
88
- @collection_json = hypermedia_collection_json_for [article], resource_path: '"#{model.id}?key=#{model.key}"'
89
- end
90
-
91
- it 'returns the _links node' do
92
- expect(@collection_json['_links']['self']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
93
- expect(@collection_json['_links']['next']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
94
- expect(@collection_json['_links']['prev']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}"
95
- end
96
-
97
- it 'returns the _embedded node' do
98
- expect(@collection_json['_embedded']['articles'])
99
- .to eq [{ 'id' => article.id, 'title' => article.title, 'key' => article.key, '_links' => { 'self' => { 'href' => "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/#{article.id}?key=#{article.key}" } } }]
100
- end
101
-
102
- it 'returns the current_page' do
103
- expect(@collection_json['current_page']).to eq 1
104
- end
105
-
106
- it 'returns the total_count' do
107
- expect(@collection_json['total_count']).to eq 1
108
- end
109
-
110
- it 'returns the total_pages' do
111
- expect(@collection_json['total_pages']).to eq 1
112
- end
113
- end
114
- end
115
-
116
- context 'hypermedia_resource_json_for' do
117
- context 'default' do
118
- before(:each) do
119
- @resource_json = hypermedia_resource_json_for article
120
- end
121
-
122
- it 'returns the _links node' do
123
- expect(@resource_json['_links']['self']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/#{article.id}"
124
- end
125
-
126
- it 'returns the resource attributes' do
127
- expect(@resource_json['id']).to eq article.id
128
- expect(@resource_json['title']).to eq article.title
129
- end
130
- end
131
- context 'options' do
132
- before(:each) do
133
- @resource_json = hypermedia_resource_json_for article, resource_path: '"#{model.id}?key=#{model.key}"'
134
- end
135
-
136
- it 'returns the _links node' do
137
- expect(@resource_json['_links']['self']['href']).to eq "#{Article.config[:api_root_url]}/#{Article.collection_method_name}/#{article.id}?key=#{article.key}"
138
- end
139
-
140
- it 'returns the resource attributes' do
141
- expect(@resource_json['id']).to eq article.id
142
- expect(@resource_json['title']).to eq article.title
143
- end
144
- end
145
- end
146
- end
147
- end