class RemoteOK::Client

Client class to interact with the API itself

Public Class Methods

new(**config) click to toggle source
# File lib/remoteok/client.rb, line 12
def initialize(**config)
  @base_url = config[:base_url] || 'https://remoteok.io/api'
  @debug = config[:debug] || false
  @user_agent = config[:user_agent] || default_user_agent
end

Public Instance Methods

jobs(*tags) click to toggle source
# File lib/remoteok/client.rb, line 34
def jobs(*tags)
  options = { tags: stringify(tags) } if tags&.any?

  with_fetch options unless @data

  return unless @data.any?

  @data[1..].map { |job_data| RemoteOK::Job.new(job_data) }
end
with_fetch(params = {}) click to toggle source
# File lib/remoteok/client.rb, line 18
def with_fetch(params = {})
  options = { headers: { 'User-Agent' => @user_agent } }
  options[:query] = params if params&.any?
  options[:debug_output] = $stdout if @debug

  response = self.class.get @base_url, options

  @data = JSON.parse(response.body)
  self
end

Private Instance Methods

default_user_agent() click to toggle source
# File lib/remoteok/client.rb, line 52
def default_user_agent
  "remote-ok-ruby/#{RemoteOK::VERSION} +http://github.com/RemoteCTO/remote-ok-ruby"
end
stringify(tags = []) click to toggle source
# File lib/remoteok/client.rb, line 46
def stringify(tags = [])
  return unless tags.any?

  tags.map { |tag| tag.to_s.gsub('_', ' ') }.join ','
end