Sha256: 506b54c4b9d7ad69d71737141b055832897afbaa64db7ef0e78fd237acd84f6a
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
module Grendel class User attr_accessor :id, :password, :uri attr_reader :client, :modified_at, :created_at, :keys # create a new Grendel::User object # params: # id # uri # password def initialize(client, params) params.symbolize_keys! @client = client @id = params[:id] @uri = params[:uri] ? URI.parse(params[:uri]).path : "/users/" + @id # escape this? @password = params[:password] @modified_at = DateTime.parse(params[:"modified-at"]) if params[:"modified-at"] @created_at = DateTime.parse(params[:"created-at"]) if params[:"created-at"] @keys = params[:keys] end # return user's creds in the form required by HTTParty def auth {:basic_auth => {:username => id, :password => password}} end # # methods to do authenticated client calls with the user's base_uri # def get(uri = "", options = {}) options.merge!(auth) @client.get(@uri + uri, options) end def post(uri = "", data = {}, options = {}) options.merge!(auth) @client.post(@uri + uri, data, options) end def put(uri = "", data = {}, options = {}) options.merge!(auth) @client.put(@uri + uri, data, options) end def delete(uri = "", options = {}) options.merge!(auth) @client.delete(@uri + uri, options) end # change the user's password def change_password(new_password) put("", {:password => new_password}) @password = new_password end # send documents calls to the DocumentManager def documents DocumentManager.new(self) end # send linked documents calls to the LinkedDocumentManager def linked_documents LinkedDocumentManager.new(self) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grendel-ruby-0.1.1 | lib/grendel/user.rb |