Class: Fred::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/fred.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attrs) ⇒ Base
Returns a new instance of Base.
14
15
16
|
# File 'lib/fred.rb', line 14
def initialize(attrs)
@attributes = attrs
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
11
12
13
|
# File 'lib/fred.rb', line 11
def attributes
@attributes
end
|
Class Method Details
.encode_params(args) ⇒ Object
36
37
38
39
|
# File 'lib/fred.rb', line 36
def self.encode_params(args)
args['api_key'] ||= api_key
args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless args.blank?
end
|
.find(params = {}) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/fred.rb', line 25
def self.find(params = {})
results = []
uri = base_url + "/" + collection_path + "?" + encode_params(params)
puts uri
doc = Hpricot.XML(open(uri))
doc.search("/*/*").each do |el|
results << new(el.attributes) if el.respond_to?(:attributes)
end
results
end
|
.get(id) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/fred.rb', line 18
def self.get(id)
uri = base_url + "/#{element_path}?api_key=#{api_key}&#{primary_key}=#{id}"
RAILS_DEFAULT_LOGGER.debug uri
doc = Hpricot.XML(open(uri))
new(doc.search("/*/*")[1].attributes)
end
|