class Omnijack::Endpoint

A parent class for Omnijack API endpoints

@author Jonathan Hartman <j@p4nt5.com>

Public Class Methods

new(name, args = {}) click to toggle source
Calls superclass method Omnijack::new
# File lib/omnijack/endpoint.rb, line 38
def initialize(name, args = {})
  super
  base_url(args[:base_url])
end

Public Instance Methods

[](key) click to toggle source

Make class items accessible via hash keys

@param key @return [String, NilClass]

# File lib/omnijack/endpoint.rb, line 58
def [](key)
  to_h[key]
end
base_url(arg = nil) click to toggle source

The base URL of the Omnitruck API

@param [String, NilClass] arg @return [String]

# File lib/omnijack/endpoint.rb, line 83
def base_url(arg = nil)
  # TODO: Better URL validation
  set_or_return(:base_url, arg, kind_of: String, default: DEFAULT_BASE_URL)
end
method_missing(method_id, args = nil) click to toggle source

Make class items accessible via methods

@param [Symbol] method_id

Calls superclass method
# File lib/omnijack/endpoint.rb, line 48
def method_missing(method_id, args = nil)
  args.nil? && to_h[method_id] || super
end
to_h() click to toggle source

Offer a hash representation of the object

@return [Hash]

# File lib/omnijack/endpoint.rb, line 67
def to_h
  # TODO: Use a Mash -- some keys are better off addressed as strings
  JSON.parse(raw_data, symbolize_names: true)
end

Private Instance Methods

api_url() click to toggle source

Construct the full API query URL from base + endpoint

@return [URI::HTTP, URI::HTTPS]

# File lib/omnijack/endpoint.rb, line 104
def api_url
  @api_url ||= URI.parse(::File.join(base_url, endpoint))
end
endpoint() click to toggle source

Return the API endpoint for the package list of this project

@return [String]

# File lib/omnijack/endpoint.rb, line 113
def endpoint
  cl = self.class.to_s.split(':')[-1].downcase.to_sym
  OMNITRUCK_PROJECTS[name][:endpoints][cl]
end
raw_data() click to toggle source

Fetch the raw data from the configured URI

@return [String]

# File lib/omnijack/endpoint.rb, line 95
def raw_data
  @raw_data ||= api_url.open.read
end