Class: Amee::Service

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/amee/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_token) ⇒ Service

Returns a new instance of Service.



9
10
11
# File 'lib/amee/service.rb', line 9

def initialize(auth_token)
  @auth_token = auth_token
end

Instance Attribute Details

#auth_tokenObject

Returns the value of attribute auth_token.



7
8
9
# File 'lib/amee/service.rb', line 7

def auth_token
  @auth_token
end

Class Method Details

.auth_token(username, password, path) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/amee/service.rb', line 29

def self.auth_token(username, password, path)
  response = Net::HTTP.post_form(
    URI.parse("http://#{Amee::Config[:server]}#{path}"),
    {'username'=> username, 'password'=>password}
  )
  response['authToken']
rescue Errno::ECONNREFUSED, SocketError
  raise Amee::Session::ServerNotFound, "Amee Server could not be found"
end

Instance Method Details

#delete(method, path, options = {}) ⇒ Object



25
26
27
# File 'lib/amee/service.rb', line 25

def delete(method, path, options = {})
  perform_request(:delete, method, full_path(path), options)
end

#get(method, path, options = {}) ⇒ Object



17
18
19
# File 'lib/amee/service.rb', line 17

def get(method, path, options = {})
  perform_request(:get, method,full_path(path), options)
end

#post(method, path, options = {}) ⇒ Object



13
14
15
# File 'lib/amee/service.rb', line 13

def post(method, path, options = {})
  perform_request(:post, method, full_path(path), options)
end

#put(method, path, options = {}) ⇒ Object



21
22
23
# File 'lib/amee/service.rb', line 21

def put(method, path, options = {})
  perform_request(:put, method, full_path(path), options)
end