Permalink
Browse files

Merge pull request #1 from albertein/ruby-client

Ruby client
  • Loading branch information...
2 parents fe37f2e + 2931b07 commit 3a945be28d5d01fa9068394a82a341189fbb5eda @aespinoza committed Mar 8, 2012
Showing with 64 additions and 0 deletions.
  1. +9 −0 RubyClient/README.md
  2. +52 −0 RubyClient/src/client.rb
  3. +3 −0 RubyClient/src/config
View
@@ -0,0 +1,9 @@
+ruby client
+===========
+
+Rudimentary ruby client for iKnode REST Api
+
+Example:
+```
+./client.rb "MyApplication:Test --param1=value1 --param2=value2"
+```
View
@@ -0,0 +1,52 @@
+#!/usr/bin/ruby
+require 'net/http'
+def main()
+ service_url = ""
+ api_key = ""
+ user_id = ""
+
+ #parse config file
+ file = File.new("config", "r")
+ line_count = 0
+ while (line = file.gets)
+ line = line.split("=")
+ line_count += 1
+ if line.length != 2
+ abort "Error on config file, line " + line_count.to_s
+ end
+ key = line[0].strip
+ value = line[1].strip
+ if key == "service_url"
+ service_url = value
+ elsif key == "api_key"
+ api_key = value
+ elsif key == "user_id"
+ user_id = value
+ end
+ end
+ file.close
+ if service_url == "" or api_key == "" or user_id == ""
+ abort "Incomplete config file, must contain service_url, api_key and user_id values"
+ end
+
+ #validate ARGV
+ if ARGV.length == 0
+ abort "Usage: ApplicationName:MethodName [--param_name=para_value]..."
+ end
+
+ #prepare request
+ uri = URI(service_url)
+ body = "{\"userId\": \"" + user_id + "\", \"apiKey\": \"" + api_key +
+ "\", \"command\": \""+ ARGV[0] + "\"}"
+ request = Net::HTTP::Post.new(uri.path, initheader = {"Content-Type" =>
+ "application/json"})
+ request.body = body
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = uri.scheme == 'https'
+ response = http.start do |http|
+ http.request(request)
+ end
+ puts response.body
+end
+
+main
View
@@ -0,0 +1,3 @@
+service_url = https://api.iknode.net/Commands/execute
+user_id =
+api_key =

0 comments on commit 3a945be

Please sign in to comment.