Module: Authful::Endpoint::ClassMethods

Defined in:
lib/authful/endpoint.rb

Instance Method Summary collapse

Instance Method Details

#capture_common_errors(error) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/authful/endpoint.rb', line 29

def capture_common_errors(error)
  if error.http_code == 400
    JSON.parse($!.response)
  elsif error.http_code == 401
    raise Authful::Errors::IncorrectApiToken
  elsif error.http_code == 403
    JSON.parse($!.response)
  elsif error.http_code == 409
    JSON.parse($!.response)
  else
    raise error
  end
end

#configObject



14
15
16
# File 'lib/authful/endpoint.rb', line 14

def config
  @config
end

#configure(&block) ⇒ Object



10
11
12
# File 'lib/authful/endpoint.rb', line 10

def configure(&block)
  block.call(@config)
end

#headersObject



47
48
49
# File 'lib/authful/endpoint.rb', line 47

def headers
  {"Api-Token" => Authful.config.api_key}
end

#send_request(method, path, data = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/authful/endpoint.rb', line 18

def send_request(method, path, data = nil)
  if data
    r = RestClient.send(method, url_for(path), data, headers)
  else
    r = RestClient.send(method, url_for(path), headers)
  end
  JSON.parse(r)
rescue
  capture_common_errors($!)
end

#url_for(path) ⇒ Object



43
44
45
# File 'lib/authful/endpoint.rb', line 43

def url_for(path)
  [Authful.config.endpoint, path].join("")
end