king_soa 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -72,12 +72,12 @@ returns values or errors.
72
72
  === Local Services
73
73
 
74
74
  A local service calls a class with the CamelCased service name. This class MUST
75
- have a self.perform method which receives all of the givven arguments.
75
+ have a self.perform method which receives all of the given arguments.
76
76
 
77
77
  === Queued Services
78
78
 
79
- The service is put onto a resque queue and somewhere in you cloud you should
80
- have a worker looing for it. The service class should also have the resque
79
+ The service is put onto a resque queue and somewhere in your cloud you should
80
+ have a worker looking for it. The service class should also have the resque
81
81
  @queue attribute set so the job can be resceduled if it fails.
82
82
 
83
83
  == Integration
@@ -2,11 +2,10 @@ module KingSoa
2
2
  class Service
3
3
  # endpoint url
4
4
  attr_accessor :debug, :name, :auth, :queue
5
- attr_reader :request
6
5
 
7
6
  def initialize(opts)
8
7
  self.name = opts[:name].to_sym
9
- self.url = opts[:url] if opts[:url]
8
+ self.url = opts[:url] if opts[:url]
10
9
  self.queue = opts[:queue] if opts[:queue]
11
10
  self.auth = opts[:auth] if opts[:auth]
12
11
  end
@@ -14,13 +13,14 @@ module KingSoa
14
13
  # Call a service living somewhere in the soa universe. This is done by
15
14
  # making a POST request to the url
16
15
  def call_remote(*args)
17
- set_request_opts(args)
18
- resp_code = @request.perform
16
+ request = Typhoeus::Easy.new
17
+ set_request_opts(request, args)
18
+ resp_code = request.perform
19
19
  case resp_code
20
20
  when 200
21
- return self.decode(@request.response_body)["result"]
21
+ return self.decode(request.response_body)["result"]
22
22
  else
23
- return self.decode(@request.response_body)["error"]
23
+ return self.decode(request.response_body)["error"]
24
24
  end
25
25
  end
26
26
 
@@ -46,15 +46,15 @@ module KingSoa
46
46
  result = local_class ? local_class.send(:perform, *args) : call_remote(*args)
47
47
  return result
48
48
  end
49
- end
49
+ end
50
50
 
51
51
  # The local class, if found
52
52
  def local_class
53
- @local_class ||= begin
54
- local_class_name.constantize
55
- rescue NameError => e # no local implementation
56
- false
57
- end
53
+ begin
54
+ local_class_name.constantize
55
+ rescue NameError => e # no local implementation
56
+ false
57
+ end
58
58
  end
59
59
 
60
60
  # Return the classname infered from the camelized service name.
@@ -63,18 +63,18 @@ module KingSoa
63
63
  self.name.to_s.camelize
64
64
  end
65
65
 
66
- def request
67
- @request ||= Typhoeus::Easy.new
68
- end
69
-
70
- def set_request_opts(args)
71
- request.url = url
72
- request.method = :post
73
- request.timeout = 100 # milliseconds
74
- request.params = params(args)
75
- request.user_agent = 'KingSoa'
76
- request.follow_location = true
77
- request.verbose = 1 if debug
66
+ # Set options for the typhoeus curl request
67
+ # === Parameter
68
+ # req<Typhoeus::Easy>:: request object
69
+ # args<Array[]>:: the arguments for the soa method, will be json encoded and added to post body
70
+ def set_request_opts(req, args)
71
+ req.url = url
72
+ req.method = :post
73
+ req.timeout = 10000 # milliseconds
74
+ req.params = params(args)
75
+ req.user_agent = 'KingSoa'
76
+ req.follow_location = true
77
+ req.verbose = 1 if debug
78
78
  end
79
79
 
80
80
  # Url receiving the request
data/spec/server/app.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
3
  require 'sinatra'
4
- # change since we want the files in here not from installed gem
4
+ # change PATH since we want the files in here not from installed gem
5
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
7
7
  require "king_soa"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Georg Leciejewski