-
-
Save annaswims/4cb3908b0a985a3f4220576394c000a3 to your computer and use it in GitHub Desktop.
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
# vets-api/app/controllers/v0/profile/emails_controller.rb | |
module V0 | |
module Profile | |
class EmailsController < ApplicationController | |
before_action { authorize :evss, :access? } | |
# Fetches the email address, and its effective datetime, for the current user | |
# | |
# @return [Response] Sample response.body: | |
# { | |
# "data" => | |
# { | |
# "id" => "", | |
# "type" => "evss_pciu_email_address_responses", | |
# "attributes" => | |
# { | |
# "email" => "test2@test1.net", | |
# "effective_at" => "2018-02-27T14:41:32.283Z" | |
# } | |
# } | |
# } | |
# | |
def show | |
response = service.get_email_address | |
render json: response, serializer: EmailSerializer | |
end | |
private | |
def service | |
EVSS::PCIU::Service.new @current_user | |
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
# vets-api/app/serializers/email_serializer.rb | |
class EmailSerializer < ActiveModel::Serializer | |
attribute :email | |
attribute :effective_at | |
def id | |
nil | |
end | |
# Returns the email address nested in the given object. | |
# | |
# @return [String] Email address. Sample `object.email_address`: | |
# { | |
# "effective_date" => "2018-02-27T14:41:32.283Z", | |
# "value" => "test2@test1.net" | |
# } | |
# | |
def email | |
object&.email_address&.dig 'value' | |
end | |
# Returns the email's effective datetime nested in the given object | |
# | |
# @return [String] Effective datetime in the yyyy-MM-dd'T'HH:mm:ss format. | |
# Sample `object.email_address`: | |
# { | |
# "effective_date" => "2018-02-27T14:41:32.283Z", | |
# "value" => "test2@test1.net" | |
# } | |
# | |
def effective_at | |
object&.email_address&.dig 'effective_date' | |
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
# vets-api/config/routes.rb | |
... | |
namespace :v0, defaults: { format: 'json' } do | |
namespace :profile do | |
resource :email, only: :show | |
end | |
end | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment