class Typekitable::RequestFetcher

Constants

VALID_OPTIONS
VALID_TYPES

Attributes

options[R]
resource_id[R]
type[R]

Public Class Methods

new(type, options = {}, resource_id = nil) click to toggle source
# File lib/typekitable/request_fetcher.rb, line 10
def initialize(type, options = {}, resource_id = nil)
  @type = validate_type(type)
  @options = validate_options(options)
  @resource_id = resource_id
end

Public Instance Methods

parameters() click to toggle source
# File lib/typekitable/request_fetcher.rb, line 24
def parameters
  options
end
request_path() click to toggle source
# File lib/typekitable/request_fetcher.rb, line 16
def request_path
  request_config[type][:request_path]
end
response() click to toggle source
# File lib/typekitable/request_fetcher.rb, line 28
def response
  Request.new(request_path, verb, parameters).response
end
verb() click to toggle source
# File lib/typekitable/request_fetcher.rb, line 20
def verb
  request_config[type][:verb]
end

Private Instance Methods

request_config() click to toggle source
# File lib/typekitable/request_fetcher.rb, line 34
def request_config
  {
    :kit_list => {
      :request_path => "kits",
      :verb => "GET"
    },
    :kit_add => {
      :request_path => "kits",
      :verb => "POST"
    },
    :kit_info => {
      :request_path => "kits/#{resource_id}",
      :verb => "GET"
    },
    :kit_publish => {
      :request_path => "kits/#{resource_id}/publish",
      :verb => "POST"
    }
  }
end
validate_options(options_list) click to toggle source
# File lib/typekitable/request_fetcher.rb, line 61
def validate_options(options_list)
  if options_list.empty? || VALID_OPTIONS[:kit_add].all? {|element| options_list.keys.include?(element) }
    return options_list
  else
    raise InvalidOptionsError
  end
end
validate_type(type) click to toggle source
# File lib/typekitable/request_fetcher.rb, line 55
def validate_type(type)
  raise InvalidTypeError unless VALID_TYPES.include?(type)

  return type
end