Module: MatrixAPI

Defined in:
lib/matrix_dbus/api.rb

Instance Method Summary collapse

Instance Method Details

#get(url) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/matrix_dbus/api.rb', line 3

def get(url)
  uri = @host + '/_matrix/client/r0' + url
  puts 'GET URL:', uri if $VERBOSE
  JSON.parse RestClient.get(uri).body
rescue RestClient::Exceptions::OpenTimeout
  retry
rescue RestClient::BadGateway
  retry
end

#post(url, body) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/matrix_dbus/api.rb', line 13

def post(url, body)
  uri = @host + '/_matrix/client/r0' + url
  puts 'POST URL:', uri if $VERBOSE
  JSON.parse RestClient.post(
    uri,
    body,
    content_type: :json,
    accept: :json
  ).body
rescue RestClient::Exceptions::OpenTimeout
  retry
rescue RestClient::BadGateway
  retry
end

#put(url, body) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/matrix_dbus/api.rb', line 28

def put(url, body)
  uri = @host + '/_matrix/client/r0' + url
  puts 'PUT URL:', uri if $VERBOSE
  JSON.parse RestClient.put(
    uri,
    body.to_json,
    content_type: :json,
    accept: :json
  ).body
rescue RestClient::Exceptions::OpenTimeout
  retry
rescue RestClient::BadGateway
  retry
end

#upload_file(file, token) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/matrix_dbus/api.rb', line 43

def upload_file(file, token)
  uri = @host + '/_matrix/media/r0/upload?access_token=' + token
  puts 'POST URL:', uri if $VERBOSE
  JSON.parse(RestClient.post(uri, file).body)['content_uri']
rescue RestClient::Exceptions::OpenTimeout
  retry
rescue RestClient::BadGateway
  retry
end