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
require 'uri'
require 'net/http'
require 'net/https'
require 'rubygems'
require 'json'
API_URL = 'https://sandbox.mobileworks.com/api/v1/tasks/'
USERNAME = 'foo'
PASSWORD = 'fo\''
url = URI(API_URL)
http = Net::HTTP.new(url.host, 443)
http.use_ssl = true
http.start {|http|
headers = {'Content-Type' => 'application/json'}
req = Net::HTTP::Post.new(url.path, headers)
req.basic_auth(USERNAME, PASSWORD)
query = {
'question' => 'your instructions here',
'resource'=> 'http://anylinkhere.com',
'answerType' => 't',
'resourceType' => 'l'
}
req.body = query.to_json()
response = http.request(req)
if response.code == '201'
puts response['location']
else
puts 'Error. Response code: ' + response.code
end
}