Class: Vzaar::Request::Base

Inherits:
Struct
  • Object
show all
Includes:
Helper
Defined in:
lib/vzaar/request/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#blank?, #hash_to_xml, #symb_keys

Instance Attribute Details

#connObject

Returns the value of attribute conn

Returns:

  • (Object)

    the current value of conn



3
4
5
# File 'lib/vzaar/request/base.rb', line 3

def conn
  @conn
end

#optsObject

Returns the value of attribute opts

Returns:

  • (Object)

    the current value of opts



3
4
5
# File 'lib/vzaar/request/base.rb', line 3

def opts
  @opts
end

Class Method Details

.endpoint(obj = nil, &fn) ⇒ Object



16
17
18
# File 'lib/vzaar/request/base.rb', line 16

def endpoint(obj=nil, &fn)
  define_method(:endpoint) { block_given? ? yield(self) : obj }
end

.format(f) ⇒ Object



24
25
26
27
28
29
# File 'lib/vzaar/request/base.rb', line 24

def format(f)
  define_method(:format) do
    # JC: options should always overwrite format param
    self.options[:format] ? self.options[:format] : f
  end
end

.resource(name) ⇒ Object



20
21
22
# File 'lib/vzaar/request/base.rb', line 20

def resource(name)
  define_method(:resource) { name }
end

Instance Method Details

#executeObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/vzaar/request/base.rb', line 36

def execute
  conn.using_connection(url, user_options) do |res|
    _res = Response::Base.new(res)
    if _res.json?
      return _res.body
    else
      return resource_klass.new(_res.body, res.code)
    end
  end
end