restpack_serializer 0.4.8 → 0.4.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa7cfdbe2a9599b02355d695b51fb1ba6bd50bed
4
- data.tar.gz: aa3d9b0c277baf98f13fb7ab9c798a445c903a7a
3
+ metadata.gz: c406b9af62170a52083627f373ffdc67a1942140
4
+ data.tar.gz: 7b73768866438375cf7e1b870e5da680ef60b363
5
5
  SHA512:
6
- metadata.gz: e9adc45be506cf71e5d2edb1d71dd09e5d92132b6f2252d0894ac47537096840bf8b9b7cc77551ef75445eeaefdfb99314ebc075e5dc706c4322ae2136e62e6a
7
- data.tar.gz: ba50400c0c244ea96efcd89988026c58f4f9c11cdae1a53b0c0ea691243218b4d78181710f1fc3ee43a1a03e3db2caf2bbc713a12ff01673ce036d73ec8f9752
6
+ metadata.gz: ddd06300644271b871ace5bf86921c284145361fe7d3f5e3c334fedf7e8475f10afaaf74299e628a21320706229ae56927c7a20a404b414c8d8aed53a26d2fd5
7
+ data.tar.gz: a92f904c22955987d9415c772e61b7b0bccbffb8864d102d3a1d6b3d96d2b9af431eb4dc79e4d29b6bf6d756a51d80d687fb4b300499243380b27501ca0d401c
data/README.md CHANGED
@@ -42,7 +42,7 @@ end
42
42
  "title": "Kid A",
43
43
  "year": 2000,
44
44
  "artist_id": 1,
45
- "href": "/albums/1.json"
45
+ "href": "/albums/1"
46
46
  }
47
47
  ```
48
48
 
@@ -62,7 +62,7 @@ class AlbumsController < ApplicationController
62
62
  end
63
63
  ```
64
64
 
65
- These endpoint will live at URLs such as `/albums.json` and `/albums/142857.json`:
65
+ These endpoint will live at URLs such as `/albums` and `/albums/142857`:
66
66
 
67
67
  * http://restpack-serializer-sample.herokuapp.com/albums.json
68
68
  * http://restpack-serializer-sample.herokuapp.com/albums/4.json
@@ -90,7 +90,7 @@ http://restpack-serializer-sample.herokuapp.com/songs.json?page=2&page_size=3 yi
90
90
  {
91
91
  "id": "4",
92
92
  "title": "How to Dissapear Completely",
93
- "href": "/songs/4.json",
93
+ "href": "/songs/4",
94
94
  "links": {
95
95
  "artist": "1",
96
96
  "album": "1"
@@ -99,7 +99,7 @@ http://restpack-serializer-sample.herokuapp.com/songs.json?page=2&page_size=3 yi
99
99
  {
100
100
  "id": "5",
101
101
  "title": "Treefingers",
102
- "href": "/songs/5.json",
102
+ "href": "/songs/5",
103
103
  "links": {
104
104
  "artist": "1",
105
105
  "album": "1"
@@ -108,7 +108,7 @@ http://restpack-serializer-sample.herokuapp.com/songs.json?page=2&page_size=3 yi
108
108
  {
109
109
  "id": "6",
110
110
  "title": "Optimistic",
111
- "href": "/songs/6.json",
111
+ "href": "/songs/6",
112
112
  "links": {
113
113
  "artist": "1",
114
114
  "album": "1"
@@ -124,17 +124,17 @@ http://restpack-serializer-sample.herokuapp.com/songs.json?page=2&page_size=3 yi
124
124
  "page_count": 14,
125
125
  "previous_page": 1,
126
126
  "next_page": 3,
127
- "previous_href": "/api/v1/songs.json?page_size=3",
128
- "next_href": "/api/v1/songs.json?page=3&page_size=3"
127
+ "previous_href": "/api/v1/songs?page_size=3",
128
+ "next_href": "/api/v1/songs?page=3&page_size=3"
129
129
  }
130
130
  },
131
131
  "links": {
132
132
  "songs.artist": {
133
- "href": "/artists/{songs.artist}.json",
133
+ "href": "/artists/{songs.artist}",
134
134
  "type": "artists"
135
135
  },
136
136
  "songs.album": {
137
- "href": "/albums/{songs.album}.json",
137
+ "href": "/albums/{songs.album}",
138
138
  "type": "albums"
139
139
  }
140
140
  }
@@ -143,8 +143,8 @@ http://restpack-serializer-sample.herokuapp.com/songs.json?page=2&page_size=3 yi
143
143
 
144
144
  URL Templates to related data are included in the `links` element. These can be used to construct URLs such as:
145
145
 
146
- * /artists/1.json
147
- * /albums/1.json
146
+ * /artists/1
147
+ * /albums/1
148
148
 
149
149
  ## Side-loading
150
150
 
@@ -178,7 +178,7 @@ which yields:
178
178
  "id": "1",
179
179
  "title": "Kid A",
180
180
  "year": 2000,
181
- "href": "/albums/1.json",
181
+ "href": "/albums/1",
182
182
  "links": {
183
183
  "artist": "1"
184
184
  }
@@ -187,7 +187,7 @@ which yields:
187
187
  "id": "2",
188
188
  "title": "Amnesiac",
189
189
  "year": 2001,
190
- "href": "/albums/2.json",
190
+ "href": "/albums/2",
191
191
  "links": {
192
192
  "artist": "1"
193
193
  }
@@ -196,7 +196,7 @@ which yields:
196
196
  "id": "3",
197
197
  "title": "Murder Ballads",
198
198
  "year": 1996,
199
- "href": "/albums/3.json",
199
+ "href": "/albums/3",
200
200
  "links": {
201
201
  "artist": "2"
202
202
  }
@@ -205,7 +205,7 @@ which yields:
205
205
  "id": "4",
206
206
  "title": "Curtains",
207
207
  "year": 2005,
208
- "href": "/albums/4.json",
208
+ "href": "/albums/4",
209
209
  "links": {
210
210
  "artist": "3"
211
211
  }
@@ -228,19 +228,19 @@ which yields:
228
228
  },
229
229
  "links": {
230
230
  "albums.songs": {
231
- "href": "/songs.json?album_id={albums.id}",
231
+ "href": "/songs?album_id={albums.id}",
232
232
  "type": "songs"
233
233
  },
234
234
  "albums.artist": {
235
- "href": "/artists/{albums.artist}.json",
235
+ "href": "/artists/{albums.artist}",
236
236
  "type": "artists"
237
237
  },
238
238
  "artists.albums": {
239
- "href": "/albums.json?artist_id={artists.id}",
239
+ "href": "/albums?artist_id={artists.id}",
240
240
  "type": "albums"
241
241
  },
242
242
  "artists.songs": {
243
- "href": "/songs.json?artist_id={artists.id}",
243
+ "href": "/songs?artist_id={artists.id}",
244
244
  "type": "songs"
245
245
  }
246
246
  },
@@ -249,19 +249,19 @@ which yields:
249
249
  "id": "1",
250
250
  "name": "Radiohead",
251
251
  "website": "http://radiohead.com/",
252
- "href": "/artists/1.json"
252
+ "href": "/artists/1"
253
253
  },
254
254
  {
255
255
  "id": "2",
256
256
  "name": "Nick Cave & The Bad Seeds",
257
257
  "website": "http://www.nickcave.com/",
258
- "href": "/artists/2.json"
258
+ "href": "/artists/2"
259
259
  },
260
260
  {
261
261
  "id": "3",
262
262
  "name": "John Frusciante",
263
263
  "website": "http://johnfrusciante.com/",
264
- "href": "/artists/3.json"
264
+ "href": "/artists/3"
265
265
  }
266
266
  ]
267
267
  }
