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

Defined Under Namespace

Classes: Cache, Client, Form

Constant Summary collapse

VERSION =
"0.12.1"

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.


18
19
20
21
22
# File 'lib/red_cap.rb', line 18

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.


11
12
13
# File 'lib/red_cap.rb', line 11

def cache
  @cache
end

.per_pageObject

Returns the value of attribute per_page.


11
12
13
# File 'lib/red_cap.rb', line 11

def per_page
  @per_page
end

.tokenObject

Returns the value of attribute token.


11
12
13
# File 'lib/red_cap.rb', line 11

def token
  @token
end

.urlObject

Returns the value of attribute url.


11
12
13
# File 'lib/red_cap.rb', line 11

def url
  @url
end

Instance Attribute Details

#per_pageObject

Returns the value of attribute per_page.


24
25
26
# File 'lib/red_cap.rb', line 24

def per_page
  @per_page
end

#tokenObject

Returns the value of attribute token.


24
25
26
# File 'lib/red_cap.rb', line 24

def token
  @token
end

#urlObject

Returns the value of attribute url.


24
25
26
# File 'lib/red_cap.rb', line 24

def url
  @url
end

Class Method Details

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

Yields:

  • (_self)

Yield Parameters:

  • _self (REDCap)

    the object that the method was called on


7
8
9
# File 'lib/red_cap.rb', line 7

def configure
  yield self
end

Instance Method Details

#all(&block) ⇒ Object


34
35
36
# File 'lib/red_cap.rb', line 34

def all &block
  client.records &block
end

#clientObject


54
55
56
# File 'lib/red_cap.rb', line 54

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

#delete(study_id) ⇒ Object


50
51
52
# File 'lib/red_cap.rb', line 50

def delete study_id
  client.delete_records [study_id]
end

#find(study_id) ⇒ Object


30
31
32
# File 'lib/red_cap.rb', line 30

def find study_id
  client.find_record study_id
end

#formObject


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

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

#update(study_id, attributes) ⇒ Object


45
46
47
48
# File 'lib/red_cap.rb', line 45

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

#where(conditions, &block) ⇒ Object


38
39
40
41
42
43
# File 'lib/red_cap.rb', line 38

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