restafari 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -24,4 +24,4 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "rspec"
25
25
  s.add_development_dependency "rake"
26
26
 
27
- end
27
+ end
data/Gemfile CHANGED
@@ -4,8 +4,8 @@ source "http://rubygems.org"
4
4
 
5
5
 
6
6
  gem 'faraday'
7
-
8
7
  group :test do
8
+
9
9
  gem 'rake'
10
10
  gem 'rspec'
11
11
  gem 'webmock'
@@ -9,7 +9,10 @@ module Restafari
9
9
 
10
10
  module ClassMethods
11
11
  def action(name, *args)
12
+
12
13
  case args.length
14
+ when 0
15
+ path = "/#{name.to_s}"
13
16
  when 1
14
17
  if args[0].is_a? String
15
18
  path = args[0]
@@ -24,15 +27,24 @@ module Restafari
24
27
 
25
28
  default_params ||= {}
26
29
 
27
- define_singleton_method(name) { |params={}|
28
- execute!(path, default_params.merge(params))
29
- }
30
+ define_singleton_method(name) do |params={}|
31
+ execute!(path, default_params.merge(params)) do |method, url, path, params|
32
+ send_using_faraday(method, url, path, params)
33
+ end
34
+ end
35
+
36
+ define_singleton_method("#{name}_url") do |params={}|
37
+ Restafari.config.run_before_request_hook(default_params.merge(params))
38
+ conn = Faraday.new(url: Restafari.config.url, params: params)
39
+ conn.build_url(path)
40
+ end
41
+
30
42
  end
31
43
 
32
44
  private
33
45
  def execute!(path, params)
34
46
  conn = Faraday.new(url: Restafari.config.url)
35
- Restafari.config.run_before_request_hook(conn, params)
47
+ Restafari.config.run_before_request_hook(params)
36
48
  result = conn.send(Restafari.config.http_method, path, params)
37
49
  Restafari.config.run_after_response_hook(result)
38
50
  Restafari::Response.new(result)
@@ -1,3 +1,3 @@
1
1
  module Restafari
2
- VERSION = 0.5
2
+ VERSION = 0.6
3
3
  end
@@ -7,7 +7,7 @@ describe Restafari::Action do
7
7
  action :some_method, { b: 1 }
8
8
  end
9
9
 
10
- SomeAction.should_receive(:execute!).with(kind_of(String), { b: 1 }).once
10
+ SomeAction.should_receive(:execute!).with("/some_method", { b: 1 }).once
11
11
  SomeAction.some_method()
12
12
  end
13
13
 
@@ -27,7 +27,7 @@ describe Restafari::Action do
27
27
  action :some_method
28
28
  end
29
29
 
30
- Restafari.config.before_request do |conn, params|
30
+ Restafari.config.before_request do |params|
31
31
  params[:test] = true
32
32
  end
33
33
 
@@ -51,4 +51,12 @@ describe Restafari::Action do
51
51
  SomeAction.some_method()
52
52
  end
53
53
 
54
+ it "should allow accessing the action url" do
55
+ class UrlTest
56
+ include Restafari::Action
57
+ action :url_method
58
+ end
59
+ UrlTest.url_method_url(rt:2).to_s.should eq "http://www.example.com/url_method?rt=2"
60
+ end
61
+
54
62
  end
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ end
12
12
 
13
13
  Restafari.config.base_url = "www.example.com"
14
14
  WebMock::stub_request(:post, "http://#{Restafari.config.base_url}/").to_return(:status => 200, :body => "{}", :headers => {})
15
-
15
+ WebMock::stub_request(:post, "http://#{Restafari.config.base_url}/some_method").to_return(:status => 200, :body => "{}", :headers => {})
16
16
  unless defined?(RM_HOME)
17
17
  # this is here to allow teamcity to run with spork
18
18
  RM_HOME=File.expand_path("~/BuildAgent/plugins/rake-runner")
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.5'
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 6
9
+ version: "0.6"
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-29 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-07-15 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
15
20
  name: faraday
16
- requirement: &70155096119940 !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: *70155096119940
25
- - !ruby/object:Gem::Dependency
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
26
34
  name: webmock
27
- requirement: &70155096119380 !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: *70155096119380
36
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
37
48
  name: spork
38
- requirement: &70155096118760 !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: *70155096118760
47
- - !ruby/object:Gem::Dependency
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
48
62
  name: rack-test
49
- requirement: &70155096118020 !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: *70155096118020
58
- - !ruby/object:Gem::Dependency
74
+ version_requirements: *id004
75
+ - !ruby/object:Gem::Dependency
59
76
  name: rspec
60
- requirement: &70155096117260 !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: *70155096117260
69
- - !ruby/object:Gem::Dependency
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
70
90
  name: rake
71
- requirement: &70155096116560 !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: *70155096116560
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
+