Class: Fabricio::Networking::RequestModel

Inherits:
Object
  • Object
show all
Defined in:
lib/fabricio/networking/request_model.rb

Overview

A data structure that provides all values necessary for making an API request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { :type => :GET, :base_url => '', :api_path => '', :headers => {}, :body => nil, :params => {} }) {|_self| ... } ⇒ Fabricio::Networking::RequestModel

Initializes a new RequestModel object. You can use a block to fill all the options: model = Fabricio::Networking::RequestModel.new do |config|

config.type = :GET
config.base_url = FABRIC_API_URL
config.api_path = '/apps'

end

Parameters:

  • options (Hash) (defaults to: { :type => :GET, :base_url => '', :api_path => '', :headers => {}, :body => nil, :params => {} })

    Hash containing customizable options

Options Hash (options):

  • :type (String)

    Request type - :GET or :POST

  • :base_url (String)

    The base_url. E.g. ‘fabric.io

  • :api_path (String)

    An API endpoint path. E.g. ‘/apps’

  • :headers (Hash)

    All request headers

  • :body (Hash)

    Request body

  • :params (Hash)

    Request url parameters

Yields:

  • (_self)

Yield Parameters:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fabricio/networking/request_model.rb', line 23

def initialize(options =
                   {
                       :type => :GET,
                       :base_url => '',
                       :api_path => '',
                       :headers => {},
                       :body => nil,
                       :params => {}
                   })
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
end

Instance Attribute Details

#api_pathObject

Returns the value of attribute api_path.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def api_path
  @api_path
end

#base_urlObject

Returns the value of attribute base_url.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def base_url
  @base_url
end

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def body
  @body
end

#headersObject

Returns the value of attribute headers.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def headers
  @headers
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def params
  @params
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/fabricio/networking/request_model.rb', line 6

def type
  @type
end