Class: REDCap

Inherits:
Object
  • Object
show all
Defined in:
lib/red_cap.rb,
lib/red_cap/form.rb,
lib/red_cap/cache.rb,
lib/red_cap/client.rb,
lib/red_cap/version.rb,
lib/red_cap/form/fields.rb,
lib/red_cap/instrument_table.rb

Defined Under Namespace

Classes: Cache, Client, Form, InstrumentTable

Constant Summary collapse

VERSION =
"0.14.0"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: REDCap.url, token: REDCap.token, per_page: REDCap.per_page) ⇒ REDCap

Returns a new instance of REDCap.



20
21
22
23
24
# File 'lib/red_cap.rb', line 20

def initialize url: REDCap.url, token: REDCap.token, per_page: REDCap.per_page
  @url = url
  @token = token
  @per_page = per_page
end

Class Attribute Details

.cacheObject

Returns the value of attribute cache.



13
14
15
# File 'lib/red_cap.rb', line 13

def cache
  @cache
end

.per_pageObject

Returns the value of attribute per_page.



13
14
15
# File 'lib/red_cap.rb', line 13

def per_page
  @per_page
end

.tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/red_cap.rb', line 13

def token
  @token
end

.urlObject

Returns the value of attribute url.



13
14
15
# File 'lib/red_cap.rb', line 13

def url
  @url
end

Instance Attribute Details

#per_pageObject

Returns the value of attribute per_page.



26
27
28
# File 'lib/red_cap.rb', line 26

def per_page
  @per_page
end

#tokenObject

Returns the value of attribute token.



26
27
28
# File 'lib/red_cap.rb', line 26

def token
  @token
end

#urlObject

Returns the value of attribute url.



26
27
28
# File 'lib/red_cap.rb', line 26

def url
  @url
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (REDCap)

    the object that the method was called on



9
10
11
# File 'lib/red_cap.rb', line 9

def configure
  yield self
end

Instance Method Details

#all(&block) ⇒ Object



36
37
38
# File 'lib/red_cap.rb', line 36

def all &block
  client.records &block
end

#clientObject



56
57
58
# File 'lib/red_cap.rb', line 56

def client
  @client ||= Client.new(url: url, token: token, per_page: per_page)
end

#delete(study_id) ⇒ Object



52
53
54
# File 'lib/red_cap.rb', line 52

def delete study_id
  client.delete_records [study_id]
end

#find(study_id) ⇒ Object



32
33
34
# File 'lib/red_cap.rb', line 32

def find study_id
  client.find_record study_id
end

#formObject



28
29
30
# File 'lib/red_cap.rb', line 28

def form
  @form ||= Form.new(client.)
end

#update(study_id, attributes) ⇒ Object



47
48
49
50
# File 'lib/red_cap.rb', line 47

def update study_id, attributes
  record = attributes.merge(study_id: study_id).stringify_keys
  client.save_records [record]
end

#where(conditions, &block) ⇒ Object



40
41
42
43
44
45
# File 'lib/red_cap.rb', line 40

def where conditions, &block
  filters = conditions.reduce([]) do |filters, (field, value)|
    filters << "[#{field}]=#{value}"
  end
  client.records(filters.join(" AND "), &block)
end