-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: standardize API endpoints (#981)
- Wrap return JSON in an "envelope" to provide the ability to send down viewable data versus metadata (such as paging information). - Moves spec `json_response` to a support/api_helpers file to allow for a single source for parsing response body into json_response (data) and json_meta (meta). Eventually we will want to add API headers for versioning so we can introduce changes with backwards compatibility. Co-authored-by: Laura Mosher <[email protected]>
- Loading branch information
1 parent
52cb696
commit 718bc49
Showing
12 changed files
with
130 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
json.array! @communities do |community| | ||
json.extract! community, :name, :description, :slug | ||
envelope(json) do | ||
json.array! @communities do |community| | ||
json.extract! community, :name, :description, :slug | ||
|
||
json.createdAt community.created_at | ||
json.updatedAt community.updated_at | ||
json.createdAt community.created_at | ||
json.updatedAt community.updated_at | ||
|
||
if community.display_image.attached? | ||
json.displayImage rails_blob_url(community.display_image) | ||
end | ||
if community.display_image.attached? | ||
json.displayImage rails_blob_url(community.display_image) | ||
end | ||
|
||
if community.theme.static_map.attached? | ||
json.staticMapUrl rails_blob_url(community.theme.static_map) | ||
end | ||
if community.theme.static_map.attached? | ||
json.staticMapUrl rails_blob_url(community.theme.static_map) | ||
end | ||
|
||
json.mapConfig do | ||
json.mapboxAccessToken community.theme.mapbox_access_token | ||
json.mapboxStyle community.theme.mapbox_style | ||
json.mapbox3dEnabled community.theme.mapbox_3d | ||
json.mapProjection community.theme.map_projection | ||
json.mapConfig do | ||
json.mapboxAccessToken community.theme.mapbox_access_token | ||
json.mapboxStyle community.theme.mapbox_style | ||
json.mapbox3dEnabled community.theme.mapbox_3d | ||
json.mapProjection community.theme.map_projection | ||
|
||
json.center community.theme.center | ||
json.center community.theme.center | ||
|
||
json.zoom community.theme.zoom | ||
json.pitch community.theme.pitch | ||
json.bearing community.theme.bearing | ||
json.zoom community.theme.zoom | ||
json.pitch community.theme.pitch | ||
json.bearing community.theme.bearing | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
json.(@community, :name, :slug, :description) | ||
|
||
# Details are used specifically in the Explore Panel | ||
json.details do | ||
json.(@community, :name, :description) | ||
json.sponsorLogos @community.sponsor_logos do |logo| | ||
json.url rails_blob_url(logo) | ||
json.blobId logo.blob.id | ||
envelope(json) do | ||
json.(@community, :name, :slug, :description) | ||
|
||
# Details are used specifically in the Explore Panel | ||
json.details do | ||
json.(@community, :name, :description) | ||
json.sponsorLogos @community.sponsor_logos do |logo| | ||
json.url rails_blob_url(logo) | ||
json.blobId logo.blob.id | ||
end | ||
if @community.display_image.attached? | ||
json.displayImage rails_blob_url(@community.display_image) | ||
end | ||
end | ||
if @community.display_image.attached? | ||
json.displayImage rails_blob_url(@community.display_image) | ||
|
||
# Initial Map Configuration | ||
stories = @community.stories.preload(:places).where(permission_level: :anonymous) | ||
json.storiesCount stories.size | ||
json.points stories.flat_map(&:public_points).uniq | ||
|
||
# Side Panel Filter Categories | ||
json.categories Community::FILTERABLE_ATTRIBUTES | ||
|
||
# Side Panel Filter Options (generated from available content) | ||
json.filters @community.filters | ||
|
||
json.mapConfig do | ||
json.mapboxAccessToken @community.theme.mapbox_access_token | ||
json.mapboxStyle @community.theme.mapbox_style | ||
json.mapbox3dEnabled @community.theme.mapbox_3d | ||
json.mapProjection @community.theme.map_projection | ||
|
||
json.centerLat @community.theme.center_lat | ||
json.centerLong @community.theme.center_long | ||
json.swBoundaryLat @community.theme.sw_boundary_lat | ||
json.swBoundaryLong @community.theme.sw_boundary_long | ||
json.neBoundaryLat @community.theme.ne_boundary_lat | ||
json.neBoundaryLong @community.theme.ne_boundary_long | ||
|
||
json.center @community.theme.center | ||
json.maxBounds @community.theme.boundaries | ||
|
||
json.zoom @community.theme.zoom | ||
json.pitch @community.theme.pitch | ||
json.bearing @community.theme.bearing | ||
end | ||
end | ||
|
||
# Initial Map Configuration | ||
stories = @community.stories.preload(:places).where(permission_level: :anonymous) | ||
json.storiesCount stories.size | ||
json.points stories.flat_map(&:public_points).uniq | ||
|
||
# Side Panel Filter Categories | ||
json.categories Community::FILTERABLE_ATTRIBUTES | ||
|
||
# Side Panel Filter Options (generated from available content) | ||
json.filters @community.filters | ||
|
||
json.mapConfig do | ||
json.mapboxAccessToken @community.theme.mapbox_access_token | ||
json.mapboxStyle @community.theme.mapbox_style | ||
json.mapbox3dEnabled @community.theme.mapbox_3d | ||
json.mapProjection @community.theme.map_projection | ||
|
||
json.centerLat @community.theme.center_lat | ||
json.centerLong @community.theme.center_long | ||
json.swBoundaryLat @community.theme.sw_boundary_lat | ||
json.swBoundaryLong @community.theme.sw_boundary_long | ||
json.neBoundaryLat @community.theme.ne_boundary_lat | ||
json.neBoundaryLong @community.theme.ne_boundary_long | ||
|
||
json.center @community.theme.center | ||
json.maxBounds @community.theme.boundaries | ||
|
||
json.zoom @community.theme.zoom | ||
json.pitch @community.theme.pitch | ||
json.bearing @community.theme.bearing | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
json.(@place, :id, :name, :description, :region) | ||
envelope(json) do | ||
json.(@place, :id, :name, :description, :region) | ||
|
||
json.placenameAudio @place.name_audio_url(full_url: true) | ||
json.typeOfPlace @place.type_of_place | ||
json.placenameAudio @place.name_audio_url(full_url: true) | ||
json.typeOfPlace @place.type_of_place | ||
|
||
json.points [@place.public_point_feature] | ||
json.points [@place.public_point_feature] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
json.total @page.total | ||
|
||
# Regardless of Story list page, all points in the data relation | ||
# should be returned for map markers. | ||
json.points @page.relation.flat_map { |s| s.public_points }.uniq | ||
|
||
json.stories @stories do |story| | ||
json.extract! story, :id, :title, :topic, :desc, :language | ||
json.mediaContentTypes story.media_types | ||
json.mediaPreviewUrl story.media_preview_thumbnail | ||
|
||
json.createdAt story.created_at | ||
json.updatedAt story.updated_at | ||
end | ||
|
||
json.hasNextPage @page.has_next_page? | ||
json.nextPageMeta @page.next_page_meta | ||
envelope(json, @page) do | ||
# Regardless of Story list page, all points in the data relation | ||
# should be returned for map markers. | ||
json.points @page.relation.flat_map { |s| s.public_points }.uniq | ||
|
||
json.stories @stories do |story| | ||
json.extract! story, :id, :title, :topic, :desc, :language | ||
json.mediaContentTypes story.media_types | ||
json.mediaPreviewUrl story.media_preview_thumbnail | ||
|
||
json.createdAt story.created_at | ||
json.updatedAt story.updated_at | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def json_body | ||
JSON.parse(response.body) | ||
end | ||
|
||
def json_response | ||
json_body["data"] | ||
end | ||
|
||
def json_meta | ||
json_body["meta"] | ||
end |