userapp 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,7 +25,7 @@ module UserApp
25
25
 
26
26
  def get_options(*args)
27
27
  if self.options.nil?
28
- self.options = UserApp::ClientOptions.get_global().copy()
28
+ self.options = ClientOptions.get_global().clone()
29
29
  end
30
30
  return self.options
31
31
  end
@@ -62,9 +62,9 @@ module UserApp
62
62
 
63
63
  if self.options.throw_errors and is_error_result
64
64
  if result.error_code == 'INVALID_SERVICE'
65
- raise InvalidServiceException.new("Service '#{service}' does not exist.")
65
+ raise InvalidServiceError.new("Service '#{service}' does not exist.")
66
66
  elsif result.error_code == 'INVALID_METHOD'
67
- raise InvalidServiceException.new("Method '#{method}' on service '#{service}' does not exist.")
67
+ raise InvalidServiceError.new("Method '#{method}' on service '#{service}' does not exist.")
68
68
  else
69
69
  raise ServiceError.new(result.error_code, result.message)
70
70
  end
@@ -4,6 +4,7 @@ module UserApp
4
4
  class ClientOptions
5
5
  @@instance = nil
6
6
 
7
+ attr_accessor :version
7
8
  attr_accessor :app_id
8
9
  attr_accessor :token
9
10
  attr_accessor :base_address
@@ -13,6 +14,7 @@ module UserApp
13
14
  attr_accessor :logger
14
15
 
15
16
  def initialize(*args)
17
+ @version = 1
16
18
  @base_address = 'api.userapp.io'
17
19
  @throw_errors = true
18
20
  @secure = true
@@ -42,10 +44,6 @@ module UserApp
42
44
  end
43
45
  end
44
46
 
45
- def copy()
46
- return ClientOptions.new(self.instance_variables)
47
- end
48
-
49
47
  def self.get_global(*args)
50
48
  if @@instance.nil?
51
49
  @@instance = ClientOptions.new(args)
@@ -2,10 +2,10 @@ module UserApp
2
2
  class Error < Exception
3
3
  end
4
4
 
5
- class InvalidServiceException < Error
5
+ class InvalidServiceError < Error
6
6
  end
7
7
 
8
- class InvalidMethodException < Error
8
+ class InvalidMethodError < Error
9
9
  end
10
10
 
11
11
  class ServiceError < Error
@@ -8,16 +8,13 @@ module UserApp
8
8
  attr_accessor :client
9
9
  attr_accessor :services
10
10
  attr_accessor :service_name
11
- attr_accessor :service_version
12
11
 
13
12
  def initialize(*args)
14
13
  @services = Hash.new()
15
- if (args.length == 2 or args.length == 3) and args[0].is_a?(Client)
14
+ if args.length == 2 and args[0].is_a?(Client)
16
15
  @client = args[0]
17
16
  @service_name = args[1]
18
- @service_version = args.length == 2 ? 1 : args[2]
19
17
  else
20
- self.service_version = 1
21
18
  @client = Client.new(*args)
22
19
  end
23
20
  end
@@ -29,24 +26,20 @@ module UserApp
29
26
  def method_missing(method_id, *args)
30
27
  if args.length > 0
31
28
  if self.service_name.nil?
32
- raise UserAppError.new("Unable to call method on base service.")
29
+ raise UserApp::Error.new("Unable to call method on base service.")
33
30
  end
34
31
 
35
- self.client.call(self.service_version, self.service_name, method_id.to_s(), args[0])
32
+ self.client.call(self.get_options().version, self.service_name, method_id.to_s(), args[0])
36
33
  else
37
34
  target_service = nil
38
- target_version = nil
39
35
 
40
36
  if self.services[method_id]
41
37
  return self.services[method_id]
42
38
  end
43
39
 
44
40
  if self.service_name.nil? and method_id.length >= 2 and method_id[0] == 'v' and method_id[1, method_id.length-1].match(/\A[0-9]+\Z/)
45
- target_version = method_id[1].to_i
46
- end
47
-
48
- if target_version.nil?
49
- target_version = self.service_version
41
+ self.get_options().version = method_id[1].to_i
42
+ else
50
43
  if !self.service_name.nil?
51
44
  target_service = self.service_name.to_s + '.' + method_id.to_s
52
45
  else
@@ -54,7 +47,8 @@ module UserApp
54
47
  end
55
48
  end
56
49
 
57
- proxy = ProxyClient.new(self.client, target_service, target_version)
50
+ puts target_service
51
+ proxy = ProxyClient.new(self.client, target_service)
58
52
  self.services[method_id] = proxy
59
53
 
60
54
  return proxy
@@ -2,10 +2,17 @@ module UserApp
2
2
  class Client
3
3
  require File.expand_path('../client.rb', __FILE__)
4
4
  end
5
+
5
6
  class ProxyClient
6
7
  require File.expand_path('../proxy_client.rb', __FILE__)
7
8
  end
9
+
8
10
  class API < ProxyClient
9
11
  require File.expand_path('../api.rb', __FILE__)
10
12
  end
13
+
14
+ class Error < Exception; end
15
+ class InvalidServiceError < Error; end
16
+ class InvalidMethodError < Error; end
17
+ class ServiceError < Error; end
11
18
  end
@@ -1,3 +1,3 @@
1
1
  module UserApp
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2014-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &9937560 !ruby/object:Gem::Requirement
16
+ requirement: &15729580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9937560
24
+ version_requirements: *15729580
25
25
  description: User management and authentication for your Ruby app.
26
26
  email: robin.orheden@userapp.io
27
27
  executables: []