Module: Arcgis::Base::ClassMethods
- Defined in:
- lib/arcgis/base.rb
Instance Method Summary collapse
-
#extend_api(api, definition) ⇒ Object
Factory for building API endpoints from Definitions.
Instance Method Details
#extend_api(api, definition) ⇒ Object
Factory for building API endpoints from Definitions
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/arcgis/base.rb', line 9 def extend_api(api,definition) definition.each do |parent,ops| ops.each do |op,methods| methods.each do |method| # build the method, but allow for 'root' level methods with the parent # (e.g. /community/user = user_community; /community/user/update = user_update) subapi = method.length == 0 ? parent.to_s : method define_method("#{api}_#{subapi}".gsub(/_$/,'')) { || # differentiate 'items' for /content/ from '' for /community/ - e.g. content/users/id vs. community/users/id url = "#{self.send(parent.to_s+'_url')}#{self.send(api.to_s+'_url')}#{options.delete(:id)}/#{method.gsub(/items/,'')}" url.gsub!(/\/+/, '/') url.gsub!(/community\/community/,'community') self.send(op,url,) } end end end end |