forked from ckolivas/cgminer
-
Notifications
You must be signed in to change notification settings - Fork 30
/
api-example.rb
38 lines (30 loc) · 846 Bytes
/
api-example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
# Copyright 2014 James Hilliard
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version. See COPYING for more details.
require 'socket'
require 'json'
api_command = ARGV[0].split(":")
if ARGV.length == 3
api_ip = ARGV[1]
api_port = ARGV[2]
elsif ARGV.length == 2
api_ip = ARGV[1]
api_port = 4028
else
api_ip = "127.0.0.1"
api_port = 4028
end
s = TCPSocket.open(api_ip, api_port)
if api_command.count == 2
s.write({ :command => api_command[0], :parameter => api_command[1]}.to_json)
else
s.write({ :command => api_command[0]}.to_json)
end
response = s.read.strip
response = JSON.parse(response)
puts response
s.close