module DList

Main module

Constants

API_PATH

API path prefix

CACHE_LIFETIME

Cache entry lifetime

Cache

Cache

IS_NUMBER

Regexp for checking if string is a number

VERSION

Wrapper version

Public Class Methods

_cache(name) { || ... } click to toggle source
# File lib/dblista.rb, line 94
def self._cache(name)
  DList::Cache.get(name.to_sym, lifetime: DList::CACHE_LIFETIME) { yield }
end
_delete(path, data = nil, token = nil) click to toggle source

@!visibility private

# File lib/dblista.rb, line 66
def self._delete(path, data = nil, token = nil)
  uri = URI("#{DList::API_PATH}#{path}")
  req = Net::HTTP::Delete.new(uri)
  _handle_request(req, uri, token, data)
end
_get(path, token = nil) click to toggle source

@!visibility private

# File lib/dblista.rb, line 52
def self._get(path, token = nil)
  uri = URI("#{DList::API_PATH}#{path}")
  req = Net::HTTP::Get.new(uri)
  _handle_request(req, uri, token, nil)
end
_handle_request(req, uri, token, data) click to toggle source

@!visibility private

# File lib/dblista.rb, line 40
def self._handle_request(req, uri, token, data)
  req.body = data.to_json if data
  req['Content-Type'] = 'application/json'
  req['Authorization'] = token if token
  response = _https(uri).request(req)
  result = JSON.parse response.body
  raise DList::Error, result['error'].capitalize unless result['status'] == 'success'

  result['data']
end
_https(uri) click to toggle source
# File lib/dblista.rb, line 33
def self._https(uri)
  Net::HTTP.new(uri.host, uri.port).tap do |http|
    http.use_ssl = true
  end
end
_limit_integer(input) click to toggle source

@!visibility private

# File lib/dblista.rb, line 90
def self._limit_integer(input)
  raise DList::Error, DList::Errors::LIMIT_INTEGER unless input.is_a?(Integer)
end
_page_integer(input) click to toggle source

@!visibility private

# File lib/dblista.rb, line 85
def self._page_integer(input)
  raise DList::Error, DList::Errors::PAGE_INTEGER unless input.is_a?(Integer)
end
_post(path, data = nil, token = nil) click to toggle source

@!visibility private

# File lib/dblista.rb, line 59
def self._post(path, data = nil, token = nil)
  uri = URI("#{DList::API_PATH}#{path}")
  req = Net::HTTP::Post.new(uri)
  _handle_request(req, uri, token, data)
end
_put(path, data = nil, token = nil) click to toggle source

@!visibility private

# File lib/dblista.rb, line 73
def self._put(path, data = nil, token = nil)
  uri = URI("#{DList::API_PATH}#{path}")
  req = Net::HTTP::Put.new(uri)
  _handle_request(req, uri, token, data)
end
_validate_id(id) click to toggle source

@!visibility private

# File lib/dblista.rb, line 80
def self._validate_id(id)
  raise DList::Error, DList::Errors::ID_NEEDED unless DList::IS_NUMBER.match?(id.to_s)
end