Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making tags_controller and tagged_items_controller fully v1 and v2 aw…
…are; also updating the Swagger JSON specs
- Loading branch information
Tim Schmelmer
committed
Apr 18, 2014
1 parent
571fb34
commit 615c10f
Showing
11 changed files
with
498 additions
and
15 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
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,5 +1,10 @@ | ||
module ApplicationHelper | ||
def tagged_item_url(tagged_item, version = 1) | ||
"http://inventory-service-development.herokuapp.com/api/v#{version}/inventory_items/#{tagged_item.item_id}" | ||
case TaggedItem.item_type_name_for(tagged_item.item_type) | ||
when 'city' | ||
"http://cities-service-development.herokuapp.com/api/v#{version}/cities/#{tagged_item.item_id}" | ||
else | ||
"http://inventory-service-development.herokuapp.com/api/v#{version}/inventory_items/#{tagged_item.item_id}" | ||
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
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,19 @@ | ||
class Presenters::V2::TagPresenter < Presenters::V1::TagPresenter | ||
|
||
def to_hash(tg = tag) | ||
HashWithIndifferentAccess.new( | ||
{ | ||
name: tg.name, | ||
tagged_items: { | ||
count: tg.tagged_items.count, | ||
items: tg.tagged_items.map do |item| | ||
{ id: item.item_id, | ||
type: item.item_type, | ||
url: tagged_item_url(item, self.class.version_number) } | ||
end | ||
}, | ||
path: tag_path(self.class.version_number, tg.name) | ||
}) | ||
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Presenters::V2::TaggedItemPresenter < Presenters::V1::TaggedItemPresenter | ||
|
||
def to_hash(tagged_item = item) | ||
HashWithIndifferentAccess.new( | ||
{ | ||
tagged_item_id: tagged_item.item_id, | ||
tagged_item_type: tagged_item.item_type, | ||
url: tagged_item_url(tagged_item, self.class.version_number), | ||
tag_name: tagged_item.tag.name | ||
}) | ||
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"apiVersion": "2.0", | ||
"swaggerVersion": "1.2", | ||
"basePath": "http://tags-service-development.herokuapp.com/api_docs/v2", | ||
"apis": [ | ||
{ | ||
"path": "/tagged_items.{format}", | ||
"description": "Managing associating tags with items" | ||
}, | ||
{ | ||
"path": "/tags.{format}", | ||
"description": "Tag management" | ||
} | ||
] | ||
} |
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,165 @@ | ||
{ | ||
"apiVersion": "2.0", | ||
"swaggerVersion": "1.2", | ||
"basePath": "http://tags-service-development.herokuapp.com/api/v2", | ||
"apis": [ | ||
{ | ||
"path": "/tags/{tag_name}/tagged_items.json", | ||
"operations": [ | ||
{ | ||
"summary": "Fetches all tagged items for tag {tag_name}", | ||
"parameters": [ | ||
{ | ||
"paramType": "path", | ||
"name": "tag_name", | ||
"type": "string", | ||
"description": "Tag name for which all tagged items are retrieved", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "query", | ||
"name": "item_type", | ||
"type": "string", | ||
"description": "Name of the type of item by which to filter the items tagged, e.g. 'city'; defaults to 'all'", | ||
"required": false | ||
} | ||
], | ||
"responseMessages": [ | ||
{ | ||
"code": 304, | ||
"message": "The content has not changed in relation to the request ETag / If-Modified-Since" | ||
} | ||
], | ||
"method": "get", | ||
"nickname": "TaggedItems#index" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "/tags/{tag_name}/tagged_items.json", | ||
"operations": [ | ||
{ | ||
"summary": "Tags an item with ID {id} with tag by name {tag_name}", | ||
"parameters": [ | ||
{ | ||
"paramType": "path", | ||
"name": "tag_name", | ||
"type": "string", | ||
"description": "Tag name to be applied to the tagged item", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "form", | ||
"name": "id", | ||
"type": "integer", | ||
"description": "ID of the item to be tagged", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "form", | ||
"name": "item_type", | ||
"type": "string", | ||
"description": "Name of the type of item to be tagged, e.g. 'city'; defaults to 'inventory_item'", | ||
"required": false | ||
} | ||
], | ||
"responseMessages": [ | ||
{ | ||
"code": 422, | ||
"message": "Unprocessable Entity" | ||
} | ||
], | ||
"method": "post", | ||
"nickname": "TaggedItems#create" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "/tags/{tag_name}/tagged_items/{id}.json", | ||
"operations": [ | ||
{ | ||
"summary": "Fetches a single tagged item for tag {tag_name} and item ID {id}", | ||
"parameters": [ | ||
{ | ||
"paramType": "path", | ||
"name": "id", | ||
"type": "integer", | ||
"description": "ID of the tagged item", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "path", | ||
"name": "tag_name", | ||
"type": "string", | ||
"description": "Name of the tag that is was applied to the tagged item", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "query", | ||
"name": "item_type", | ||
"type": "string", | ||
"description": "Name of the item type by which to filter the applicable tags (e.g., 'city'), so that just one tagged item is ever returned; defaults to 'inventory_item'", | ||
"required": false | ||
} | ||
], | ||
"responseMessages": [ | ||
{ | ||
"code": 304, | ||
"message": "The content has not changed in relation to the request ETag / If-Modified-Since" | ||
}, | ||
{ | ||
"code": 404, | ||
"message": "Not Found" | ||
} | ||
], | ||
"method": "get", | ||
"nickname": "TaggedItems#show" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "/tags/{tag_name}/tagged_items/{id}.json", | ||
"operations": [ | ||
{ | ||
"summary": "Deletes an existing association between a tag (by name) and a tagged item", | ||
"parameters": [ | ||
{ | ||
"paramType": "path", | ||
"name": "id", | ||
"type": "integer", | ||
"description": "ID of the item that is currently tagged", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "path", | ||
"name": "tag_name", | ||
"type": "string", | ||
"description": "name of the tag to be removed from the item", | ||
"required": true | ||
}, | ||
{ | ||
"paramType": "query", | ||
"name": "item_type", | ||
"type": "string", | ||
"description": "Name of the item type by which to filter the applicable tags (e.g., 'city'), so that just one tagged item is ever destroyed; defaults to 'inventory_item'", | ||
"required": false | ||
} | ||
], | ||
"responseMessages": [ | ||
{ | ||
"code": 404, | ||
"message": "Not Found" | ||
}, | ||
{ | ||
"code": 400, | ||
"message": "Bad Request" | ||
} | ||
], | ||
"method": "delete", | ||
"nickname": "TaggedItems#destroy" | ||
} | ||
] | ||
} | ||
], | ||
"resourcePath": "/tagged_items" | ||
} |
Oops, something went wrong.