Module: Noteshred::API

Defined in:
lib/noteshred/api.rb

Class Method Summary collapse

Class Method Details

.get(rel, params = nil) ⇒ Object



10
11
12
13
# File 'lib/noteshred/api.rb', line 10

def self.get(rel,params = nil)
  response = RestClient.get(Noteshred.url(rel), {:params => params, :authorization => "Token token=#{Noteshred.api_key}"}){|response, request, result| response }
  Noteshred::API.render(response)
end

.post(rel, params = nil) ⇒ Object



15
16
17
18
# File 'lib/noteshred/api.rb', line 15

def self.post(rel,params = nil)
  response = RestClient.post(Noteshred.url(rel), params, {:authorization => "Token token=#{Noteshred.api_key}", :content_type => :json, :accept => :json}){|response, request, result| response }
  Noteshred::API.render(response)
end

.render(response) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/noteshred/api.rb', line 20

def self.render(response)
  JSON.parse(response)
rescue JSON::ParserError => err
  {:error => err.message}
rescue StandardError
  {:error => 'Error parsing response'}
end