opendatakit 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/opendatakit.rb +42 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16562bcc4a06f24a850b59f82e505fcbdde3c25a
|
4
|
+
data.tar.gz: cd01c37a8f5ec287d5521142b2185eb9916612e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cf6e5744a0b449c93b7c53b0a7acfe19ee242742b8e0e4a4378a71dc8e8e7bf47214990c44ca93702f6ee1f2d2fb5af64dab367feeef7a9053b629f69b36d91
|
7
|
+
data.tar.gz: 69b1616e0d43c755e76a17fa593a16639903b160e0572b041f0515e0b73910238cb5bfc321848bdd7ec1c182027a52ebcbb00dce173fd58640fde2d13d4ffac7
|
data/lib/opendatakit.rb
CHANGED
@@ -1,46 +1,71 @@
|
|
1
1
|
require 'httpclient'
|
2
2
|
require 'uri'
|
3
3
|
require 'rexml/document'
|
4
|
+
require 'stringio'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
4
7
|
class OdkInstance
|
5
8
|
attr_accessor:url
|
9
|
+
|
6
10
|
def initialize(url)
|
7
11
|
@url = URI.parse(url)
|
8
12
|
end
|
13
|
+
|
9
14
|
def url
|
10
|
-
|
15
|
+
@url
|
11
16
|
end
|
17
|
+
|
12
18
|
def getSubmissions(formname)
|
13
|
-
submission_url = URI.join(@url,"
|
14
|
-
params = { :formId => formname}
|
15
|
-
submission_url.query = URI.encode_www_form(
|
19
|
+
submission_url = URI.join(@url,"view/submissionList")
|
20
|
+
params = { :formId => formname }
|
21
|
+
submission_url.query = URI.encode_www_form(params)
|
22
|
+
|
16
23
|
http = HTTPClient.new
|
17
24
|
httpresults = http.get submission_url
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
|
26
|
+
if httpresults.status == 200
|
27
|
+
submission_xml = httpresults.content
|
28
|
+
doc = REXML::Document.new(submission_xml)
|
29
|
+
all_id_elements = doc.elements.to_a( "//id" ).map { |el| el.text }
|
30
|
+
else
|
31
|
+
"Form name not found"
|
21
32
|
end
|
22
|
-
submission_xml = httpresults.content
|
23
|
-
doc = REXML::Document.new(submission_xml)
|
24
|
-
submissions = []
|
25
|
-
all_upc_strings = doc.elements.to_a("idChunk/idList")
|
26
|
-
all_id_elements = doc.elements.to_a( "//id" )
|
27
|
-
#doc.elements.each("idChunk/idList") { |element| submissions.push(element.elements["id"].text) }
|
28
|
-
puts all_id_elements
|
29
33
|
end
|
34
|
+
|
30
35
|
def uploadForm(form_xml)
|
31
|
-
form_post_url = URI.join(@url,"
|
36
|
+
form_post_url = URI.join(@url,"formUpload")
|
32
37
|
params = { :form_def_file => File.open(form_xml)}
|
33
38
|
doc = REXML::Document.new(File.open(form_xml))
|
34
39
|
title = REXML::XPath.first( doc, "//h:title" )
|
40
|
+
|
35
41
|
http = HTTPClient.new
|
36
42
|
httpresults = http.post(form_post_url,params)
|
37
|
-
|
43
|
+
|
44
|
+
if httpresults.status_code == 201
|
45
|
+
title.text
|
46
|
+
else
|
47
|
+
"Form could not be uploaded"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
def uploadXmlform(doc)
|
51
|
+
form_post_url = URI.join(@url,"formUpload")
|
52
|
+
params = { :form_def_file => StringIO.new(doc.to_xml) }
|
53
|
+
http = HTTPClient.new
|
54
|
+
httpresults = http.post(form_post_url,params)
|
55
|
+
if httpresults.status_code == 201
|
56
|
+
httpresults.status_code
|
57
|
+
else
|
58
|
+
"Form could not be uploaded"
|
59
|
+
end
|
38
60
|
end
|
61
|
+
|
39
62
|
def addSubmissions(submission_data,media_files)
|
40
63
|
submission_post_url = URI.join(@url,"submission")
|
41
64
|
params = { :xml_submission_file => File.open(submission_data)}
|
65
|
+
|
42
66
|
http = HTTPClient.new
|
43
67
|
httpresults = http.post(submission_post_url,params)
|
44
|
-
|
68
|
+
httpresults.content
|
45
69
|
end
|
70
|
+
|
46
71
|
end
|