formhub_ruby 0.0.3 → 0.0.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53e40696a5df2916c66b1c0147d072f249745cd3
4
- data.tar.gz: b75207dbede97b2e27594c4f441afd39b4503139
3
+ metadata.gz: 95753893821c1be2a8456e22fb70499992484a8d
4
+ data.tar.gz: a847323a8e96ec51dfa6137f75204c50d987dcc9
5
5
  SHA512:
6
- metadata.gz: 9e779da0e015cf45314fe0a3f25014366e11dafee2ada6503ce7bfe0cc42888d33d0ecbdd5d5982a821ce8c8acc1b04b10c3ca0fead91bb2d9f0885fb0589fe1
7
- data.tar.gz: 3bea5ec656654992ab7e089e7f2adda6c04aa080738be73ef44f071890cb932d07537bcd8ad723efb55c626e613790edd9bf7a276427517f2072bb817c337e25
6
+ metadata.gz: eab39d6ce6bb0b1de0a1302102913c47cc32b4a867f4ff4c9b374c74530644301c0e2ac69d1ff8394af193503dd9fdf73f934b9c626eb9eef1a6e64a0545208b
7
+ data.tar.gz: eff1f2671954992df3408fc050f52f716ae113d4c95d37260363bebac0142f7fadd37f687dbe8dbee48f6fcd6711a03d8ced9bf8486a6c088e673b6bd7a124ba
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FormhubRuby
2
2
 
