lib/ahub/user.rb in ahub-0.1.17 vs lib/ahub/user.rb in ahub-0.2.0
- old
+ new
@@ -10,21 +10,21 @@
email: email,
username: username,
password: password || Ahub::DEFAULT_PASSWORD,
}
- make_post_call(url: url, payload: payload, headers: admin_headers)
+ create_resource(url: url, payload: payload, headers: admin_headers)
end
def self.find_by_username(username)
matches = find_all(params: {q: username})
matches.find{|user| user.username.downcase.strip == username.downcase.strip}
end
attr_reader :username, :realname, :avatar_url,
:post_count, :follow_count, :follower_count,
- :active, :suspended, :deactivated
+ :active, :suspended, :deactivated, :answers
def initialize(attrs)
@id = attrs[:id]
@username = attrs[:username]
@realname = attrs[:realname]
@@ -38,8 +38,17 @@
@complete = attrs[:complete]
end
def is_complete?
!!@complete
+ end
+
+ def answers
+ unless @answers
+ response = self.class.get_resource(url: "#{self.class.base_url}/#{id}/answer.json", headers: self.class.admin_headers)
+ @answers = response[:list].map{ |answer| Ahub::Answer.new(answer) }
+ end
+
+ @answers
end
end
end