Class: REDCap::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/red_cap/client.rb

Defined Under Namespace

Classes: File

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



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

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

Instance Method Details

#file(record_id, file_id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/red_cap/client.rb', line 19

def file record_id, file_id
  response = base_request({
    content: "file",
    action: "export",
    record: record_id,
    field: file_id,
  })
  _, type, filename = *response.headers["content-type"].match(/\A(.+); name=\"(.+)\"\z/)
  File.new(response.body, type, filename)
end

#metadataObject



15
16
17
# File 'lib/red_cap/client.rb', line 15

def 
  json_api_request(content: "metadata")
end

#recordsObject



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

def records
  json_api_request(content: "record")
end