class Bloopi::HTTPService::Request

Attributes

raw_args[R]
raw_options[R]
raw_path[R]
raw_verb[R]

Public Class Methods

new(path: path, verb: verb, args: {}, options: {}) click to toggle source

@param path the server path for this request @param args @param verb the HTTP method to use.

If not get or post, this will be turned into a POST request with the appropriate :method
specified in the arguments.

@param options various flags to indicate which server to use. @param options @option options :use_ssl force https, even if not needed @option options :json whether or not to send JSON to Bloopi

# File lib/bloopi/http_service/request.rb, line 15
def initialize(path: path, verb: verb, args: {}, options: {})
  @raw_path = path
  @raw_args = args
  @raw_verb = verb
  @raw_options = options
end

Public Instance Methods

get_args() click to toggle source
# File lib/bloopi/http_service/request.rb, line 53
def get_args
  raw_verb == "get" ? args : {}
end
json?() click to toggle source

Whether or not this request should use JSON.

@return true or false

# File lib/bloopi/http_service/request.rb, line 72
def json?
  raw_options[:format] == :json
end
options() click to toggle source

Calculates a set of request options to pass to Faraday.

@return a hash combining GET parameters (if appropriate), default options, and any specified for the request.

# File lib/bloopi/http_service/request.rb, line 61
def options
  # figure out our options for this request
  add_ssl_options(
    # for GETs, we pass the params to Faraday to encode
    {params: get_args}.merge(HTTPService.http_options).merge(raw_options)
  )
end
path() click to toggle source

Determines the path to be requested on Bloopi, incorporating an API version if specified.

@return the original path, with API version if appropriate.

# File lib/bloopi/http_service/request.rb, line 32
def path
  # if an api_version is specified and the path does not already contain
  # one, prepend it to the path
  api_version = raw_options[:api_version] || Bloopi.config.api_version
  "/#{api_version}/#{raw_path}"
end
post_args() click to toggle source

Determines any arguments to be sent in a POST body.

@return {} for GET; the provided args for POST; those args with the method parameter for other values

# File lib/bloopi/http_service/request.rb, line 43
def post_args
  if raw_verb == "get"
    {}
  elsif raw_verb == "post"
    args
  else
    args.merge(method: raw_verb)
  end
end
server() click to toggle source

The address of the appropriate Bloopi server.

@return a complete server address with protocol

# File lib/bloopi/http_service/request.rb, line 79
def server
  uri = "#{options[:use_ssl] ? "https" : "http"}://#{Bloopi.config.api_server}"
end
verb() click to toggle source

Determines which type of request to send to Bloopi. Bloopi natively accepts GETs and POSTs, for others we have to include the method in the post body.

@return one of get or post

# File lib/bloopi/http_service/request.rb, line 25
def verb
  ["get", "post"].include?(raw_verb) ? raw_verb : "post"
end

Protected Instance Methods

add_ssl_options(opts) click to toggle source
# File lib/bloopi/http_service/request.rb, line 90
def add_ssl_options(opts)
  # require https if there's a token
  return opts unless raw_args["access_token"]

  {
    use_ssl: true,
    ssl: {verify: true}.merge(opts[:ssl] || {})
  }.merge(opts)
end
args() click to toggle source

The arguments to include in the request.

# File lib/bloopi/http_service/request.rb, line 86
def args
  raw_args
end