Class: Puavo::Client::API::Base
- Inherits:
-
Object
- Object
- Puavo::Client::API::Base
show all
- Includes:
- HTTParty
- Defined in:
- lib/puavo/client/api/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(subdomain, username, password, ssl = true) ⇒ Base
Returns a new instance of Base.
9
10
11
|
# File 'lib/puavo/client/api/base.rb', line 9
def initialize(subdomain, username, password, ssl = true)
@subdomain, @username, @password, @ssl = subdomain, username, password, ssl
end
|
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
7
8
9
|
# File 'lib/puavo/client/api/base.rb', line 7
def password
@password
end
|
#ssl ⇒ Object
Returns the value of attribute ssl.
7
8
9
|
# File 'lib/puavo/client/api/base.rb', line 7
def ssl
@ssl
end
|
#subdomain ⇒ Object
Returns the value of attribute subdomain.
7
8
9
|
# File 'lib/puavo/client/api/base.rb', line 7
def subdomain
@subdomain
end
|
#username ⇒ Object
Returns the value of attribute username.
7
8
9
|
# File 'lib/puavo/client/api/base.rb', line 7
def username
@username
end
|
Class Method Details
.model_name(klass) ⇒ Object
22
23
24
|
# File 'lib/puavo/client/api/base.rb', line 22
def model_name(klass)
class_eval("def model_name() #{klass} end")
end
|
Instance Method Details
#all ⇒ Object
27
28
29
|
# File 'lib/puavo/client/api/base.rb', line 27
def all
self.model_name.parse( self, rest("#{url_prefix}#{self.model_name.model_path}").parsed_response )
end
|
#basic_auth ⇒ Object
13
14
15
|
# File 'lib/puavo/client/api/base.rb', line 13
def basic_auth
{ :username => @username, :password => @password }
end
|
#find_all_by_memberUid(uid) ⇒ Object
34
35
36
|
# File 'lib/puavo/client/api/base.rb', line 34
def find_all_by_memberUid(uid)
self.model_name.parse( self, rest("#{url_prefix}#{self.model_name.model_path}?memberUid=#{uid}").parsed_response )
end
|
#find_by_school_id(id) ⇒ Object
30
31
32
|
# File 'lib/puavo/client/api/base.rb', line 30
def find_by_school_id(id)
self.model_name.parse( self, rest("#{url_prefix}#{self.model_name.model_path(:school_id => id)}").parsed_response )
end
|
#rest(url) ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/puavo/client/api/base.rb', line 38
def rest(url)
self.class.get(url,
:basic_auth => basic_auth,
:headers => {
"Accept" => "application/json",
"Content-Type" => "application/json; charset=utf-8",
"User-Agent" => "PuavoClient/0.01" })
end
|
#url_prefix ⇒ Object
17
18
19
|
# File 'lib/puavo/client/api/base.rb', line 17
def url_prefix
(ssl ? 'https' : 'http') + "://" + @subdomain
end
|