Slide 61
Slide 61 text
ͩΊͳྫ
class User
include ActiveModel::Model
attr_accessor :id, :name, :age
end
class UserRepository
def self.get(id)
response = api_client.get("/v1/users/#{id}")
return nil if response.status == 404
raise 'Error' unless response.success?
# response.body
# => { 'id' => 1, 'name' => 'qsona', 'age' => 17 }
User.new(response.body)
end
end