Module: Voorhees::Resource::ClassMethods
- Defined in:
- lib/voorhees/resource.rb
Instance Method Summary collapse
- #json_request(klass = nil) {|request| ... } ⇒ Object
- #json_service(name, request_options = {}) ⇒ Object
- #new_from_json(json, hierarchy = nil) ⇒ Object
Instance Method Details
#json_request(klass = nil) {|request| ... } ⇒ Object
36 37 38 39 40 |
# File 'lib/voorhees/resource.rb', line 36 def json_request(klass=nil) request = Voorhees::Request.new(klass || self) yield request request.perform.to_objects end |
#json_service(name, request_options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/voorhees/resource.rb', line 22 def json_service(name, ={}) (class << self; self; end).instance_eval do define_method name do |*args| params = args[0] json_request do |r| r.parameters = params if params.is_a?(Hash) .each do |option, value| r.send("#{option}=", value) end end end end end |
#new_from_json(json, hierarchy = nil) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/voorhees/resource.rb', line 15 def new_from_json(json, hierarchy=nil) obj = self.new obj.raw_json = json obj.json_hierarchy = hierarchy obj end |