Sha256: a942852c5eedca903a7f423c31f72cd6695c33ad4cad4beb6f569bd819f6a3ec
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
module Stir module Endpoints def self.included(base) base.extend(ClassMethods) end def routes(name, *args) endpoints = self.class.send(:endpoints) endpoint = nil endpoints.each {|x| endpoint = x[name.to_sym] if x[name.to_sym]} return nil if endpoint.nil? base_uri + endpoint.interpolate(args.first) end private module ClassMethods def get(name, &block) endpoint(name, :get, &block) end def put(name, &block) endpoint(name, :put, &block) end def post(name, &block) endpoint(name, :post, &block) end def head(name, &block) endpoint(name, :head, &block) end def delete(name, &block) endpoint(name, :delete, &block) end private def endpoint(name, method, &block) send(:define_method, name) do |*args| @response = HTTParty.send(method, URI.escape(yield.interpolate(args.first)), merge_configs(args.flatten.first)) end endpoints.push({name => yield.to_s}) end def endpoints @endpoints ||= [] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stir-2.1.1 | lib/stir/rest/endpoints.rb |