Class: Acfs::Request

Inherits:
Object
  • Object
show all
Includes:
Callbacks
Defined in:
lib/acfs/request.rb,
lib/acfs/request/callbacks.rb
more...

Overview

Encapsulate all data required to make up a request to the underlaying http library.

Defined Under Namespace

Modules: Callbacks

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

#callbacks, #complete!, #on_complete

Constructor Details

#initialize(url, **options, &block) ⇒ Request

Returns a new instance of Request.

[View source]

14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/acfs/request.rb', line 14

def initialize(url, **options, &block)
  @uri = URI.parse(url.to_s).tap do |_url|
    @data    = options.delete(:data) || nil
    @format  = options.delete(:format) || :json
    @headers = options.delete(:headers) || {}
    @params  = options.delete(:params) || {}
    @method  = options.delete(:method) || :get
  end
  @url = @uri.to_s

  @operation = options.delete(:operation) || nil

  on_complete(&block) if block
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.


10
11
12
# File 'lib/acfs/request.rb', line 10

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.


11
12
13
# File 'lib/acfs/request.rb', line 11

def data
  @data
end

#formatObject

Returns the value of attribute format.


10
11
12
# File 'lib/acfs/request.rb', line 10

def format
  @format
end

#headersObject (readonly)

Returns the value of attribute headers.


11
12
13
# File 'lib/acfs/request.rb', line 11

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.


11
12
13
# File 'lib/acfs/request.rb', line 11

def method
  @method
end

#operationObject (readonly)

Returns the value of attribute operation.


11
12
13
# File 'lib/acfs/request.rb', line 11

def operation
  @operation
end

#paramsObject (readonly)

Returns the value of attribute params.


11
12
13
# File 'lib/acfs/request.rb', line 11

def params
  @params
end

#uriObject (readonly)

Returns the value of attribute uri.


11
12
13
# File 'lib/acfs/request.rb', line 11

def uri
  @uri
end

#urlObject (readonly)

Returns the value of attribute url.


11
12
13
# File 'lib/acfs/request.rb', line 11

def url
  @url
end

Instance Method Details

#data?Boolean

Returns:

  • (Boolean)
[View source]

29
30
31
# File 'lib/acfs/request.rb', line 29

def data?
  !data.nil?
end