hookercookerman-amee 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/amee.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{amee}
5
- s.version = '0.1.6'
5
+ s.version = '0.1.8'
6
6
 
7
7
  s.homepage = 'http://github.com/hookercookerman/amee/tree/master'
8
8
  s.description = %q{Its a gem to interact with the amee api}
@@ -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: "server" on the amee config with: "prod.amee.com"
15
+ When I set the: "logging" on the amee config with: "false"
16
16
 
17
- Then the amee config: "server" should be: "prod.amee.com"
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, path, options)
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(self.base_uri + path),
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
@@ -36,5 +36,5 @@ require "amee/profile_api/profile_category"
36
36
  require "amee/profile_api/profile"
37
37
 
38
38
  module Amee
39
- VERSION = '0.1.6'
39
+ VERSION = '0.1.8'
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookercookerman-amee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Hooker