Class: Dropwallet::Core::User
- Inherits:
-
Model
- Object
- Model
- Dropwallet::Core::User
show all
- Defined in:
- lib/dropwallet/core/user.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
all, baseServiceUrl, count, create, debug?, delete, #delete, field, find, #initialize, #isNew?, pages, #read_attribute, #read_attribute_for_validation, #save, serviceUrl, #to_json, #to_s, #update, #write_attribute
Class Method Details
.forgotPassword(account) ⇒ Object
30
31
32
33
|
# File 'lib/dropwallet/core/user.rb', line 30
def self.forgotPassword(account)
options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/forgottenpassword"}
RestClient.post(options[:path], {:email=>account})
end
|
.login(username, password) ⇒ Object
Login Function, returns User object on success, nil on failure
48
49
50
51
52
53
54
|
# File 'lib/dropwallet/core/user.rb', line 48
def self.login(username, password)
login = JSON.parse(RestClient.post baseServiceUrl + '/session/login', "username=#{username}&password=#{password}", {:accept => :json})
if login['status'] == 'SUCCESS'
return Dropwallet::Core::User.find(login['userId'])
end
return nil
end
|
Instance Method Details
#order(orderId) ⇒ Object
20
21
22
23
|
# File 'lib/dropwallet/core/user.rb', line 20
def order(orderId)
options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders"}
return Dropwallet::Core::Order.find(orderId, options)
end
|
#orders(page = 1) ⇒ Object
15
16
17
18
|
# File 'lib/dropwallet/core/user.rb', line 15
def orders(page = 1)
options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders.json"}
return Dropwallet::Core::Order.all(page, options)
end
|
#orderSearch(query, page = 1) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/dropwallet/core/user.rb', line 35
def orderSearch(query, page = 1)
options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders/search?query=#{query}&limit=95&page=#{page}"}
doc = JSON.parse(RestClient.get(options[:path], {:accept => :json}))
if doc.include? 'errorMessage'
raise doc['errorMessage']
end
objects = []
doc['items'].each do |item|
objects << Dropwallet::Core::Order.new(item)
end
return {:page=>page, :pages=>doc['pages'], :orders=>objects}
end
|
#ordersPages ⇒ Object
25
26
27
28
|
# File 'lib/dropwallet/core/user.rb', line 25
def ordersPages
options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders.json"}
return Dropwallet::Core::Order.pages(options)
end
|