Class: Atlantis::AppClient

Inherits:
Object
  • Object
show all
Defined in:
lib/atlantis/app_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAppClient

Returns a new instance of AppClient.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 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

Instance Attribute Details

#httpObject (readonly)

Returns the value of attribute http.



11
12
13
# File 'lib/atlantis/app_client.rb', line 11

def http
  @http
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/atlantis/app_client.rb', line 11

def url
  @url
end

Instance Method Details

#_delete(path, params = {}) ⇒ Object



40
41
42
# File 'lib/atlantis/app_client.rb', line 40

def _delete path, params={}
 request :delete, path, params
end

#_get(path, params = {}) ⇒ Object



44
45
46
# File 'lib/atlantis/app_client.rb', line 44

def _get path, params={}
 request :get, path, params
end

#_post(path, params = {}) ⇒ Object



48
49
50
# File 'lib/atlantis/app_client.rb', line 48

def _post path, params={}
 request :post, path, params
end

#_put(path, params = {}) ⇒ Object



52
53
54
# File 'lib/atlantis/app_client.rb', line 52

def _put path, params={}
 request :put, path, params
end

#create(attributes) ⇒ Object



36
37
38
# File 'lib/atlantis/app_client.rb', line 36

def create attributes
  _post "/documents", attributes
end

#prepare(file, options) ⇒ Object



32
33
34
# File 'lib/atlantis/app_client.rb', line 32

def prepare file, options
	_post '/upload/prepare', options
end

#request(method, path, params) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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