Ruby is an interpreted, high-level, general-purpose programming language which supports multiple programming paradigms. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including primitive data types. It was developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
Apify Ruby SDK Unofficial Unstable Unsupported Under Maintenance. Inspired by Apify Python SDK
Disclaimer : This library is community library and not supported by Apify
Included :
- Apify SDK (unofficial)
- Apify Client (unofficial)
Source Code :
Important Notes (for Ruby beginner like me) :
- On ruby all evaluated to
trueexcept for:falseandnil. - Function will return value from last expression.
Developer Notes
- Some method is conflicting with Ruby internal method such as:
.initialize,.exit,.fail, etc. Renamed to:.initialize_,.exit_,.fail_etc.
git clone https://github.com/JupriGH/apify-ruby-sdk.git# import inside script
require_relative './apify-ruby-sdk/lib/apify_sdk'logger = Apify::Log
# level: INFO | WARN | ERROR | FATAL | UNKNOWN
logger.level = Logger::DEBUG
# Formatter
logger.formatter = Apify::ActorLogFormatter.new# SYNC Mode
# won't be able to receive platform events (aborting, migration, etc.)
# for testing on local development (eg: IRB)
Apify::Actor.main(<callable>)
# ASYNC Mode
# use on apify platform to receive platform events
Async do
Apify::Actor.main(<callable>)
endExample #1
Apify::Actor.main( lambda { |actor|
input = actor.get_input
0 # optional exit code
})or
actor = Apify::Actor
actor.main( lambda {
input = actor.get_input
0 # optional exit code
})Example #2
def main(actor)
input = actor.get_input
end
Apify::Actor.main( method(:main) )Use with function to emulate Python context manager
# SYNC Mode
with Apify::Actor do |actor|
input = actor.get_input
end
# ASYNC Mode
Async do
with Apify::Actor do |actor|
input = actor.get_input
end
enddo ... end can be replaced with { ... }
Async {
with Apify::Actor { |actor|
input = actor.get_input
}
}