
June 24th, 2012, 08:27 PM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 1
Time spent in forums: 14 m 48 sec
Reputation Power: 0
|
|
|
Calling an RB File from another one
Hello,
I have a main RB file (gem) that runs, it's a siriproxy server. Basically, it runs and listens to commands and executes script when it catches matching text.
So I am now using an rb file seperately, which returns my paypal balance. So basically, paypal.rb when execute simply returns a number, a paypal balance.
I need to get the number that paypal.rb returns into the initial script.
Is it possible to do this and how would I go about that? I was thinking in my main program I can do "require paypal.rb"
and then I could call the command but I am not sure how?
Any help would be great.
The paypal.rb file contains this code,
Code:
require 'ruby-paypal'
username = 'xx'
password = 'xx'
signature = 'xx'
paypal = Paypal.new username, password, signature, :production
# silence annoying output
class CaptureOutput < IO
def initialize
super(2)
end
def write(text)
# send text to logfile
end
end
def silence
raise unless block_given?
dout, serr, sout = $defout, $stderr, $stdout
buf = CaptureOutput.new
begin
$defout = buf
$stderr = buf
$stdout = buf
yield
ensure
$defout, $stderr, $stdout = dout, serr, sout
end
end
silence do
paypal = paypal.make_nvp_call 'METHOD' => 'GetBalance'
end
if paypal.ack == 'Success'
puts paypal['L_AMT0']
end
|