From ef48e6c4df451ef1f74a984b86c36d88e75b7617 Mon Sep 17 00:00:00 2001 From: Hannah Howard Date: Thu, 30 Oct 2014 17:08:43 -0700 Subject: [PATCH] Missing files --- .gitignore | 1 + .../error_messages_serializer.rb | 16 +++++++++++++ .../resource_errors_serializer.rb | 24 +++++++++++++++++++ .../devise_token_auth/resource_serializer.rb | 17 +++++++++++++ .../success_message_serializer.rb | 15 ++++++++++++ 5 files changed, 73 insertions(+) create mode 100644 app/serializers/devise_token_auth/error_messages_serializer.rb create mode 100644 app/serializers/devise_token_auth/resource_errors_serializer.rb create mode 100644 app/serializers/devise_token_auth/resource_serializer.rb create mode 100644 app/serializers/devise_token_auth/success_message_serializer.rb diff --git a/.gitignore b/.gitignore index 10bfacc3c..f30fec5f3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ test/dummy/log/*.log test/dummy/tmp/ test/dummy/.sass-cache coverage +*.orig diff --git a/app/serializers/devise_token_auth/error_messages_serializer.rb b/app/serializers/devise_token_auth/error_messages_serializer.rb new file mode 100644 index 000000000..d82c4cd9e --- /dev/null +++ b/app/serializers/devise_token_auth/error_messages_serializer.rb @@ -0,0 +1,16 @@ +module DeviseTokenAuth + class ErrorMessagesSerializer + def initialize(*args) + @args = args + end + + attr_reader :args + + def as_json(options) + { + status: 'error', + errors: args + } + end + end +end diff --git a/app/serializers/devise_token_auth/resource_errors_serializer.rb b/app/serializers/devise_token_auth/resource_errors_serializer.rb new file mode 100644 index 000000000..c5e63da49 --- /dev/null +++ b/app/serializers/devise_token_auth/resource_errors_serializer.rb @@ -0,0 +1,24 @@ +module DeviseTokenAuth + class ResourceErrorsSerializer + def initialize(*args) + @args = args + end + + attr_reader :args + + def as_json(options) + resource = args[0] + response = { + status: "error", + data: resource.as_json(except: [:tokens, :created_at, :updated_at]) + } + if args.length > 1 + args.shift + response[:errors] = args + else + response[:errors] = resource.errors.to_hash.merge(full_messages: resource.errors.full_messages) + end + response + end + end +end diff --git a/app/serializers/devise_token_auth/resource_serializer.rb b/app/serializers/devise_token_auth/resource_serializer.rb new file mode 100644 index 000000000..e2ab1f95f --- /dev/null +++ b/app/serializers/devise_token_auth/resource_serializer.rb @@ -0,0 +1,17 @@ +module DeviseTokenAuth + + class ResourceSerializer + def initialize(resource) + @resource = resource + end + attr_reader :resource + + def as_json(options) + { + status: "success", + data: resource.as_json(except: [:tokens, :created_at, :updated_at]) + } + end + + end +end diff --git a/app/serializers/devise_token_auth/success_message_serializer.rb b/app/serializers/devise_token_auth/success_message_serializer.rb new file mode 100644 index 000000000..1eef97e01 --- /dev/null +++ b/app/serializers/devise_token_auth/success_message_serializer.rb @@ -0,0 +1,15 @@ +module DeviseTokenAuth + class SuccessMessageSerializer + def initialize(message) + @message = message + end + + attr_reader :message + + def as_json(options) + json_response = { status: 'success' } + json_response[:message] = message if message + json_response + end + end +end