restafari 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,11 +31,12 @@ module Restafari
31
31
 
32
32
  private
33
33
  def execute!(path, params)
34
- params = Restafari.config.run_before_request_hook(params)
35
34
  conn = Faraday.new(url: Restafari.config.url)
35
+ Restafari.config.run_before_request_hook(conn, params)
36
36
  result = conn.send(Restafari.config.http_method, path, params)
37
+ Restafari.config.run_after_response_hook(result)
37
38
  Restafari::Response.new(result)
38
39
  end
39
40
  end
40
41
  end
41
- end
42
+ end
@@ -12,6 +12,7 @@ module Restafari
12
12
  http_method: :post,
13
13
  scheme: :http,
14
14
  before_request: nil,
15
+ after_response: nil
15
16
  }
16
17
 
17
18
  define_singleton_method :defaults do
@@ -38,9 +39,17 @@ module Restafari
38
39
  @before_request = block if block_given?
39
40
  end
40
41
 
42
+ def after_response(&block)
43
+ @after_response = block if block_given?
44
+ end
45
+
41
46
  def run_before_request_hook(*params)
42
- @before_request.call(*params)
47
+ @before_request.call(*params) unless @after_response.nil?
48
+ end
49
+
50
+ def run_after_response_hook(*params)
51
+ @after_response.call(*params) unless @after_response.nil?
43
52
  end
44
53
 
45
54
  end
46
- end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Restafari
2
- VERSION = 0.3
3
- end
2
+ VERSION = 0.4
3
+ end
@@ -27,7 +27,7 @@ describe Restafari::Action do
27
27
  action :some_method
28
28
  end
29
29
 
30
- Restafari.config.before_request do |params|
30
+ Restafari.config.before_request do |conn, params|
31
31
  params[:test] = true
32
32
  end
33
33
 
@@ -36,4 +36,19 @@ describe Restafari::Action do
36
36
  SomeAction.some_method()
37
37
  end
38
38
 
39
- end
39
+ it "should run the after response hook after each response" do
40
+ class SomeAction
41
+ include Restafari::Action
42
+ action :some_method
43
+ end
44
+
45
+ Restafari.config.after_response do |response|
46
+ "aaa"
47
+ end
48
+
49
+
50
+ Restafari.config.should_receive(:run_after_response_hook).once.and_return("aaa")
51
+ SomeAction.some_method()
52
+ end
53
+
54
+ end
metadata CHANGED
@@ -1,89 +1,115 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: restafari
3
- version: !ruby/object:Gem::Version
4
- version: '0.3'
3
+ version: !ruby/object:Gem::Version
4
+ hash: 3
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ version: "0.4"
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Danni Friedland
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-05-14 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-05-29 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
15
20
  name: faraday
16
- requirement: &70206649617060 !ruby/object:Gem::Requirement
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
22
31
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70206649617060
25
- - !ruby/object:Gem::Dependency
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
26
34
  name: webmock
27
- requirement: &70206649616640 !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
28
37
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
33
45
  type: :development
34
- prerelease: false
35
- version_requirements: *70206649616640
36
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
37
48
  name: spork
38
- requirement: &70206649616220 !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
39
51
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
44
59
  type: :development
45
- prerelease: false
46
- version_requirements: *70206649616220
47
- - !ruby/object:Gem::Dependency
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
48
62
  name: rack-test
49
- requirement: &70206649615800 !ruby/object:Gem::Requirement
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
50
65
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
55
73
  type: :development
56
- prerelease: false
57
- version_requirements: *70206649615800
58
- - !ruby/object:Gem::Dependency
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
59
76
  name: rspec
60
- requirement: &70206649615380 !ruby/object:Gem::Requirement
77
+ prerelease: false
78
+ requirement: &id005 !ruby/object:Gem::Requirement
61
79
  none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
66
87
  type: :development
67
- prerelease: false
68
- version_requirements: *70206649615380
69
- - !ruby/object:Gem::Dependency
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
70
90
  name: rake
71
- requirement: &70206649614960 !ruby/object:Gem::Requirement
91
+ prerelease: false
92
+ requirement: &id006 !ruby/object:Gem::Requirement
72
93
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
77
101
  type: :development
78
- prerelease: false
79
- version_requirements: *70206649614960
102
+ version_requirements: *id006
80
103
  description: Helper class to work with the restful apis
81
- email:
104
+ email:
82
105
  - - dannifriedland@gmail.com
83
106
  executables: []
107
+
84
108
  extensions: []
109
+
85
110
  extra_rdoc_files: []
86
- files:
111
+
112
+ files:
87
113
  - .gemspec
88
114
  - .gitignore
89
115
  - Gemfile
@@ -100,26 +126,36 @@ files:
100
126
  - spec/spec_helper.rb
101
127
  homepage: https://github.com/TheGiftsProject/restafari
102
128
  licenses: []
129
+
103
130
  post_install_message:
104
131
  rdoc_options: []
105
- require_paths:
132
+
133
+ require_paths:
106
134
  - lib
107
- required_ruby_version: !ruby/object:Gem::Requirement
135
+ required_ruby_version: !ruby/object:Gem::Requirement
108
136
  none: false
109
- requirements:
110
- - - ! '>='
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ hash: 3
141
+ segments:
142
+ - 0
143
+ version: "0"
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
145
  none: false
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
119
153
  requirements: []
154
+
120
155
  rubyforge_project:
121
- rubygems_version: 1.8.10
156
+ rubygems_version: 1.8.13
122
157
  signing_key:
123
158
  specification_version: 3
124
159
  summary: A DSL for consuming RESTful apis
125
160
  test_files: []
161
+