3
- TODO: Write a gem description
3
+ A very simple Ruby Wrapper for the Formhub API
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,60 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ### Basic usage
22
+ This gem is a very simple API wrapper for the JSON API of [Formhub
23
+ ](https://formhub.org/) application.
24
+ More details on their JSON API can be foud on their [wiki page]( https://github.com/SEL-Columbia/formhub/wiki/Formhub-Access-Points-(API)).
25
+
26
+
27
+ ### Set a connection with the Formhub API
28
+
29
+ Create a connection like so:
30
+
31
+ connection = FormhubRuby::API.new(username: 'fake_username', password: 'fake_password', formnamne: 'my_form_name' )
32
+
33
+ You can also pass authentification configuration arguments in a block (e.g. in a initializer file, etc...):
34
+
35
+ FormhubRuby.configure do |config|
36
+ config.username = 'fake_username'
37
+ config.password = 'fake_password'
38
+ end
39
+
40
+ To get the actual data from the api call, call the fetch method on it:
41
+
42
+ connection.fetch
43
+
44
+ You should then be able to retrieve an array of hashes by using the data method
45
+
46
+ the_result = connection.data
47
+ the_result.first.name
48
+ # => Loic
49
+
50
+ If only want the actual count of rows is needed, use the count method:
51
+
52
+ connection.count
53
+ # => 4
54
+
55
+ Before fetching, a more refined query can be created by using a hash of queries:
56
+
57
+ connection.query = {age: 12}
58
+
59
+ You can set a start and limit for the rows returned
60
+
61
+ connection.start = 2
62
+ connection.limit = 2
63
+
64
+ and select the fields to be retrieved:
65
+
66
+ connection.fields = [:age, :name]
67
+
68
+ Finally you can also sort the results: 1 denotes an ascending sort while -1 denotes a descending sort:
69
+
70
+ connection.sort = {name: -1} # Descending by name
71
+ connection.sort = {name: 1} # Ascending by name
72
+
73
+ As far as I could tell though, the integers seem to be stored as strings in the Formhub database, so the sorting of these would be quite irrelevant.
74
+
22
75
 
23
76
  ## Contributing
24
77
 
data/formhub_ruby.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.add_dependency 'addressable'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.5'
22
24
  spec.add_development_dependency 'rake'
23
25
  spec.add_development_dependency 'rspec'
@@ -1,10 +1,12 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'cgi'
4
+ require 'addressable/uri'
5
+
4
6
  module FormhubRuby
5
7
  class ApiConnector
6
8
  attr_reader :formname, :filetype, :username, :password, :data
7
- attr_accessor :query, :start, :limit
9
+ attr_accessor :query, :start, :limit, :sort, :fields
8
10
 
9
11
 
10
12
  def initialize(args)
@@ -15,13 +17,27 @@ module FormhubRuby
15
17
  @query = args[:query]
16
18
  @start = args[:start]
17
19
  @limit = args[:limit]
20
+ @sort = args[:sort]
21
+ @fields = args[:fields]
22
+ @data = []
18
23
  end
19
24
 
20
25
  def fetch
21
- # CAN DO THAT A LATER STAGE: Define different url format
22
- # for different data point formats
23
- # uri = URI(form_uri)
24
- uri = URI(api_uri)
26
+ get_response(api_uri)
27
+ end
28
+
29
+ def get_count
30
+ response = get_response("#{api_uri}&count=1")
31
+ response[0]['count']
32
+ end
33
+
34
+
35
+
36
+
37
+ # private
38
+
39
+ def get_response(custom_uri)
40
+ uri = URI(custom_uri)
25
41
  req = Net::HTTP::Get.new(uri)
26
42
  req.basic_auth @username, @password
27
43
  response = Net::HTTP.start(uri.hostname, uri.port) do |http|
@@ -35,7 +51,6 @@ module FormhubRuby
35
51
  end
36
52
  end
37
53
 
38
- # private
39
54
 
40
55
  def api_uri
41
56
  "http://formhub.org/#{@username}/forms/#{@formname}/api" + api_parameters.to_s
@@ -54,7 +69,7 @@ module FormhubRuby
54
69
  end
55
70
 
56
71
  def api_parameters_array
57
- [api_query, start, limit]
72
+ [api_query, start, limit, sort_query, fields_query]
58
73
  end
59
74
 
60
75
  def api_parameters_joined
@@ -77,6 +92,29 @@ module FormhubRuby
77
92
  hash.merge(hash){|k,hashv|hashv.to_s}
78
93
  end
79
94
 
95
+ # Note that integers seem to be stored as strings in Formhub database,
96
+ # and will be sorted as such
97
+
98
+ def sort_query
99
+ if @sort
100
+ validates_sort
101
+ "sort=#{CGI.escape @sort.to_json}"
102
+ end
103
+ end
104
+
105
+ def fields_query
106
+ if @fields
107
+ "fields=#{CGI.escape @fields.to_json}"
108
+ end
109
+ end
110
+
111
+ def validates_sort
112
+ unless @sort.values.all? { |value| value == 1 || value == -1}
113
+ raise 'The sort option is hash taking +1 (ascending) or -1 (descending) value '
114
+ end
115
+
116
+ end
117
+
80
118
  # end
81
119
  end
82
120
  end
@@ -1,3 +1,3 @@
1
1
  module FormhubRuby
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.6.1'
3
3
  end
@@ -2,12 +2,14 @@ require 'formhub_ruby'
2
2
  require 'spec_helper'
3
3
  require 'yaml'
4
4
 
5
+ # Currently 4 records on my account for the survey form
6
+
5
7
  describe FormhubRuby::ApiConnector do
6
8
  before :each do
7
9
  credentials = YAML.load_file('spec/fixtures/test_credentials.yml')
8
10
  FormhubRuby.configure do |config|
9
- config.username = credentials['username']
10
- config.password = credentials['password']
11
+ config.username = credentials['username'] || 'fake'
12
+ config.password = credentials['password'] || 'fake'
11
13
  end
12
14
  end
13
15
 
@@ -19,8 +21,8 @@ describe FormhubRuby::ApiConnector do
19
21
  VCR.use_cassette 'successful_connection' do
20
22
  connection = FormhubRuby::ApiConnector.new(formname: 'survey')
21
23
  connection.fetch
22
- connection.data.should be_a_kind_of(Array)
23
- connection.data[0].should be_a_kind_of(Object)
24
+ expect(connection.data).to be_a_kind_of(Array)
25
+ expect(connection.data[0]).to be_a_kind_of(Object)
24
26
  end
25
27
  end
26
28
 
@@ -38,36 +40,86 @@ describe FormhubRuby::ApiConnector do
38
40
 
39
41
  it "does not add any extraneaous query" do
40
42
  connection = FormhubRuby::ApiConnector.new(formname: 'survey')
41
- connection.api_uri.should == "http://formhub.org/#{username}/forms/survey/api"
43
+ expect(connection.api_uri).to eq("http://formhub.org/#{username}/forms/survey/api")
42
44
  end
43
45
 
44
46
  it "does form a simple query" do
45
47
  connection.query = {age: 12}
46
- connection.api_uri.should == "http://formhub.org/#{username}/forms/survey/api?query=%7B%22age%22%3A%2212%22%7D"
48
+
49
+ expect(connection.api_uri).to eq("http://formhub.org/#{username}/forms/survey/api?query=%7B%22age%22%3A%2212%22%7D")
47
50
  VCR.use_cassette 'age_query' do
48
51
  connection.fetch
49
- connection.data.length.should == 1
52
+ expect(connection.data.length).to eq(1)
50
53
  end
51
54
 
52
55
  end
53
56
 
54
57
  it "formulates a query with a start" do
55
58
  connection.start = 1
56
- connection.api_uri.should == "http://formhub.org/#{username}/forms/survey/api?start=1"
59
+ expect(connection.api_uri).to eq("http://formhub.org/#{username}/forms/survey/api?start=1")
57
60
  VCR.use_cassette 'query_start' do
58
61
  connection.fetch
59
- connection.data.length.should == 1
62
+ expect(connection.data.length).to eq(3)
60
63
  end
61
64
  end
62
65
 
63
66
  it "formulates a query with a limit" do
64
67
  connection.limit = 1
65
- connection.api_uri.should == "http://formhub.org/#{username}/forms/survey/api?limit=1"
68
+ expect(connection.api_uri).to eq("http://formhub.org/#{username}/forms/survey/api?limit=1")
66
69
  VCR.use_cassette 'query_limit' do
67
70
  connection.fetch
68
- connection.data.length.should == 1
71
+ expect(connection.data.length).to eq(1)
69
72
  end
70
73
  end
74
+
75
+ it "combines a query with a start and a limit" do
76
+ connection.start = 1
77
+ connection.limit = 1
78
+ expect(connection.api_uri).to eq("http://formhub.org/#{username}/forms/survey/api?start=1&limit=1")
79
+ VCR.use_cassette 'query_start_and_limit' do
80
+ connection.fetch
81
+ expect(connection.data.length).to eq(1)
82
+ end
83
+ end
84
+
85
+
86
+ it "just returns the count of rows for the query" do
87
+ connection.start = 1
88
+ connection.limit = 1
89
+ VCR.use_cassette "just_get_the_count" do
90
+ response = connection.get_count
91
+ expect(response).to eq(4)
92
+ end
93
+
94
+ end
95
+
96
+
97
+ it "sorts the data according to the supplied params" do
98
+
99
+ connection.sort = {name: -1}
100
+
101
+ VCR.use_cassette "sorts_properly" do
102
+ connection.fetch
103
+ expect(connection.data.map{|row| row["name"]} ).to eq(['napoléon', 'loic', 'georges', 'Robert'])
104
+ end
105
+
106
+ end
107
+
108
+ it "only retrieve the selected fields" do
109
+
110
+ connection.fields = [:name, :age]
111
+ puts connection.api_uri
112
+
113
+ VCR.use_cassette "retrieve_selected_fields_only" do
114
+ connection.fetch
115
+ expect(connection.data.first['pizza_fan']).to be_nil
116
+ expect(connection.data.first['name']).not_to be_nil
117
+ end
118
+
119
+
120
+
121
+ end
122
+
71
123
 
72
124
  end
73
125
 
@@ -21,7 +21,7 @@ http_interactions:
21
21
  message: OK
22
22
  headers:
23
23
  Date:
24
- - Fri, 23 May 2014 11:41:14 GMT
24
+ - Mon, 02 Jun 2014 11:09:53 GMT
25
25
  Content-Type:
26
26
  - application/json
27
27
  Transfer-Encoding:
@@ -56,5 +56,5 @@ http_interactions:
56
56
  \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
57
57
  \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
58
58
  http_version:
59
- recorded_at: Fri, 23 May 2014 11:41:39 GMT
59
+ recorded_at: Mon, 02 Jun 2014 11:09:53 GMT
60
60
  recorded_with: VCR 2.9.0
@@ -0,0 +1,52 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<USERNAME>:<PASSWORD>@formhub.org/<USERNAME>/forms/survey/api?count=1&limit=1&start=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - formhub.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Thu, 29 May 2014 15:28:33 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - gunicorn/0.15.0
33
+ Access-Control-Allow-Headers:
34
+ - Accept, Origin, X-Requested-With, Authorization
35
+ Content-Language:
36
+ - en-us
37
+ Vary:
38
+ - Accept-Language, Cookie
39
+ Etag:
40
+ - "\"14a3ce9385ab94d0a05702445e9cb804\""
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Access-Control-Allow-Methods:
44
+ - GET
45
+ Strict-Transport-Security:
46
+ - max-age=31536000
47
+ body:
48
+ encoding: UTF-8
49
+ string: "[{\"count\": 4}]"
50
+ http_version:
51
+ recorded_at: Thu, 29 May 2014 15:28:43 GMT
52
+ recorded_with: VCR 2.9.0
@@ -21,7 +21,7 @@ http_interactions:
21
21
  message: OK
22
22
  headers:
23
23
  Date:
24
- - Fri, 23 May 2014 11:46:21 GMT
24
+ - Thu, 29 May 2014 15:28:31 GMT
25
25
  Content-Type:
26
26
  - application/json
27
27
  Transfer-Encoding:
@@ -37,7 +37,7 @@ http_interactions:
37
37
  Vary:
38
38
  - Accept-Language, Cookie
39
39
  Etag:
40
- - "\"a8b3103fef34948c7ead4c8335e29543\""
40
+ - "\"0d06d7f4e0deb690eab5d9ed82e6a990\""
41
41
  Access-Control-Allow-Origin:
42
42
  - "*"
43
43
  Access-Control-Allow-Methods:
@@ -46,15 +46,15 @@ http_interactions:
46
46
  - max-age=31536000
47
47
  body:
48
48
  encoding: UTF-8
49
- string: "[{\"meta/instanceID\": \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
50
- \"name\": \"georges\", \"_submission_time\": \"2014-05-15T16:29:00\", \"age\":
51
- \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"_bamboo_dataset_id\":
52
- \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\": [null, null],
53
- \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\": \"survey\",
54
- \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\": \"no phonenumber
55
- property in enketo\", \"_status\": \"submitted_via_web\", \"_id\": 3318651,
56
- \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
57
- \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
49
+ string: "[{\"meta/instanceID\": \"uuid:269e2328-5997-43c1-aeb1-6edec8f914af\",
50
+ \"age\": \"15\", \"name\": \"napol\\u00e9on\", \"_submission_time\": \"2014-05-29T13:55:58\",
51
+ \"start_time\": \"2014-05-29T14:55:42.000+01:00\", \"_uuid\": \"269e2328-5997-43c1-aeb1-6edec8f914af\",
52
+ \"_bamboo_dataset_id\": \"\", \"_tags\": [], \"_attachments\": [], \"imei\":
53
+ \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"_geolocation\": [null, null], \"end_time\":
54
+ \"2014-05-29T14:56:05.000+01:00\", \"gender\": \"female\", \"_xform_id_string\":
55
+ \"survey\", \"phonenumber\": \"no phonenumber property in enketo\", \"_status\":
56
+ \"submitted_via_web\", \"_id\": 3413156, \"pizza_fan\": \"no\", \"today\":
57
+ \"2014-05-29\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
58
58
  http_version:
59
- recorded_at: Fri, 23 May 2014 11:46:46 GMT
59
+ recorded_at: Thu, 29 May 2014 15:28:41 GMT
60
60
  recorded_with: VCR 2.9.0
@@ -21,7 +21,7 @@ http_interactions:
21
21
  message: OK
22
22
  headers:
23
23
  Date:
24
- - Fri, 23 May 2014 11:47:06 GMT
24
+ - Thu, 29 May 2014 15:28:31 GMT
25
25
  Content-Type:
26
26
  - application/json
27
27
  Transfer-Encoding:
@@ -37,7 +37,7 @@ http_interactions:
37
37
  Vary:
38
38
  - Accept-Language, Cookie
39
39
  Etag:
40
- - "\"cca3b5eba43f81971965707f51c4882b\""
40
+ - "\"ce11c6a0cd553a81e77d3553380fe14d\""
41
41
  Access-Control-Allow-Origin:
42
42
  - "*"
43
43
  Access-Control-Allow-Methods:
@@ -46,15 +46,33 @@ http_interactions:
46
46
  - max-age=31536000
47
47
  body:
48
48
  encoding: UTF-8
49
- string: "[{\"meta/instanceID\": \"uuid:2aebfa29-6284-4c3a-9c3f-6eb604f89194\",
50
- \"age\": \"23\", \"name\": \"loic\", \"_submission_time\": \"2014-05-15T16:28:19\",
51
- \"start_time\": \"2014-05-15T17:27:57.000+01:00\", \"_uuid\": \"2aebfa29-6284-4c3a-9c3f-6eb604f89194\",
52
- \"_bamboo_dataset_id\": \"\", \"_tags\": [], \"_attachments\": [], \"imei\":
53
- \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"_geolocation\": [null, null], \"end_time\":
54
- \"2014-05-15T17:28:18.000+01:00\", \"gender\": \"female\", \"_xform_id_string\":
55
- \"survey\", \"phonenumber\": \"no phonenumber property in enketo\", \"_status\":
56
- \"submitted_via_web\", \"_id\": 3318647, \"pizza_fan\": \"no\", \"today\":
57
- \"2014-05-15\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
49
+ string: "[{\"meta/instanceID\": \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
50
+ \"name\": \"georges\", \"_submission_time\": \"2014-05-15T16:29:00\", \"age\":
51
+ \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"_bamboo_dataset_id\":
52
+ \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\": [null, null],
53
+ \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\": \"survey\",
54
+ \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\": \"no phonenumber
55
+ property in enketo\", \"_status\": \"submitted_via_web\", \"_id\": 3318651,
56
+ \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
57
+ \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\":
58
+ \"uuid:2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"age\": \"23\", \"name\":
59
+ \"loic\", \"_submission_time\": \"2014-05-15T16:28:19\", \"start_time\": \"2014-05-15T17:27:57.000+01:00\",
60
+ \"_uuid\": \"2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"_bamboo_dataset_id\":
61
+ \"\", \"_tags\": [], \"_attachments\": [], \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\",
62
+ \"_geolocation\": [null, null], \"end_time\": \"2014-05-15T17:28:18.000+01:00\",
63
+ \"gender\": \"female\", \"_xform_id_string\": \"survey\", \"phonenumber\":
64
+ \"no phonenumber property in enketo\", \"_status\": \"submitted_via_web\",
65
+ \"_id\": 3318647, \"pizza_fan\": \"no\", \"today\": \"2014-05-15\", \"formhub/uuid\":
66
+ \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"_bamboo_dataset_id\": \"\", \"_tags\":
67
+ [], \"pizza_type\": \"chitown\", \"phonenumber\": \"no phonenumber property
68
+ in enketo\", \"_xform_id_string\": \"survey\", \"meta/instanceID\": \"uuid:d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\",
69
+ \"pizza_fan\": \"yes\", \"favorite_toppings\": \"pepperoni sausauge\", \"_attachments\":
70
+ [], \"_status\": \"submitted_via_web\", \"today\": \"2014-05-29\", \"start_time\":
71
+ \"2014-05-29T14:53:31.000+01:00\", \"_uuid\": \"d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\",
72
+ \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\",
73
+ \"name\": \"Robert\", \"_submission_time\": \"2014-05-29T13:55:41\", \"age\":
74
+ \"100\", \"_geolocation\": [null, null], \"end_time\": \"2014-05-29T14:53:58.000+01:00\",
75
+ \"gender\": \"male\", \"_id\": 3413155}]"
58
76
  http_version:
59
- recorded_at: Fri, 23 May 2014 11:47:31 GMT
77
+ recorded_at: Thu, 29 May 2014 15:28:41 GMT
60
78
  recorded_with: VCR 2.9.0
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<USERNAME>:<PASSWORD>@formhub.org/<USERNAME>/forms/survey/api?limit=1&start=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - formhub.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Thu, 29 May 2014 15:28:32 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - gunicorn/0.15.0
33
+ Access-Control-Allow-Headers:
34
+ - Accept, Origin, X-Requested-With, Authorization
35
+ Content-Language:
36
+ - en-us
37
+ Vary:
38
+ - Accept-Language, Cookie
39
+ Etag:
40
+ - "\"a8b3103fef34948c7ead4c8335e29543\""
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Access-Control-Allow-Methods:
44
+ - GET
45
+ Strict-Transport-Security:
46
+ - max-age=31536000
47
+ body:
48
+ encoding: UTF-8
49
+ string: "[{\"meta/instanceID\": \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
50
+ \"name\": \"georges\", \"_submission_time\": \"2014-05-15T16:29:00\", \"age\":
51
+ \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"_bamboo_dataset_id\":
52
+ \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\": [null, null],
53
+ \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\": \"survey\",
54
+ \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\": \"no phonenumber
55
+ property in enketo\", \"_status\": \"submitted_via_web\", \"_id\": 3318651,
56
+ \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
57
+ \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
58
+ http_version:
59
+ recorded_at: Thu, 29 May 2014 15:28:42 GMT
60
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<USERNAME>:<PASSWORD>@formhub.org/<USERNAME>/forms/survey/api?fields=%5B%22name%22,%22age%22%5D
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - formhub.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Mon, 02 Jun 2014 11:53:49 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - gunicorn/0.15.0
33
+ Access-Control-Allow-Headers:
34
+ - Accept, Origin, X-Requested-With, Authorization
35
+ Content-Language:
36
+ - en-us
37
+ Vary:
38
+ - Accept-Language, Cookie
39
+ Etag:
40
+ - "\"28b1d13b897184580960f6691040cc94\""
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Access-Control-Allow-Methods:
44
+ - GET
45
+ Strict-Transport-Security:
46
+ - max-age=31536000
47
+ body:
48
+ encoding: UTF-8
49
+ string: "[{\"age\": \"15\", \"_id\": 3413156, \"name\": \"napol\\u00e9on\"},
50
+ {\"age\": \"12\", \"_id\": 3318651, \"name\": \"georges\"}, {\"age\": \"23\",
51
+ \"_id\": 3318647, \"name\": \"loic\"}, {\"age\": \"100\", \"_id\": 3413155,
52
+ \"name\": \"Robert\"}]"
53
+ http_version:
54
+ recorded_at: Mon, 02 Jun 2014 11:53:49 GMT
55
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,87 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<USERNAME>:<PASSWORD>@formhub.org/<USERNAME>/forms/survey/api?sort=%7B%22name%22:-1%7D
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - formhub.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Mon, 02 Jun 2014 11:37:40 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - gunicorn/0.15.0
33
+ Access-Control-Allow-Headers:
34
+ - Accept, Origin, X-Requested-With, Authorization
35
+ Content-Language:
36
+ - en-us
37
+ Vary:
38
+ - Accept-Language, Cookie
39
+ Etag:
40
+ - "\"f9b8d47fed9e7bad4df95ec530fd7134\""
41
+ Access-Control-Allow-Origin:
42
+ - "*"
43
+ Access-Control-Allow-Methods:
44
+ - GET
45
+ Strict-Transport-Security:
46
+ - max-age=31536000
47
+ body:
48
+ encoding: UTF-8
49
+ string: "[{\"meta/instanceID\": \"uuid:269e2328-5997-43c1-aeb1-6edec8f914af\",
50
+ \"age\": \"15\", \"name\": \"napol\\u00e9on\", \"_submission_time\": \"2014-05-29T13:55:58\",
51
+ \"start_time\": \"2014-05-29T14:55:42.000+01:00\", \"_uuid\": \"269e2328-5997-43c1-aeb1-6edec8f914af\",
52
+ \"_bamboo_dataset_id\": \"\", \"_tags\": [], \"_attachments\": [], \"imei\":
53
+ \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"_geolocation\": [null, null], \"end_time\":
54
+ \"2014-05-29T14:56:05.000+01:00\", \"gender\": \"female\", \"_xform_id_string\":
55
+ \"survey\", \"phonenumber\": \"no phonenumber property in enketo\", \"_status\":
56
+ \"submitted_via_web\", \"_id\": 3413156, \"pizza_fan\": \"no\", \"today\":
57
+ \"2014-05-29\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\":
58
+ \"uuid:2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"age\": \"23\", \"name\":
59
+ \"loic\", \"_submission_time\": \"2014-05-15T16:28:19\", \"start_time\": \"2014-05-15T17:27:57.000+01:00\",
60
+ \"_uuid\": \"2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"_bamboo_dataset_id\":
61
+ \"\", \"_tags\": [], \"_attachments\": [], \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\",
62
+ \"_geolocation\": [null, null], \"end_time\": \"2014-05-15T17:28:18.000+01:00\",
63
+ \"gender\": \"female\", \"_xform_id_string\": \"survey\", \"phonenumber\":
64
+ \"no phonenumber property in enketo\", \"_status\": \"submitted_via_web\",
65
+ \"_id\": 3318647, \"pizza_fan\": \"no\", \"today\": \"2014-05-15\", \"formhub/uuid\":
66
+ \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\": \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
67
+ \"name\": \"georges\", \"_submission_time\": \"2014-05-15T16:29:00\", \"age\":
68
+ \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"_bamboo_dataset_id\":
69
+ \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\": [null, null],
70
+ \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\": \"survey\",
71
+ \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\": \"no phonenumber
72
+ property in enketo\", \"_status\": \"submitted_via_web\", \"_id\": 3318651,
73
+ \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
74
+ \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"_bamboo_dataset_id\":
75
+ \"\", \"_tags\": [], \"pizza_type\": \"chitown\", \"phonenumber\": \"no phonenumber
76
+ property in enketo\", \"_xform_id_string\": \"survey\", \"meta/instanceID\":
77
+ \"uuid:d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\", \"pizza_fan\": \"yes\", \"favorite_toppings\":
78
+ \"pepperoni sausauge\", \"_attachments\": [], \"_status\": \"submitted_via_web\",
79
+ \"today\": \"2014-05-29\", \"start_time\": \"2014-05-29T14:53:31.000+01:00\",
80
+ \"_uuid\": \"d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\", \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\",
81
+ \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\", \"name\": \"Robert\",
82
+ \"_submission_time\": \"2014-05-29T13:55:41\", \"age\": \"100\", \"_geolocation\":
83
+ [null, null], \"end_time\": \"2014-05-29T14:53:58.000+01:00\", \"gender\":
84
+ \"male\", \"_id\": 3413155}]"
85
+ http_version:
86
+ recorded_at: Mon, 02 Jun 2014 11:37:39 GMT
87
+ recorded_with: VCR 2.9.0
@@ -21,7 +21,7 @@ http_interactions:
21
21
  message: OK
22
22
  headers:
23
23
  Date:
24
- - Fri, 23 May 2014 10:45:15 GMT
24
+ - Thu, 29 May 2014 15:28:29 GMT
25
25
  Content-Type:
26
26
  - application/json
27
27
  Transfer-Encoding:
@@ -37,7 +37,7 @@ http_interactions:
37
37
  Vary:
38
38
  - Accept-Language, Cookie
39
39
  Etag:
40
- - "\"29c06f8ea5b6a1ac0301ef2e10305bea\""
40
+ - "\"4baf3432bbeb6cd2b3425cf06e7158ef\""
41
41
  Access-Control-Allow-Origin:
42
42
  - "*"
43
43
  Access-Control-Allow-Methods:
@@ -46,15 +46,23 @@ http_interactions:
46
46
  - max-age=31536000
47
47
  body:
48
48
  encoding: UTF-8
49
- string: "[{\"meta/instanceID\": \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
50
- \"name\": \"georges\", \"_submission_time\": \"2014-05-15T16:29:00\", \"age\":
51
- \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"_bamboo_dataset_id\":
52
- \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\": [null, null],
53
- \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\": \"survey\",
54
- \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\": \"no phonenumber
55
- property in enketo\", \"_status\": \"submitted_via_web\", \"_id\": 3318651,
56
- \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\": \"2014-05-15\",
57
- \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\":
49
+ string: "[{\"meta/instanceID\": \"uuid:269e2328-5997-43c1-aeb1-6edec8f914af\",
50
+ \"age\": \"15\", \"name\": \"napol\\u00e9on\", \"_submission_time\": \"2014-05-29T13:55:58\",
51
+ \"start_time\": \"2014-05-29T14:55:42.000+01:00\", \"_uuid\": \"269e2328-5997-43c1-aeb1-6edec8f914af\",
52
+ \"_bamboo_dataset_id\": \"\", \"_tags\": [], \"_attachments\": [], \"imei\":
53
+ \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"_geolocation\": [null, null], \"end_time\":
54
+ \"2014-05-29T14:56:05.000+01:00\", \"gender\": \"female\", \"_xform_id_string\":
55
+ \"survey\", \"phonenumber\": \"no phonenumber property in enketo\", \"_status\":
56
+ \"submitted_via_web\", \"_id\": 3413156, \"pizza_fan\": \"no\", \"today\":
57
+ \"2014-05-29\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\":
58
+ \"uuid:be1b882a-b377-4cf0-95d3-c2acc8d04e7a\", \"name\": \"georges\", \"_submission_time\":
59
+ \"2014-05-15T16:29:00\", \"age\": \"12\", \"_uuid\": \"be1b882a-b377-4cf0-95d3-c2acc8d04e7a\",
60
+ \"_bamboo_dataset_id\": \"\", \"_tags\": [], \"_attachments\": [], \"_geolocation\":
61
+ [null, null], \"end_time\": \"2014-05-15T17:28:59.000+01:00\", \"_xform_id_string\":
62
+ \"survey\", \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"phonenumber\":
63
+ \"no phonenumber property in enketo\", \"_status\": \"submitted_via_web\",
64
+ \"_id\": 3318651, \"start_time\": \"2014-05-15T17:28:43.000+01:00\", \"today\":
65
+ \"2014-05-15\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"meta/instanceID\":
58
66
  \"uuid:2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"age\": \"23\", \"name\":
59
67
  \"loic\", \"_submission_time\": \"2014-05-15T16:28:19\", \"start_time\": \"2014-05-15T17:27:57.000+01:00\",
60
68
  \"_uuid\": \"2aebfa29-6284-4c3a-9c3f-6eb604f89194\", \"_bamboo_dataset_id\":
@@ -63,7 +71,16 @@ http_interactions:
63
71
  \"gender\": \"female\", \"_xform_id_string\": \"survey\", \"phonenumber\":
64
72
  \"no phonenumber property in enketo\", \"_status\": \"submitted_via_web\",
65
73
  \"_id\": 3318647, \"pizza_fan\": \"no\", \"today\": \"2014-05-15\", \"formhub/uuid\":
66
- \"1bfb7222748a4ee98106ea7d7a9c72cf\"}]"
74
+ \"1bfb7222748a4ee98106ea7d7a9c72cf\"}, {\"_bamboo_dataset_id\": \"\", \"_tags\":
75
+ [], \"pizza_type\": \"chitown\", \"phonenumber\": \"no phonenumber property
76
+ in enketo\", \"_xform_id_string\": \"survey\", \"meta/instanceID\": \"uuid:d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\",
77
+ \"pizza_fan\": \"yes\", \"favorite_toppings\": \"pepperoni sausauge\", \"_attachments\":
78
+ [], \"_status\": \"submitted_via_web\", \"today\": \"2014-05-29\", \"start_time\":
79
+ \"2014-05-29T14:53:31.000+01:00\", \"_uuid\": \"d85cf54e-ecf9-4b0a-b9dd-600f3dd69460\",
80
+ \"imei\": \"enketo.formhub.org:fSucCmZ5zwzNcTe1\", \"formhub/uuid\": \"1bfb7222748a4ee98106ea7d7a9c72cf\",
81
+ \"name\": \"Robert\", \"_submission_time\": \"2014-05-29T13:55:41\", \"age\":
82
+ \"100\", \"_geolocation\": [null, null], \"end_time\": \"2014-05-29T14:53:58.000+01:00\",
83
+ \"gender\": \"male\", \"_id\": 3413155}]"
67
84
  http_version:
68
- recorded_at: Fri, 23 May 2014 10:45:40 GMT
85
+ recorded_at: Thu, 29 May 2014 15:28:39 GMT
69
86
  recorded_with: VCR 2.9.0
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formhub_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loïc Seigland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-23 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -186,8 +200,12 @@ files:
186
200
  - spec/api_connectior_spec.rb
187
201
  - spec/client_spec.rb
188
202
  - spec/fixtures/vcr_cassettes/age_query.yml
203
+ - spec/fixtures/vcr_cassettes/just_get_the_count.yml
189
204
  - spec/fixtures/vcr_cassettes/query_limit.yml
190
205
  - spec/fixtures/vcr_cassettes/query_start.yml
206
+ - spec/fixtures/vcr_cassettes/query_start_and_limit.yml
207
+ - spec/fixtures/vcr_cassettes/retrieve_selected_fields_only.yml
208
+ - spec/fixtures/vcr_cassettes/sorts_properly.yml
191
209
  - spec/fixtures/vcr_cassettes/successful_connection.yml
192
210
  - spec/spec_helper.rb
193
211
  homepage: http://loicseigland.ie
@@ -218,7 +236,11 @@ test_files:
218
236
  - spec/api_connectior_spec.rb
219
237
  - spec/client_spec.rb
220
238
  - spec/fixtures/vcr_cassettes/age_query.yml
239
+ - spec/fixtures/vcr_cassettes/just_get_the_count.yml
221
240
  - spec/fixtures/vcr_cassettes/query_limit.yml
222
241
  - spec/fixtures/vcr_cassettes/query_start.yml
242
+ - spec/fixtures/vcr_cassettes/query_start_and_limit.yml
243
+ - spec/fixtures/vcr_cassettes/retrieve_selected_fields_only.yml
244
+ - spec/fixtures/vcr_cassettes/sorts_properly.yml
223
245
  - spec/fixtures/vcr_cassettes/successful_connection.yml
224
246
  - spec/spec_helper.rb