Class: RemoteOK::Client

Inherits:
Object
  • Object
show all
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.



10
11
12
13
# File 'lib/remoteok/client.rb', line 10

def initialize(**config)
  @base_url = config[:base_url] || "https://remoteok.com/api"
  @user_agent = config[:user_agent] || default_user_agent
end

Instance Method Details

#jobs(*tags) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/remoteok/client.rb', line 35

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


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

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

#with_fetch(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/remoteok/client.rb', line 15

def with_fetch(params = {})
  uri = URI(@base_url)
  uri.query = URI.encode_www_form(params) if params&.any?

  headers = {"User-Agent" => @user_agent}

  @data = Sync do
    internet = Async::HTTP::Internet.new
    response = internet.get(uri, headers)
    JSON.parse(response.read)
  end

  self
end