RedcapAPI 0.0.4 → 0.0.5a

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTc3NGJhYzZmMTJhNzAyMTUyNTZiZmRhMjk5ZjcxOWRlMjU3OTE2OA==
4
+ MDMyNzg4ZWJjZWUyZThkMzExN2Q5ODQ2NzQyZDE2YzFiZTQ1OGI0MA==
5
5
  data.tar.gz: !binary |-
6
- MTg2MmU2MDAyNmQ0ZWQwMmJiOTViYWQ2NjEyNjcyMGU3ZmQzNzBjZg==
6
+ ZWUxNGMyM2ZkZGEzZDMxMmM0YTU3ZDQ5ZmJlYmRhZTI3NTFhNjk3MA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTAxMWRlNmFlMzczMTAwOWVhNzU1YWQ5ODFkZWY3OTczYmI0M2Y3YmI1Nzc3
10
- NzZjMTNiNjkwNjZlNTE1OTU2MzkwZjYyYzNkNTFiM2Y5YWJmY2ZkYzBlYzk1
11
- MjJhMzkwOTRmNDdhMzFlYzk1ODQ3OWNmNWMzMDhmYzNiYzcyM2Y=
9
+ MDJkZjkzYmY2OTNiN2RhYmFlZWVkYjI2N2Y5YTE1YzY5MTFmODQ1Y2JkOGJi
10
+ ZjQ0Y2I3NDQ0NmRkNjlkYmY1OTViNjE5MWU3ZTE0NzhjNWNlYTQyMWQ4ZGQ3
11
+ Njc4NWMxZDAwOWVlMTIxYWQ5ZGVhMjA0YjRjYmJkZjhjODM5OGI=
12
12
  data.tar.gz: !binary |-
13
- ZjA4OWQzYWNiZjliMDUyNzQ2YTI0NjRhMTM2ZDAxOTZmYzllMGI1NmQ4YjEw
14
- ODFkYmNlOTMyZTE1OGIzNmE0M2M0NTVjNDVlNDUwZWYwM2RmMjY4MzhmNzgx
15
- ZmI2M2U0MjdlYmZjNTdjMjA0ODQ2Zjk2NGEyNjU2NDY0MzQ0YTA=
13
+ YzJjOGRmNDRkZGVlMTJiZjRiZjQ1MmRjMGNkOWEzYjg5Yjk1ZmY4ODhhYjYx
14
+ YmFiZTQ2MzliZTMyZDVkMWVlMGYyNzVjY2YzMDZmYzBhNTI0NDBjOWRmZjc0
15
+ ODc5OGY5YWM0MDUxMWZmOWJmODg2YjYwZjQ3NzJiNTEwOGVhZGI=
data/README.md CHANGED
@@ -3,12 +3,26 @@
3
3
  This is an api to utilize REDCAP api with ruby. This Gem requires mechanize as a dependency.
4
4
  it is based on instructions here http://sburns.org/2013/07/22/intro-to-redcap-api.html
5
5
 
6
+ This gem is still under active development. Please contact me directly with any questions or suggestions.
7
+
6
8
  To start:
7
9
 
8
10
  r = RedcapAPI.new(token, url) # your institution has it's own url, and each project has it's own token
9
11
 
10
12
  r.get(optional record_id) # returns all records in JSON format or a specific record if specified
11
13
 
14
+ r.get_fields # returns all fields for that instrument
15
+
16
+ r.post(data) # this will either update an old record or create a new one. the data should be in form of array of hashes or as a hash (for one item). dates are accepted in Date class or in strftime('%F') format.
17
+ for example
18
+ data = {name: 'this is a test', field_2: Date.today}
19
+ r.post(data) # creates a new object using the fields above. field names must match those in the existing project
20
+ "{\"count\": 1}" --> indicates the object posted.
21
+
22
+ to update an existing record:
23
+ data = {record_id: 3, name: 'this is a test to update', field_2: Date.today}
24
+ r.post(data) # this will update the record with record_id 3. if record_id 3 does not exist it will create an entry with that record id
25
+
12
26
  ## Contributing
13
27
 
14
28
  1. Fork it ( https://github.com/[my-github-username]/RedcapAPI/fork )
@@ -23,6 +23,15 @@ Gem::Specification.new do |spec|
23
23
  r.get_fields # returns all fields for that instrument
24
24
 
25
25
  r.post(data) # this will either update an old record or create a new one. the data should be in form of array of hashes or as a hash (for one item). dates are accepted in Date class or in strftime('%F') format.
26
+ for example
27
+ data = {name: 'this is a test', field_2: Date.today}
28
+ r.post(data) # creates a new object using the fields above. field names must match those in the existing project
29
+ "{\"count\": 1}" --> indicates the object posted.
30
+
31
+ to update an existing record:
32
+ data = {record_id: 3, name: 'this is a test to update', field_2: Date.today}
33
+ r.post(data) # this will update the record with record_id 3. if record_id 3 does not exist it will create an entry with that record id
34
+
26
35
  }
27
36
  spec.homepage = ""
28
37
  spec.license = "MIT"
@@ -1,59 +1,59 @@
1
1
  require "RedcapAPI/version"
