lib/pilha/stack_overflow/user.rb in pilha-0.1.3 vs lib/pilha/stack_overflow/user.rb in pilha-0.1.5

- old
+ new

@@ -1,9 +1,9 @@ module StackExchange module StackOverflow - class User + class User < Base extend Forwardable def_delegators :@struct, :user_id, :user_type, :creation_date, :display_name, :reputation, :email_hash, :age, :last_access_date, :website_url, :location, :about_me, :question_count, @@ -16,24 +16,25 @@ class << self attr_reader :client def all(options = {}) - response = client.request('/users', options) - OpenStruct.new(parse response) + parse client.request('/users', options) end def find_by_badge_id(id, options = {}) - options.merge! :id => id - response = client.request('/badges/:id', options) - OpenStruct.new(parse response) + request('/badges/:id', id, options) end + def find(id, options = {}) + request('/users/:id', id, options).users.first + end + private def parse(response) users = response['users'].map { |user| User.new(user) } response['users'] = users - response + OpenStruct.new response end end def initialize(hash) @struct = OpenStruct.new hash