@@ -2,7 +2,7 @@ module RestPack::Serializer::Attributes
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  def default_href
5
- "#{RestPack::Serializer.config.href_prefix}/#{self.class.key}/#{@model.id}.json"
5
+ "#{RestPack::Serializer.config.href_prefix}/#{self.class.key}/#{@model.id}"
6
6
  end
7
7
 
8
8
  module ClassMethods
@@ -58,7 +58,7 @@ module RestPack::Serializer::Paging
58
58
  def page_href(page, options)
59
59
  return nil unless page
60
60
 
61
- url = "#{RestPack::Serializer.config.href_prefix}/#{self.key}.json"
61
+ url = "#{RestPack::Serializer.config.href_prefix}/#{self.key}"
62
62
 
63
63
  params = []
64
64
  params << "page=#{page}" unless page == 1
@@ -31,11 +31,11 @@ module RestPack::Serializer::SideLoading
31
31
  associations.each do |association|
32
32
  if association.macro == :belongs_to
33
33
  link_key = "#{self.key}.#{association.name}"
34
- href = "/#{association.plural_name}/{#{link_key}}.json"
34
+ href = "/#{association.plural_name}/{#{link_key}}"
35
35
  elsif association.macro == :has_many
36
36
  singular_key = self.key.to_s.singularize
37
37
  link_key = "#{self.key}.#{association.plural_name}"
38
- href = "/#{association.plural_name}.json?#{singular_key}_id={#{key}.id}"
38
+ href = "/#{association.plural_name}?#{singular_key}_id={#{key}.id}"
39
39
  end
40
40
 
