Class: WEB_API::WebApi

Inherits:
Object
  • Object
show all
Defined in:
lib/web_api/web_api.rb

Direct Known Subclasses

Auth, Auto, Client

Constant Summary collapse

@@trace =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base = nil) ⇒ WebApi

Returns a new instance of WebApi.



100
101
102
103
# File 'lib/web_api/web_api.rb', line 100

def initialize(base=nil)
  @base = base
  @webmethods = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



105
106
107
108
# File 'lib/web_api/web_api.rb', line 105

def method_missing(symbol , *args)
  super unless @webmethods.has_key?(symbol)
  @webmethods[symbol].call(args)
end

Instance Attribute Details

#webmethodsObject (readonly)

Returns the value of attribute webmethods.



99
100
101
# File 'lib/web_api/web_api.rb', line 99

def webmethods
  @webmethods
end

Class Method Details

.traceObject



92
93
94
# File 'lib/web_api/web_api.rb', line 92

def self.trace
  @@trace
end

.trace=(trace) ⇒ Object



95
96
97
# File 'lib/web_api/web_api.rb', line 95

def self.trace=(trace)
  @@trace=trace
end

Instance Method Details

#_add(method, uri, type) ⇒ Object



110
111
112
# File 'lib/web_api/web_api.rb', line 110

def _add(method, uri, type)
  @webmethods[method] = WebApiMethod.new(uri, type)
end

#_url(path) ⇒ Object



114
115
116
# File 'lib/web_api/web_api.rb', line 114

def _url(path)
  (@base)? File.join(@base, path) : path
end

#add(method, path, type = :get) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/web_api/web_api.rb', line 118

def add(method, path, type=:get)
  method         = method.downcase.to_sym
  uri            = URI.parse _url(path)
  type           = type.downcase.to_sym
  raise "#{method} already defined" if @webmethods.include?(method)
  webmethod      = _add(method, uri, type)
  if @base
    webmethod.base = @base
    webmethod.path = path
  end
end