2
- class RedcapAPI
3
- def initialize(token, url)
4
- @url = url
5
- @token = token
6
- end
2
+ class RedcapAPI
3
+ def initialize(token, url)
4
+ @url = url
5
+ @token = token
6
+ end
7
7
 
8
- def get(record_id = nil)
9
- payload = {:token=>@token, :format=>"json", :content=>"record", :type => 'flat'}
10
- data = JSON.parse Mechanize.new.post(@url, payload).body
11
- if record_id
12
- data = data.select{|x| x['record_id'] == record_id.to_s}
8
+ def get(record_id = nil)
9
+ payload = {:token=>@token, :format=>"json", :content=>"record", :type => 'flat'}
10
+ data = JSON.parse Mechanize.new.post(@url, payload).body
11
+ if record_id
12
+ data = data.select{|x| x['record_id'] == record_id.to_s}
13
+ end
14
+ data
13
15
  end
14
- data
15
- end
16
16
 
17
- def get_fields
18
- payload = {:token=>@token, :format=>"json", :content=>"metadata"}
19
- response = JSON.parse Mechanize.new.post(@url, payload).body
20
- if response
21
- response.collect {|r| r['field_name'] if r }
17
+ def get_fields
18
+ payload = {:token=>@token, :format=>"json", :content=>"metadata"}
19
+ response = JSON.parse Mechanize.new.post(@url, payload).body
20
+ if response
21
+ response.collect {|r| r['field_name'] if r }
22
+ end
22
23
  end
23
- end
24
24
 
25
- def post(data)
26
- data = filter_data(data)
27
- data_string = data.to_json
28
- payload = {:token => @token, :format=> 'json', :content=>'record', :type => 'flat', :data => data_string}
29
- Mechanize.new.post(@url, payload).body
30
- end
25
+ def post(data)
26
+ data = filter_data(data)
27
+ data_string = data.to_json
28
+ payload = {:token => @token, :format=> 'json', :content=>'record', :type => 'flat', :data => data_string}
29
+ Mechanize.new.post(@url, payload).body
30
+ end
31
31
 
32
- def filter_data(data)
33
- data = [data] if data.class == Hash
32
+ def filter_data(data)
33
+ data = [data] if data.class == Hash
34
34
 
35
- data = data.collect do |entry|
36
- entry.each do |k, v|
37
- if v.class == Date
38
- entry[k] = v.strftime('%F')
35
+ data = data.collect do |entry|
36
+ entry.each do |k, v|
37
+ if v.class == Date
38
+ entry[k] = v.strftime('%F')
39
+ end
39
40
  end
40
- end
41
41
 
42
- if !(entry.keys.include? 'record_id' or entry.keys.include? :record_id) # new entry and no id listed
43
- entry['record_id'] = next_open_record_id
42
+ if !(entry.keys.include? 'record_id' or entry.keys.include? :record_id) # new entry and no id listed
43
+ entry['record_id'] = next_open_record_id
44
+ end
45
+ entry
44
46
  end
45
- entry
46
- end
47
47
 
48
- end
48
+ end
49
49
 
50
- def next_open_record_id
51
- old_entries = self.get
52
- if old_entries.empty?
53
- '1'
54
- else
55
- max_entry = old_entries.max_by{|e| e['record_id'].to_i}['record_id']
56
- (max_entry.to_i + 1).to_s
50
+ def next_open_record_id
51
+ old_entries = self.get
52
+ if old_entries.empty?
53
+ '1'
54
+ else
55
+ max_entry = old_entries.max_by{|e| e['record_id'].to_i}['record_id']
56
+ (max_entry.to_i + 1).to_s
57
+ end
57
58
  end
58
59
  end
59
-
@@ -1,3 +1,3 @@
1
1
  class RedcapAPI
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5a"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RedcapAPI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5a
5
5
  platform: ruby
6
6
  authors:
7
7
  - eugyev
@@ -59,7 +59,13 @@ description: ! "\n This gem is still under active development. Please contact
59
59
  if specified\n \n r.get_fields # returns all fields for that instrument\n \n
60
60
  \ r.post(data) # this will either update an old record or create a new one. the
61
61
  data should be in form of array of hashes or as a hash (for one item). dates are
62
- accepted in Date class or in strftime('%F') format. \n "
62
+ accepted in Date class or in strftime('%F') format. \n for example\n data =
63
+ {name: 'this is a test', field_2: Date.today}\n r.post(data) # creates a new
64
+ object using the fields above. field names must match those in the existing project\n
65
+ \ \"{\\\"count\\\": 1}\" --> indicates the object posted. \n \n to update an
66
+ existing record:\n data = {record_id: 3, name: 'this is a test to update', field_2:
67
+ Date.today}\n r.post(data) # this will update the record with record_id 3. if record_id
68
+ 3 does not exist it will create an entry with that record id\n \n "
63
69
  email:
64
70
  - eugyev@gmail.com
65
71
  executables: []
@@ -89,9 +95,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
95
  version: '0'
90
96
  required_rubygems_version: !ruby/object:Gem::Requirement
91
97
  requirements:
92
- - - ! '>='
98
+ - - ! '>'
93
99
  - !ruby/object:Gem::Version
94
- version: '0'
100
+ version: 1.3.1
95
101
  requirements: []
96
102
  rubyforge_project:
97
103
  rubygems_version: 2.2.2