41
41
  links[link_key] = {
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.4.8'
3
+ VERSION = '0.4.9'
4
4
  end
5
5
  end
@@ -23,12 +23,12 @@ describe RestPack::Serializer::Paging do
23
23
  page[:meta][:songs][:previous_page].should == nil
24
24
  page[:meta][:songs][:previous_href].should == nil
25
25
  page[:meta][:songs][:next_page].should == 2
26
- page[:meta][:songs][:next_href].should == '/songs.json?page=2'
26
+ page[:meta][:songs][:next_href].should == '/songs?page=2'
27
27
  end
28
28
  it "includes links" do
29
29
  page[:links].should == {
30
- 'songs.album' => { :href => "/albums/{songs.album}.json", :type => :albums },
31
- 'songs.artist' => { :href => "/artists/{songs.artist}.json", :type => :artists }
30
+ 'songs.album' => { :href => "/albums/{songs.album}", :type => :albums },
31
+ 'songs.artist' => { :href => "/artists/{songs.artist}", :type => :artists }
32
32
  }
33
33
  end
34
34
  end
@@ -41,7 +41,7 @@ describe RestPack::Serializer::Paging do
41
41
  end
42
42
  it "includes the custom page size in the page hrefs" do
43
43
  page[:meta][:songs][:next_page].should == 2
44
- page[:meta][:songs][:next_href].should == '/songs.json?page=2&page_size=3'
44
+ page[:meta][:songs][:next_href].should == '/songs?page=2&page_size=3'
45
45
  end
46
46
  end
47
47
 
@@ -93,7 +93,7 @@ describe RestPack::Serializer::Paging do
93
93
  page[:meta][:songs][:page].should == 2
94
94
  page[:meta][:songs][:previous_page].should == 1
95
95
  page[:meta][:songs][:next_page].should == nil
96
- page[:meta][:songs][:previous_href].should == '/songs.json'
96
+ page[:meta][:songs][:previous_href].should == '/songs'
97
97
  end
98
98
  end
99
99
 
@@ -109,7 +109,7 @@ describe RestPack::Serializer::Paging do
109
109
  end
110
110
 
111
111
  it "includes the side-loads in page hrefs" do
112
- page[:meta][:songs][:next_href].should == '/songs.json?page=2&include=albums'
112
+ page[:meta][:songs][:next_href].should == '/songs?page=2&include=albums'
113
113
  end
114
114
 
115
115
  it "includes links between documents" do
@@ -133,7 +133,7 @@ describe RestPack::Serializer::Paging do
133
133
  end
134
134
 
135
135
  it "includes the side-loads in page hrefs" do
136
- page[:meta][:songs][:next_href].should == '/songs.json?page=2&include=albums,artists'
136
+ page[:meta][:songs][:next_href].should == '/songs?page=2&include=albums,artists'
137
137
  end
138
138
 
139
139
  it "includes links" do
@@ -164,7 +164,7 @@ describe RestPack::Serializer::Paging do
164
164
  end
165
165
 
166
166
  it "includes the filter in page hrefs" do
167
- page[:meta][:songs][:next_href].should == "/songs.json?page=2&album_id=#{@album1.id}"
167
+ page[:meta][:songs][:next_href].should == "/songs?page=2&album_id=#{@album1.id}"
168
168
  end
169
169
  end
170
170
  end
@@ -55,7 +55,7 @@ describe RestPack::Serializer do
55
55
  serializer.class.serialize(person).should == {
56
56
  people: [{
57
57
  id: '123', name: 'Gavin', description: 'This is person #123',
58
- href: '/people/123.json', custom_key: 'custom value for model id 123'
58
+ href: '/people/123', custom_key: 'custom value for model id 123'
59
59
  }]
60
60
  }
61
61
  end
@@ -65,14 +65,14 @@ describe RestPack::Serializer do
65
65
  it "serializes specified attributes" do
66
66
  serializer.as_json(person).should == {
67
67
  id: '123', name: 'Gavin', description: 'This is person #123',
68
- href: '/people/123.json', custom_key: 'custom value for model id 123'
68
+ href: '/people/123', custom_key: 'custom value for model id 123'
69
69
  }
70
70
  end
71
71
 
72
72
  context "with options" do
73
73
  it "excludes specified attributes" do
74
74
  serializer.as_json(person, { include_description?: false }).should == {
75
- id: '123', name: 'Gavin', href: '/people/123.json',
75
+ id: '123', name: 'Gavin', href: '/people/123',
76
76
  custom_key: 'custom value for model id 123'
77
77
  }
78
78
  end
@@ -52,11 +52,11 @@ describe RestPack::Serializer::SideLoading do
52
52
  describe "#links" do
53
53
  MyApp::AlbumSerializer.links.should == {
54
54
  "albums.artist" => {
55
- :href => "/artists/{albums.artist}.json",
55
+ :href => "/artists/{albums.artist}",
56
56
  :type => :artists
57
57
  },
58
58
  "albums.songs" => {
59
- :href => "/songs.json?album_id={albums.id}",
59
+ :href => "/songs?album_id={albums.id}",
60
60
  :type => :songs
61
61
  }
62
62
  }
@@ -64,7 +64,7 @@ describe RestPack::Serializer::SideLoading do
64
64
  it "applies custom RestPack::Serializer.config.href_prefix" do
65
65
  original = RestPack::Serializer.config.href_prefix
66
66
  RestPack::Serializer.config.href_prefix = "/api/v1"
67
- MyApp::AlbumSerializer.links["albums.artist"][:href].should == "/api/v1/artists/{albums.artist}.json"
67
+ MyApp::AlbumSerializer.links["albums.artist"][:href].should == "/api/v1/artists/{albums.artist}"
68
68
  RestPack::Serializer.config.href_prefix = original
69
69
  end
70
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-08 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord