class Schatter::Resource

Public Class Methods

new(params) click to toggle source
# File lib/schatter/resource.rb, line 5
def initialize params
  @url = params[:url]
  @resource = params[:resource]
  @url = links[:self] if @resource
end

Public Instance Methods

delete(url, params={}) click to toggle source
# File lib/schatter/resource.rb, line 52
def delete url, params={}
  params[:auth_token] = ENV['SCHATTER_AUTH_TOKEN']
  full_url = "#{url}?#{params.map{ |k,v| "#{k}=#{CGI.escape v.to_s}" }.join('&')}"
  puts "DELETE #{full_url}" if ENV['DEBUG']
  response = HTTParty.delete full_url,
    headers: {'Accept' => 'application/json'}
  puts response if ENV['DEBUG']
  response
end
destroy() click to toggle source
# File lib/schatter/resource.rb, line 11
def destroy
  delete @url
end
formatted_timestamp() click to toggle source
# File lib/schatter/resource.rb, line 38
def formatted_timestamp
  timestamp.strftime "%d/%m/%Y %H:%M:%S"
end
get(url, params={}) click to toggle source
# File lib/schatter/resource.rb, line 42
def get url, params={}
  params[:auth_token] = ENV['SCHATTER_AUTH_TOKEN']
  full_url = "#{url}?#{params.map{ |k,v| "#{k}=#{CGI.escape v.to_s}" }.join('&')}"
  puts "GET #{full_url}" if ENV['DEBUG']
  response = HTTParty.get full_url,
    headers: {'Accept' => 'application/json'}
  puts response if ENV['DEBUG']
  response
end
post(url, body) click to toggle source
# File lib/schatter/resource.rb, line 62
def post url, body
  body[:auth_token] = ENV['SCHATTER_AUTH_TOKEN']
  puts "POST #{url} #{body.to_json}" if ENV['DEBUG']
  response = HTTParty.post url,
    headers: {'Accept' => 'application/json', 'Content-Type' => 'application/json'},
    body: body.to_json
  puts response if ENV['DEBUG']
  response
end
resource() click to toggle source
# File lib/schatter/resource.rb, line 15
def resource
  return @resource if @resource
  @resource = get @url
end
timestamp() click to toggle source
# File lib/schatter/resource.rb, line 34
def timestamp
  Time.at resource['timestamp']
end
uuid() click to toggle source
# File lib/schatter/resource.rb, line 30
def uuid
  resource['uuid']
end