from webob import Response
from apiversion import APIVersion
from application import Application
from apiv1app import APIv1App

class VersionsApp(Application):

	version_classes = [ APIv1App ]

	def APIVersionList(self, args):
		return Response(content_type = 'application/json', body = self._resultset_to_json([
			{
				"id": version._version_identifier(),
				"links": [
					{
						"href": "/" + version._version_identifier(),
						"rel": "self"
					}
				]
			} for version in self.version_classes
		]))

	def APIVersion(self, args):
		return Response(content_type = 'application/json', body = self._resultset_to_json({
			'todo': 'Report detail'
		}))

def factory(global_config, **settings):
	return VersionsApp()

from webob import Response
import webob.exc
from apiversion import APIVersion
from application import Application
from apiv1app import APIv1App

class VersionsApp(Application):

	version_classes = [ APIv1App ]

	def _api_version_detail(self, version):
		return {
			"id": version._version_identifier(),
			"links": [
				{
					"href": "/" + version._version_identifier(),
					"rel": "self"
				}
			]
		}

	def APIVersionList(self, args):
		return Response(status = 300, content_type = 'application/json', body = self._resultset_to_json([
			self._api_version_detail(version) for version in self.version_classes
		]))

	def APIVersion(self, version_identifier):
		versions = [ version for version in self.version_classes if version._version_identifier() == version_identifier ]
		if not versions:
			return webob.exc.HTTPNotFound()
		if len(versions) > 1:
			raise RuntimeError("Multiple API versions with identifier '%s'" % version_identifier)
		return Response(content_type = 'application/json', body = self._resultset_to_json({
			self._api_version_detail(versions[0])
		}))

def factory(global_config, **settings):
	return VersionsApp()

Correct the HTTP status from GET / - it should be 300 (Multiple Choices) not 200. Implement the details of a given version.
Correct the HTTP status from GET / - it should be 300 (Multiple Choices) not 200. Implement the details of a given version.

  from webob import Response
+ import webob.exc
  from apiversion import APIVersion
  from application import Application
  from apiv1app import APIv1App
  
  class VersionsApp(Application):
  
  	version_classes = [ APIv1App ]
  
+ 	def _api_version_detail(self, version):
+ 		return {
+ 			"id": version._version_identifier(),
+ 			"links": [
+ 				{
+ 					"href": "/" + version._version_identifier(),
+ 					"rel": "self"
+ 				}
+ 			]
+ 		}
+ 
  	def APIVersionList(self, args):
- 		return Response(content_type = 'application/json', body = self._resultset_to_json([
+ 		return Response(status = 300, content_type = 'application/json', body = self._resultset_to_json([
+ 			self._api_version_detail(version) for version in self.version_classes
- 			{
- 				"id": version._version_identifier(),
- 				"links": [
- 					{
- 						"href": "/" + version._version_identifier(),
- 						"rel": "self"
- 					}
- 				]
- 			} for version in self.version_classes
  		]))
  
- 	def APIVersion(self, args):
+ 	def APIVersion(self, version_identifier):
+ 		versions = [ version for version in self.version_classes if version._version_identifier() == version_identifier ]
+ 		if not versions:
+ 			return webob.exc.HTTPNotFound()
+ 		if len(versions) > 1:
+ 			raise RuntimeError("Multiple API versions with identifier '%s'" % version_identifier)
  		return Response(content_type = 'application/json', body = self._resultset_to_json({
- 			'todo': 'Report detail'
+ 			self._api_version_detail(versions[0])
  		}))
  
  def factory(global_config, **settings):
  	return VersionsApp()
  
Correct the HTTP status from GET / - it should be 300 (Multiple Choices) not 200. Implement the details of a given version.
## Code Before:
from webob import Response
from apiversion import APIVersion
from application import Application
from apiv1app import APIv1App

class VersionsApp(Application):

	version_classes = [ APIv1App ]

	def APIVersionList(self, args):
		return Response(content_type = 'application/json', body = self._resultset_to_json([
			{
				"id": version._version_identifier(),
				"links": [
					{
						"href": "/" + version._version_identifier(),
						"rel": "self"
					}
				]
			} for version in self.version_classes
		]))

	def APIVersion(self, args):
		return Response(content_type = 'application/json', body = self._resultset_to_json({
			'todo': 'Report detail'
		}))

def factory(global_config, **settings):
	return VersionsApp()

## Instruction:
Correct the HTTP status from GET / - it should be 300 (Multiple Choices) not 200. Implement the details of a given version.
## Code After:
from webob import Response
import webob.exc
from apiversion import APIVersion
from application import Application
from apiv1app import APIv1App

class VersionsApp(Application):

	version_classes = [ APIv1App ]

	def _api_version_detail(self, version):
		return {
			"id": version._version_identifier(),
			"links": [
				{
					"href": "/" + version._version_identifier(),
					"rel": "self"
				}
			]
		}

	def APIVersionList(self, args):
		return Response(status = 300, content_type = 'application/json', body = self._resultset_to_json([
			self._api_version_detail(version) for version in self.version_classes
		]))

	def APIVersion(self, version_identifier):
		versions = [ version for version in self.version_classes if version._version_identifier() == version_identifier ]
		if not versions:
			return webob.exc.HTTPNotFound()
		if len(versions) > 1:
			raise RuntimeError("Multiple API versions with identifier '%s'" % version_identifier)
		return Response(content_type = 'application/json', body = self._resultset_to_json({
			self._api_version_detail(versions[0])
		}))

def factory(global_config, **settings):
	return VersionsApp()
