class Atlantis::AppClient

Attributes

http[R]
url[R]

Public Class Methods

new() click to toggle source
# File lib/atlantis/app_client.rb, line 13
def initialize
  @url = ENV['ATLANTIS_URL'] || 'http://atlantis.sodalis.com.au'
  @http = Faraday.new(url: @url, ssl: {verify: false}) do |builder|
    builder.response :mashify
    builder.response :json, :content_type => /\bjson$/
    builder.request :json
    builder.request :basic_auth, ENV['ATLANTIS_API_KEY'], ENV['ATLANTIS_API_SECRET']
    builder.options[:read_timeout] = 4
    builder.options[:open_timeout] = 2
    builder.adapter :excon
  end

  @http.headers = {
    accept:  'application/json',
    user_agent: "Atlantis Ruby Gem #{Atlantis::VERSION}",
    "Content-Type" => "application/json"
  }
end

Public Instance Methods

_delete(path, params={}) click to toggle source
# File lib/atlantis/app_client.rb, line 40
def _delete path, params={}
 request :delete, path, params
end
_get(path, params={}) click to toggle source
# File lib/atlantis/app_client.rb, line 44
def _get path, params={}
 request :get, path, params
end
_post(path, params={}) click to toggle source
# File lib/atlantis/app_client.rb, line 48
def _post path, params={}
 request :post, path, params
end
_put(path, params={}) click to toggle source
# File lib/atlantis/app_client.rb, line 52
def _put path, params={}
 request :put, path, params
end
create(attributes) click to toggle source
# File lib/atlantis/app_client.rb, line 36
def create attributes
  _post "/documents", attributes
end
prepare(file, options) click to toggle source
# File lib/atlantis/app_client.rb, line 32
def prepare file, options
    _post '/upload/prepare', options
end
request(method, path, params) click to toggle source
# File lib/atlantis/app_client.rb, line 56
def request method, path, params
  response = http.send(method, path, params)

  case response.status
  when 200..299
    response.body
  when 404, 410
    raise RequestError::NotFound.new(response)
  when 401
    raise RequestError::Unauthorized.new(response)
  else
    raise RequestError.new(response)
  end
end