hookercookerman-amee 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/amee.gemspec +1 -1
- data/features/config.feature +2 -2
- data/lib/amee/service.rb +16 -6
- data/lib/amee/session.rb +1 -0
- data/lib/amee.rb +1 -1
- metadata +1 -1
data/amee.gemspec
CHANGED
data/features/config.feature
CHANGED
@@ -12,9 +12,9 @@ Feature: Amee can be configured
|
|
12
12
|
And the amee config: "cache" should be: "true"
|
13
13
|
|
14
14
|
Scenario: server should be changed if I set a config with new server
|
15
|
-
When I set the: "
|
15
|
+
When I set the: "logging" on the amee config with: "false"
|
16
16
|
|
17
|
-
Then the amee config: "
|
17
|
+
Then the amee config: "logging" should be: "false"
|
18
18
|
And the amee config: "cache_store" should be: "Moneta::Memory"
|
19
19
|
And the amee config: "cache" should be: "true"
|
20
20
|
|
data/lib/amee/service.rb
CHANGED
@@ -2,7 +2,6 @@ require 'net/http'
|
|
2
2
|
module Amee
|
3
3
|
class Service
|
4
4
|
include HTTParty
|
5
|
-
base_uri Amee::Config[:server]
|
6
5
|
format :json
|
7
6
|
|
8
7
|
attr_accessor :auth_token
|
@@ -12,27 +11,29 @@ module Amee
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def post(method, path, options = {})
|
15
|
-
perform_request(:post, method, path, options)
|
14
|
+
perform_request(:post, method, full_path(path), options)
|
16
15
|
end
|
17
16
|
|
18
17
|
def get(method, path, options = {})
|
19
|
-
perform_request(:get, method,
|
18
|
+
perform_request(:get, method,full_path(path), options)
|
20
19
|
end
|
21
20
|
|
22
21
|
def put(method, path, options = {})
|
23
|
-
perform_request(:put, method, path, options)
|
22
|
+
perform_request(:put, method, full_path(path), options)
|
24
23
|
end
|
25
24
|
|
26
25
|
def delete(method, path, options = {})
|
27
|
-
perform_request(:delete, method, path, options)
|
26
|
+
perform_request(:delete, method, full_path(path), options)
|
28
27
|
end
|
29
28
|
|
30
29
|
def self.auth_token(username, password, path)
|
31
30
|
response = Net::HTTP.post_form(
|
32
|
-
URI.parse(
|
31
|
+
URI.parse("http://#{Amee::Config[:server]}#{path}"),
|
33
32
|
{'username'=> username, 'password'=>password}
|
34
33
|
)
|
35
34
|
response['authToken']
|
35
|
+
rescue Errno::ECONNREFUSED, SocketError
|
36
|
+
raise Amee::Session::ServerNotFound, "Amee Server could not be found"
|
36
37
|
end
|
37
38
|
|
38
39
|
private
|
@@ -43,6 +44,8 @@ module Amee
|
|
43
44
|
response = self.class.send(type, path, options)
|
44
45
|
check_response(response.code)
|
45
46
|
Parser.parse(method, response)
|
47
|
+
rescue Errno::ECONNREFUSED, SocketError
|
48
|
+
raise Amee::Session::ServerNotFound, "Amee Server could not be found"
|
46
49
|
end
|
47
50
|
|
48
51
|
def attach_headers(options)
|
@@ -54,6 +57,13 @@ module Amee
|
|
54
57
|
)
|
55
58
|
end
|
56
59
|
|
60
|
+
# using the config instead of base_uri as onces its set its set
|
61
|
+
# Also https as well if needed
|
62
|
+
# same for the format but I dont care about XML
|
63
|
+
def full_path(path)
|
64
|
+
"http://#{Amee::Config[:server]}#{path}"
|
65
|
+
end
|
66
|
+
|
57
67
|
# checking the status code of the response; if we are not authenticated
|
58
68
|
# then authenticate the session
|
59
69
|
#
|
data/lib/amee/session.rb
CHANGED
@@ -6,6 +6,7 @@ module Amee
|
|
6
6
|
class NotAuthenticated < StandardError; end
|
7
7
|
class PermissionDenied < StandardError; end
|
8
8
|
class NotFound < StandardError; end
|
9
|
+
class ServerNotFound < StandardError; end
|
9
10
|
class UnknownError < StandardError; end
|
10
11
|
attr_accessor :auth_token, :cache, :service
|
11
12
|
|
data/lib/amee.rb
CHANGED