Class: RemoteOK::Client
- Inherits:
-
Object
- Object
- RemoteOK::Client
- Includes:
- HTTParty
- Defined in:
- lib/remoteok/client.rb
Overview
Client class to interact with the API itself
Instance Method Summary collapse
-
#initialize(**config) ⇒ Client
constructor
A new instance of Client.
- #jobs(*tags) ⇒ Object
- #legal ⇒ Object
- #with_fetch(params = {}) ⇒ Object
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: stringify() } if &.any? with_fetch unless @data return unless @data.any? @data[1..].map { |job_data| RemoteOK::Job.new(job_data) } end |
#legal ⇒ Object
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 = {}) = { headers: { 'User-Agent' => @user_agent } } [:query] = params if params&.any? [:debug_output] = $stdout if @debug response = self.class.get @base_url, @data = JSON.parse(response.body) self end |