Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,54 @@ PATH
remote: .
specs:
remoteok (0.1.0)
httparty (~> 0.18.1)
async-http

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
async (2.20.0)
console (~> 1.29)
fiber-annotation
io-event (~> 1.6, >= 1.6.5)
async-http (0.83.1)
async (>= 2.10.2)
async-pool (~> 0.9)
io-endpoint (~> 0.14)
io-stream (~> 0.6)
metrics (~> 0.12)
protocol-http (~> 0.43)
protocol-http1 (>= 0.28.1)
protocol-http2 (~> 0.19)
traces (~> 0.10)
async-pool (0.10.2)
async (>= 1.25)
traces
console (1.29.0)
fiber-annotation
fiber-local (~> 1.1)
json
diff-lcs (1.4.4)
docile (1.3.5)
httparty (0.18.1)
mime-types (~> 3.0)
multi_xml (>= 0.5.2)
fiber-annotation (0.2.0)
fiber-local (1.1.0)
fiber-storage
fiber-storage (1.0.0)
io-endpoint (0.14.0)
io-event (1.7.3)
io-stream (0.6.1)
json (2.5.1)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an older version of the json gem (2.5.1). More recent versions include security fixes and performance improvements. Should upgrade to latest stable version.

mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2021.0225)
multi_xml (0.6.0)
metrics (0.12.1)
parallel (1.20.1)
parser (3.0.1.1)
ast (~> 2.4.1)
protocol-hpack (1.5.1)
protocol-http (0.44.0)
protocol-http1 (0.28.1)
protocol-http (~> 0.22)
protocol-http2 (0.20.0)
protocol-hpack (~> 1.4)
protocol-http (~> 0.18)
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.1.1)
Expand Down Expand Up @@ -60,9 +89,11 @@ GEM
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
traces (0.14.1)
unicode-display_width (2.0.0)

PLATFORMS
arm64-darwin-24
x86_64-darwin-19

DEPENDENCIES
Expand Down
9 changes: 5 additions & 4 deletions lib/remoteok/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ module RemoteOK
# Client class to interact with the API itself
class Client
require 'json'
require 'httparty'
require 'async/http/internet'
require_relative 'job'

include HTTParty

def initialize(**config)
@base_url = config[:base_url] || 'https://remoteok.io/api'
@debug = config[:debug] || false
Expand All @@ -20,7 +18,10 @@ def with_fetch(params = {})
options[:query] = params if params&.any?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safe navigation operator (&.) with any? could cause issues if params is not nil but also not a collection that responds to any?. Should check if params is a Hash first or use params.is_a?(Hash) && !params.empty?

options[:debug_output] = $stdout if @debug

response = self.class.get @base_url, options
response = Sync do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code uses 'Sync' which appears to be undefined. For async/await pattern in Ruby, it should be 'Async' (capital A) instead of 'Sync'. This is a common class provided by the async gem.

internet = Async::HTTP::Internet.new
internet.get @base_url, options
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Async::HTTP::Internet#get method expects headers to be passed directly, not nested in an options hash. The correct format should be internet.get(@base_url, headers: { 'User-Agent' => @user_agent })

end

@data = JSON.parse(response.body)
self
Expand Down
2 changes: 1 addition & 1 deletion remoteok.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

# Prod dependencies
spec.add_dependency 'httparty', '~> 0.18.1'
spec.add_dependency 'async-http'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency is specified without a version constraint. This can lead to compatibility issues if breaking changes are introduced in future versions. It's recommended to specify version constraints for all dependencies (e.g. '~> 1.0').


# Dev dependencies
spec.add_development_dependency 'simplecov', '< 0.18'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an upper bound version constraint ('< 0.18') without a lower bound can be problematic. It's better to specify a range with both lower and upper bounds (e.g. '>= 0.17.1, < 0.18') to ensure compatibility.

Expand Down
Loading