Class: RemoteResource::Connection

Inherits:
Object
  • Object
show all
Includes:
PartyQuery
Defined in:
lib/remote_resource/connection.rb

Direct Known Subclasses

Html::Connection, Json::Connection

Instance Method Summary collapse

Methods included from PartyQuery

#query

Instance Method Details

#request(path, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/remote_resource/connection.rb', line 6

def request(path, options={})
  separate = options[:separate]

  if options[:unwrap]
    original_parser  = self.class.parser
    options[:parser] = Proc.new { |body|
      body = options[:unwrap].call(body)
      original_parser.call(body)
    }
  end

  result = query(path, options)
  Array.wrap(
      if separate.try(:[], :json)
        separate[:json].inject(result) { |r, p| r.try(:[], p.to_s) }
      elsif separate.try(:[], :css)
        result.css(separate[:css])
      else
        result
      end
  )
end