shutl_resource 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,14 +20,16 @@ module Shutl::Resource
20
20
 
21
21
  module Configuration
22
22
  class << self
23
- def logger
24
- @logger ||= Logger.new($stdout)
25
- end
23
+ attr_accessor :base_uri
26
24
 
27
25
  def configure
28
26
  yield self
29
27
  end
30
28
 
29
+ def logger
30
+ @logger ||= Logger.new($stdout)
31
+ end
32
+
31
33
  def logger=(logger)
32
34
  @logger = logger
33
35
  end
@@ -271,6 +271,8 @@ module Shutl::Resource
271
271
  def generate_url!(url_pattern, args, params = {})
272
272
  url = url_pattern.dup
273
273
 
274
+ url = "#{Shutl::Resource.base_uri}#{url}" unless self.base_uri
275
+
274
276
  args, url = replace_args_from_pattern! args, url
275
277
 
276
278
  url = URI.escape url
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '0.10.4'
3
+ VERSION = '0.10.5'
4
4
  end
5
5
  end
@@ -10,7 +10,7 @@ require 'shutl/resource/errors'
10
10
  module Shutl::Resource
11
11
  extend self
12
12
 
13
- delegate :logger, :logger=, to: Configuration
13
+ delegate :logger, :logger=, :base_uri, :base_uri=, to: Configuration
14
14
 
15
15
  def configure(*args, &block)
16
16
  Configuration.configure(*args, &block)
@@ -13,5 +13,18 @@ describe Shutl::Resource do
13
13
 
14
14
  Shutl::Resource.logger.should == logger
15
15
  end
16
+
17
+ it "allows for configuration of the base uri" do
18
+ Shutl::Resource.configure do |config|
19
+ config.base_uri = 'base uri'
20
+ end
21
+
22
+ Shutl::Resource.base_uri.should == 'base uri'
23
+
24
+ #set it back to not corrupt other tests
25
+ Shutl::Resource.configure do |config|
26
+ config.base_uri = nil
27
+ end
28
+ end
16
29
  end
17
30
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe TestConfiguredBaseUriResource do
4
+ let(:headers) do
5
+ {'Accept' => 'application/json',
6
+ 'Content-Type' => 'application/json',
7
+ 'Authorization' => 'Bearer some auth'}
8
+ end
9
+
10
+ before do
11
+ Shutl::Resource.configure do |config|
12
+ config.base_uri = "http://configured"
13
+ end
14
+ end
15
+
16
+ after do
17
+ Shutl::Resource.configure do |config|
18
+ config.base_uri = nil
19
+ end
20
+ end
21
+
22
+ context "uses the configured base uri if present" do
23
+ before do
24
+ @request = stub_request(:get, 'http://configured/test_configured_base_uri_resources/a').
25
+ to_return(:status => 200,
26
+ :body => '{"test_configured_base_uri_resource": { "a": "a", "b": 2 }}',
27
+ :headers => headers)
28
+ end
29
+
30
+ it 'should query the endpoint' do
31
+ TestConfiguredBaseUriResource.find('a', auth: "some auth")
32
+
33
+ @request.should have_been_requested
34
+ end
35
+ end
36
+
37
+ context "doesnt override a resources declared base uri" do
38
+ before do
39
+ @request = stub_request(:get, 'http://host/test_rests/a').
40
+ to_return(:status => 200,
41
+ :body => '{"test_rest": { "a": "a", "b": 2 }}',
42
+ :headers => headers)
43
+ end
44
+
45
+ it 'should query the endpoint' do
46
+ TestRest.find('a', auth: "some auth")
47
+
48
+ @request.should have_been_requested
49
+ end
50
+ end
51
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,5 +2,7 @@ require 'shutl_resource'
2
2
  require 'webmock/rspec'
3
3
 
4
4
  require 'support/test_resource'
5
+ require 'support/test_resource'
6
+ require 'support/configured_base_uri_resource'
5
7
  require 'support/test_singular_resource'
6
8
  require 'support/double_logger'
@@ -0,0 +1,5 @@
1
+ class TestConfiguredBaseUriResource
2
+ include Shutl::Resource::Rest
3
+ resource_id :a
4
+ end
5
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-05 00:00:00.000000000 Z
14
+ date: 2013-07-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
18
- requirement: !ruby/object:Gem::Requirement
18
+ requirement: &70115703855460 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,31 +23,21 @@ dependencies:
23
23
  version: 0.10.0
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: 0.10.0
26
+ version_requirements: *70115703855460
32
27
  - !ruby/object:Gem::Dependency
33
28
  name: shutl_auth
34
- requirement: !ruby/object:Gem::Requirement
29
+ requirement: &70115703853480 !ruby/object:Gem::Requirement
35
30
  none: false
36
31
  requirements:
37
- - - '='
32
+ - - =
38
33
  - !ruby/object:Gem::Version
