class Conf::Api::Client

Constants

VERSION

Attributes

conn[RW]
pass[RW]
url[RW]
user[RW]

Public Class Methods

new(user, pass, url) click to toggle source
# File lib/conf/api/client.rb, line 10
def initialize(user, pass, url)
  self.user = user
  self.pass = pass
  self.url  = url
  self.conn = Faraday.new(url: url) do |faraday|
    faraday.request :url_encoded # form-encode POST params
    # faraday.response :logger                  # log requests to STDOUT
    faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
    faraday.basic_auth(self.user, self.pass)
  end
end

Public Instance Methods

create(params) click to toggle source
# File lib/conf/api/client.rb, line 32
def create(params)
  response = conn.post do |req|
    req.url '/rest/api/content'
    req.headers['Content-Type'] = 'application/json'
    req.body                    = params.to_json
  end
  JSON.parse(response.body)
end
get(params) click to toggle source
# File lib/conf/api/client.rb, line 22
def get(params)
  response = conn.get('/rest/api/content', params)
  JSON.parse(response.body)['results']
end
get_by_id(id) click to toggle source
# File lib/conf/api/client.rb, line 27
def get_by_id(id)
  response = conn.get('/rest/api/content/' + id)
  JSON.parse(response.body)
end
update(id, params) click to toggle source
# File lib/conf/api/client.rb, line 41
def update(id, params)
  response = conn.put do |req|
    req.url "/rest/api/content/#{id}"
    req.headers['Content-Type'] = 'application/json'
    req.body                    = params.to_json
  end
  JSON.parse(response.body)
end