opendatakit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/opendatakit.rb +42 -17
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5bd13e9f36c32c40330ac4d04c107397dd8c8c9
4
- data.tar.gz: ee33088cee8df395501ce708fc25225f1b0e9bea
3
+ metadata.gz: 16562bcc4a06f24a850b59f82e505fcbdde3c25a
4
+ data.tar.gz: cd01c37a8f5ec287d5521142b2185eb9916612e2
5
5
  SHA512:
6
- metadata.gz: 86bd8d742e02f783d73aa8810ecbc1930d099fed3145b3b791c378e34b5f4a676240e649c630450c6d3374d2a3313111dad15944be83ac8a3e62a36191ddaf70
7
- data.tar.gz: a66fbf25df83cdacf00ea1a8e23a70efd4e63cdb414957b81636a5212ea90e50667fe8aa26e85d83123e72adc7b7f007ffab295b924a8f28c7005288251fae7e
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
- puts @url
15
+ @url
11
16
  end
17
+
12
18
  def getSubmissions(formname)
13
- submission_url = URI.join(@url,"/view/submissionList")
14
- params = { :formId => formname}
15
- submission_url.query = URI.encode_www_form( params )
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
- if httpresults.status == 404
19
- puts "Form name not found"
20
- exit
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,"/formUpload")
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
- puts title.text
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
- puts httpresults.content
68
+ httpresults.content
45
69
  end
70
+
46
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opendatakit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jude Mwenda