File: api-example.rb

package info (click to toggle)
bfgminer 4.7.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,116 kB
  • ctags: 9,129
  • sloc: ansic: 62,470; lisp: 5,221; sh: 4,572; php: 2,645; asm: 667; makefile: 427; python: 85; ruby: 23
file content (38 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (3)
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