class BusinessCentral::RequestBuilder
An object to build the request object
Attributes
data[R]
etag[R]
request[RW]
url[R]
verb[R]
Public Class Methods
new(client, opts = {})
click to toggle source
@param client [BusinessCentral::Client] @param opts [Hash] Options used to build the request
# File lib/business_central/request_builder.rb, line 12 def initialize(client, opts = {}) @client = client @verb = opts[:verb] if opts.has_key?(:verb) @url = opts[:url] if opts.has_key?(:url) @etag = opts[:etag] if opts.has_key?(:etag) @data = opts[:data] if opts.has_key?(:data) build end
Public Instance Methods
add_data()
click to toggle source
If form data is supplied, add it to the request body as JSON
# File lib/business_central/request_builder.rb, line 41 def add_data return if @data.nil? @request.body = JSON.generate(@data) end
add_etag()
click to toggle source
If an etag is supplied, add it to the request in an ['If-Match'] header
# File lib/business_central/request_builder.rb, line 34 def add_etag return if @etag.nil? @request['If-Match'] = @etag end
build()
click to toggle source
Create the appropriate request object
Populates @request with the constructed object
# File lib/business_central/request_builder.rb, line 24 def build @request = request_object.new(uri) @request.content_type = "application/json" @request.basic_auth(@client.api_username, @client.api_password) add_etag add_data end
request_object()
click to toggle source
@returns [Net::HTTP::Request] object, based on the verb supplied in the initialization opts Hash
# File lib/business_central/request_builder.rb, line 49 def request_object Object.const_get("Net::HTTP::#{@verb.capitalize}") end
uri()
click to toggle source
Contstruct URI for the request
@returns [URI]
# File lib/business_central/request_builder.rb, line 57 def uri URI(@client.base_url + @url) end