restulicious 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,15 +8,13 @@ module Restulicious
8
8
  end
9
9
 
10
10
  def get(url, params, &block)
11
- request = ::RESTApi.get(url, params)
12
- request.queue if request.respond_to?(:queue)
13
- handle_response(request, &block)
11
+ @request = ::RESTApi.get(url, params)
12
+ handle_response(&block)
14
13
  end
15
14
 
16
15
  def post(url, params, &block)
17
- request = ::RESTApi.post(url, params)
18
- request.queue if request.respond_to?(:queue)
19
- handle_response(request, &block)
16
+ @request = ::RESTApi.post(url, params)
17
+ handle_response(&block)
20
18
  end
21
19
 
22
20
  def on_success(&block)
@@ -41,29 +39,42 @@ module Restulicious
41
39
  Restulicious.config.hydra
42
40
  end
43
41
 
44
- def handle_response(request, &block)
42
+ def should_run_request?(&block)
43
+ !block_given? && !@on_success && !@on_complete
44
+ end
45
+
46
+ def run_request
47
+ @request.queue if @request.respond_to?(:queue)
48
+ hydra.run
49
+ parser(@request.response).result
50
+ end
51
+
52
+ def handle_response(&block)
45
53
  if @on_success
46
- request.on_success do |response|
54
+ @request.on_success do |response|
47
55
  @on_success.call(parser(response).result)
48
56
  end
49
57
  end
50
58
  if @on_complete
51
- request.on_complete do |response|
59
+ @request.on_complete do |response|
52
60
  @on_complete.call(parser(response).result)
53
61
  end
54
62
  end
55
63
  if @on_failure
56
- request.on_failure do |response|
64
+ @request.on_failure do |response|
57
65
  @on_failure.call(parser(response).result)
58
66
  end
59
67
  end
60
68
  if block_given?
61
- request.on_complete do |response|
69
+ @request.on_complete do |response|
62
70
  block.call(parser(response).result)
63
71
  end
64
- elsif !@on_success && !@on_complete
65
- hydra.run
66
- parser(request.response).result
72
+ end
73
+ if should_run_request?(&block)
74
+ run_request
75
+ else
76
+ @request.queue if @request.respond_to?(:queue)
77
+ @request
67
78
  end
68
79
  end
69
80
  end
@@ -19,7 +19,7 @@ module Restulicious
19
19
  self.class.attribute_names.each do |attr_name|
20
20
  instance_variable_set("@#{attr_name}", check_utf8(attributes[attr_name]))
21
21
  end
22
- super(attributes)
22
+ super
23
23
  end
24
24
 
25
25
  private
@@ -1,3 +1,3 @@
1
1
  module Restulicious
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restulicious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport