Class: URL::Service::Endpoint

Inherits:
Object
  • Object
show all
Includes:
AcceptsEndpoint
Defined in:
lib/url/endpoint.rb

Defined Under Namespace

Classes: EndpointNotResponding, RequiredParameter

Constant Summary collapse

BUILT_IN_MAP =

Define the built in methods and their fetcher aliases

{
  :get => %w{find},
  :post => %w{create},
  :put => %w{update},
  :delete => %w{destroy}
}.each do |method,aliases|
  class_eval <<-RUBY, __FILE__, __LINE__
    def #{method} params = {}, opts = {}
      u = @url.dup
      u.params.merge! params

      u.#{method} opts
    end
  RUBY
  aliases.each do |al|
    class_eval <<-RUBY, __FILE__, __LINE__
      def #{al} params={}, opts={}
        transform_response #{method}(params, opts)
      end
    RUBY
  end
end.freeze
BUILT_IN_METHODS =
BUILT_IN_MAP.collect do |k,v|
  v.collect{|vv| vv.to_sym}+[k.to_sym]
end.flatten.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AcceptsEndpoint

#endpoint

Constructor Details

#initialize(url) ⇒ Endpoint

Returns a new instance of Endpoint.



40
41
42
# File 'lib/url/endpoint.rb', line 40

def initialize url
  @base_url = @url = url
end

Instance Attribute Details

#inflate_intoObject

Returns the value of attribute inflate_into.



4
5
6
# File 'lib/url/endpoint.rb', line 4

def inflate_into
  @inflate_into
end

Instance Method Details

#class_eval(*args, &blk) ⇒ Object

Expose class eval externally



45
46
47
# File 'lib/url/endpoint.rb', line 45

def class_eval *args,&blk
  eigenclass.class_eval *args,&blk
end

#eigenclassObject



49
50
51
# File 'lib/url/endpoint.rb', line 49

def eigenclass
  class << self; self; end
end

#inspectObject



53
54
55
# File 'lib/url/endpoint.rb', line 53

def inspect
  %Q{#<#{self.class} #{@url.to_s}>}
end

#method_inflate_intoObject

Storage for what each endpoint should inflate into



8
9
10
# File 'lib/url/endpoint.rb', line 8

def method_inflate_into
  @method_inflate_into ||= {}
end