39
34
  version: 0.8.0
40
35
  type: :runtime
41
36
  prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - '='
46
- - !ruby/object:Gem::Version
47
- version: 0.8.0
37
+ version_requirements: *70115703853480
48
38
  - !ruby/object:Gem::Dependency
49
39
  name: activemodel
50
- requirement: !ruby/object:Gem::Requirement
40
+ requirement: &70115703852820 !ruby/object:Gem::Requirement
51
41
  none: false
52
42
  requirements:
53
43
  - - ! '>='
@@ -55,15 +45,10 @@ dependencies:
55
45
  version: '0'
56
46
  type: :runtime
57
47
  prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
48
+ version_requirements: *70115703852820
64
49
  - !ruby/object:Gem::Dependency
65
50
  name: rake
66
- requirement: !ruby/object:Gem::Requirement
51
+ requirement: &70115703850460 !ruby/object:Gem::Requirement
67
52
  none: false
68
53
  requirements:
69
54
  - - ! '>='
@@ -71,15 +56,10 @@ dependencies:
71
56
  version: '0'
72
57
  type: :development
73
58
  prerelease: false
74
- version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: '0'
59
+ version_requirements: *70115703850460
80
60
  - !ruby/object:Gem::Dependency
81
61
  name: rspec
82
- requirement: !ruby/object:Gem::Requirement
62
+ requirement: &70115703870120 !ruby/object:Gem::Requirement
83
63
  none: false
84
64
  requirements:
85
65
  - - ~>
@@ -87,15 +67,10 @@ dependencies:
87
67
  version: 2.11.0
88
68
  type: :development
89
69
  prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ~>
94
- - !ruby/object:Gem::Version
95
- version: 2.11.0
70
+ version_requirements: *70115703870120
96
71
  - !ruby/object:Gem::Dependency
97
72
  name: debugger
98
- requirement: !ruby/object:Gem::Requirement
73
+ requirement: &70115703885320 !ruby/object:Gem::Requirement
99
74
  none: false
100
75
  requirements:
101
76
  - - ! '>='
@@ -103,15 +78,10 @@ dependencies:
103
78
  version: '0'
104
79
  type: :development
105
80
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
81
+ version_requirements: *70115703885320
112
82
  - !ruby/object:Gem::Dependency
113
83
  name: webmock
114
- requirement: !ruby/object:Gem::Requirement
84
+ requirement: &70115703884340 !ruby/object:Gem::Requirement
115
85
  none: false
116
86
  requirements:
117
87
  - - ~>
@@ -119,12 +89,7 @@ dependencies:
119
89
  version: 1.8.7
120
90
  type: :development
121
91
  prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ~>
126
- - !ruby/object:Gem::Version
127
- version: 1.8.7
92
+ version_requirements: *70115703884340
128
93
  description: Shutl Rest resource
129
94
  email:
130
95
  - davidr@shutl.co.uk
@@ -152,10 +117,12 @@ files:
152
117
  - script/ci
153
118
  - shutl_resource.gemspec
154
119
  - spec/configuration_spec.rb
120
+ - spec/configured_base_uri_spec.rb
155
121
  - spec/dynamic_resource_spec.rb
156
122
  - spec/remote_url_spec.rb
157
123
  - spec/rest_resource_spec.rb
158
124
  - spec/spec_helper.rb
125
+ - spec/support/configured_base_uri_resource.rb
159
126
  - spec/support/double_logger.rb
160
127
  - spec/support/test_resource.rb
161
128
  - spec/support/test_singular_resource.rb
@@ -173,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
140
  version: '0'
174
141
  segments:
175
142
  - 0
176
- hash: -2937045685155006965
143
+ hash: -1303369992111380096
177
144
  required_rubygems_version: !ruby/object:Gem::Requirement
178
145
  none: false
179
146
  requirements:
@@ -182,19 +149,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
149
  version: '0'
183
150
  segments:
184
151
  - 0
185
- hash: -2937045685155006965
152
+ hash: -1303369992111380096
186
153
  requirements: []
187
154
  rubyforge_project:
188
- rubygems_version: 1.8.23
155
+ rubygems_version: 1.8.11
189
156
  signing_key:
190
157
  specification_version: 3
191
158
  summary: Manage Shutl Rest resource. Parse/Serialize JSON
192
159
  test_files:
193
160
  - spec/configuration_spec.rb
161
+ - spec/configured_base_uri_spec.rb
194
162
  - spec/dynamic_resource_spec.rb
195
163
  - spec/remote_url_spec.rb
196
164
  - spec/rest_resource_spec.rb
197
165
  - spec/spec_helper.rb
166
+ - spec/support/configured_base_uri_resource.rb
198
167
  - spec/support/double_logger.rb
199
168
  - spec/support/test_resource.rb
200
169
  - spec/support/test_singular_resource.rb