Created
October 17, 2014 11:17
-
-
Save 7even/419bf7bae6d8a6d426a2 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
def post_author(properties_or_obj = {}) | |
# Теперь пользователь может передать свой объект или просто хэш с параметрами | |
author = if properties_or_obj.respond_to?(:author) | |
properties_or_obj.to_author | |
else | |
properties_or_obj | |
end | |
raise ArgumentError unless author.is_a?(Hash) | |
# fetch позволяет передать блок, который вызывается если ключ не найден | |
name = author.fetch(:name) { raise KeyError, "Name must be supplied for Author API requests" } | |
email = author.fetch(:email) { raise KeyError, "Email must be supplied for Author API requests" } | |
api.send( | |
name: name, | |
email: email | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment