Class: RemoteOK::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/remoteok/client.rb

Overview

Client class to interact with the API itself

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
# 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

Instance Method Details

#jobs(*tags) ⇒ Object



34
35
36
37
38
39
40
41
42
# 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


29
30
31
32
# File 'lib/remoteok/client.rb', line 29

def legal
  with_fetch unless @data
  @data.first['legal']
end

#with_fetch(params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# 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