RedcapAPI 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTY3OWQ3Y2JiNGVkNzJkZDllZjkxNzA3YThmZGRkNTE3NDk2ODVmOA==
5
+ data.tar.gz: !binary |-
6
+ YTc1ZDQyOTYwZTAyY2UyZTYxYmU2YzJiNzdmZjJlZGFjNjIxNzhmNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTI0ZmNmMTlkOWVkNTQ2NmQyZDdiNjMyMzY1ZTA0NjE3N2M4NTFkZjdjYzI2
10
+ ZDRlYTJhMmM4ODk4YzYxM2MyYzRhYjNjYThhMzJmYjI5OTc0MjFmMGNlMTY3
11
+ NDMwZTgyZThiZjhhYjA1YTMxYWZkNGY2NzY4ODlhYzBlODJhOTk=
12
+ data.tar.gz: !binary |-
13
+ NWU4NTNjNGNlMWI2MDQxNDI3ODY3MmRlNWE1MGI5NjU0ZWJhMGZjNTU3NTcw
14
+ ODYxZTBlNDA0Mjc5NjY4ZDJiZmM0ZmRjNTA1NjU1NWRkYmFlMDZlYjQ5OGI0
15
+ ZDcyNjNlOGQ5YjQ4ZDRkZDAwOGQ2MzUxZDRhMmQyMTAzZWI4ZWE=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in RedcapAPI.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 eugyev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Usage
2
+
3
+ This is an api to utilize REDCAP api with ruby. This Gem requires mechanize as a dependency.
4
+ it is based on instructions here http://sburns.org/2013/07/22/intro-to-redcap-api.html
5
+
6
+ To start:
7
+
8
+ r = RedcapAPI.new(token, url) # your institution has it's own url, and each project has it's own token
9
+
10
+ r.get(optional record_id) # returns all records in JSON format or a specific record if specified
11
+
12
+ ## Contributing
13
+
14
+ 1. Fork it ( https://github.com/[my-github-username]/RedcapAPI/fork )
15
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
16
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
17
+ 4. Push to the branch (`git push origin my-new-feature`)
18
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/RedcapAPI.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'RedcapAPI/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "RedcapAPI"
8
+ spec.version = RedcapAPI::VERSION
9
+ spec.authors = ["eugyev"]
10
+ spec.email = ["eugyev@gmail.com"]
11
+ spec.summary = %q{This is an api to utilize REDCAP api with ruby. This Gem requires mechanize as a dependency.
12
+ it is based on instructions here http://sburns.org/2013/07/22/intro-to-redcap-api.html
13
+ }
14
+ spec.description = %q{To start:
15
+
16
+ r = RedcapAPI.new(token, url) # your institution has it's own url, and each project has it's own token
17
+
18
+ r.get(optional record_id) # returns all records in JSON format or a specific record if specified
19
+ }
20
+ spec.homepage = ""
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0")
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.6"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "mechanize"
31
+ end
@@ -0,0 +1,3 @@
1
+ module RedcapAPI
2
+ VERSION = "0.0.1"
3
+ end
data/lib/RedcapAPI.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "RedcapAPI/version"
2
+
3
+ class RedcapAPI
4
+ def initialize(token, url)
5
+ @url = url
6
+ @token = token
7
+ end
8
+
9
+ def get(record_id = nil)
10
+ payload = {:token=>@token, :format=>"json", :content=>"record", :type => 'flat'}
11
+ data = JSON.parse Mechanize.new.post(@url, payload).body
12
+ if record_id
13
+ data = data.select{|x| x['record_id'] == record_id.to_s}
14
+ end
15
+ data
16
+ end
17
+
18
+ def get_fields
19
+ payload = {:token=>@token, :format=>"json", :content=>"metadata"}
20
+ response = JSON.parse Mechanize.new.post(@url, payload).body
21
+ if response
22
+ response.collect {|r| r['field_name'] if r }
23
+ end
24
+ end
25
+
26
+ def post(data)
27
+ data = filter_data(data)
28
+ data_string = data.to_json
29
+ payload = {:token => @token, :format=> 'json', :content=>'record', :type => 'flat', :data => data_string}
30
+ Mechanize.new.post(@url, payload).body
31
+ end
32
+
33
+ def filter_data(data)
34
+ data = [data] if data.class == Hash
35
+
36
+ data = data.collect do |entry|
37
+ entry.each do |k, v|
38
+ if v.class == Date
39
+ entry[k] = v.strftime('%F')
40
+ end
41
+ end
42
+
43
+ if !(entry.keys.include? 'record_id' or entry.keys.include? :record_id) # new entry and no id listed
44
+ entry['record_id'] = next_open_record_id
45
+ end
46
+ entry
47
+ end
48
+
49
+ end
50
+
51
+ def next_open_record_id
52
+ old_entries = self.get
53
+ if old_entries.empty?
54
+ '1'
55
+ else
56
+ max_entry = old_entries.max_by{|e| e['record_id'].to_i}['record_id']
57
+ (max_entry.to_i + 1).to_s
58
+ end
59
+ end
60
+
61
+
62
+ end
63
+
64
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RedcapAPI
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - eugyev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ! "To start:\n\n r = RedcapAPI.new(token, url) # your institution has
56
+ it's own url, and each project has it's own token\n\n r.get(optional record_id)
57
+ # returns all records in JSON format or a specific record if specified\n "
58
+ email:
59
+ - eugyev@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - RedcapAPI.gemspec
70
+ - lib/RedcapAPI.rb
71
+ - lib/RedcapAPI/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: This is an api to utilize REDCAP api with ruby. This Gem requires mechanize
96
+ as a dependency. it is based on instructions here http://sburns.org/2013/07/22/intro-to-redcap-api.html
97
+ test_files: []