pebblebed 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pebblebed/config.rb +51 -25
- data/lib/pebblebed/http.rb +4 -3
- data/lib/pebblebed/version.rb +1 -1
- data/spec/config_spec.rb +38 -0
- metadata +3 -8
data/lib/pebblebed/config.rb
CHANGED
@@ -11,10 +11,11 @@ module Pebblebed
|
|
11
11
|
def service(name, options = {})
|
12
12
|
Pebblebed.require_service(name, options)
|
13
13
|
end
|
14
|
-
end
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
def base_uri(value)
|
16
|
+
Pebblebed.base_uri = value
|
17
|
+
end
|
18
|
+
alias base_url base_uri
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.require_service(name, options = {})
|
@@ -26,33 +27,58 @@ module Pebblebed
|
|
26
27
|
END
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
class << self
|
31
|
+
def config(&block)
|
32
|
+
Builder.new.send(:instance_eval, &block)
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
def host
|
36
|
+
@host
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
39
|
+
def host=(value)
|
40
|
+
@host = value
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def memcached
|
44
|
+
raise RuntimeError, "Please set Pebblebed.memcached = <your memcached client>" unless @memcached
|
45
|
+
@memcached
|
46
|
+
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
def memcached=(value)
|
49
|
+
@memcached = value
|
50
|
+
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
def services
|
53
|
+
@services.keys
|
54
|
+
end
|
55
|
+
|
56
|
+
def base_uri
|
57
|
+
@base_uri
|
58
|
+
end
|
59
|
+
alias base_url base_uri
|
60
|
+
|
61
|
+
def base_uri=(value)
|
62
|
+
@base_uri = value
|
63
|
+
end
|
64
|
+
alias base_url= base_uri=
|
54
65
|
|
55
|
-
|
56
|
-
|
66
|
+
def version_of(service)
|
67
|
+
return 1 unless @services && @services[service.to_sym]
|
68
|
+
@services[service.to_sym][:version] || 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def root_url_for(service, url_opts={})
|
72
|
+
URI.join(base_url_for(url_opts), "/api/#{service}/v#{version_of(service)}/")
|
73
|
+
end
|
74
|
+
|
75
|
+
def base_url_for(url_opts)
|
76
|
+
raise RuntimeError, "Please specify only one of host & base_uri" if url_opts[:host] && (url_opts[:base_uri] || url_opts[:base_url])
|
77
|
+
[:base_uri, :base_url].each do |key|
|
78
|
+
return url_opts[key] if url_opts[key]
|
79
|
+
end
|
80
|
+
return "http://#{url_opts[:host]}" if url_opts[:host]
|
81
|
+
base_uri || "http://#{host}"
|
82
|
+
end
|
57
83
|
end
|
58
84
|
end
|
data/lib/pebblebed/http.rb
CHANGED
@@ -10,11 +10,12 @@ require 'active_support'
|
|
10
10
|
|
11
11
|
module Pebblebed
|
12
12
|
class HttpError < StandardError
|
13
|
-
attr_reader :status, :message
|
13
|
+
attr_reader :status, :message, :response
|
14
14
|
|
15
|
-
def initialize(message, status = nil)
|
15
|
+
def initialize(message, status = nil, response = nil)
|
16
16
|
@message = message
|
17
17
|
@status = status
|
18
|
+
@response = response
|
18
19
|
end
|
19
20
|
|
20
21
|
def not_found?
|
@@ -104,7 +105,7 @@ module Pebblebed
|
|
104
105
|
elsif result.status >= 400
|
105
106
|
errmsg = "Service request to '#{result.url}' failed (#{result.status}):"
|
106
107
|
errmsg << extract_error_summary(result.body)
|
107
|
-
raise HttpError.new(ActiveSupport::SafeBuffer.new(errmsg), result.status)
|
108
|
+
raise HttpError.new(ActiveSupport::SafeBuffer.new(errmsg), result.status, result)
|
108
109
|
end
|
109
110
|
result
|
110
111
|
end
|
data/lib/pebblebed/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -31,4 +31,42 @@ describe Pebblebed do
|
|
31
31
|
Pebblebed.root_url_for(:foobar).to_s.should eq "http://example.org/api/foobar/v2/"
|
32
32
|
end
|
33
33
|
|
34
|
+
it "works with pebbles that are exposed via https" do
|
35
|
+
Pebblebed.config do
|
36
|
+
service :checkpoint
|
37
|
+
service :foobar, :version => 2
|
38
|
+
end
|
39
|
+
Pebblebed.base_url = "https://example.org"
|
40
|
+
Pebblebed.root_url_for(:checkpoint).to_s.should eq "https://example.org/api/checkpoint/v1/"
|
41
|
+
Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s.should eq "https://checkpoint.dev/api/checkpoint/v1/"
|
42
|
+
Pebblebed.root_url_for(:foobar).to_s.should eq "https://example.org/api/foobar/v2/"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "allows passed in parameters to take precedence" do
|
46
|
+
Pebblebed.config do
|
47
|
+
service :checkpoint
|
48
|
+
service :foobar, :version => 2
|
49
|
+
end
|
50
|
+
Pebblebed.base_url = "https://example.org"
|
51
|
+
Pebblebed.root_url_for(:checkpoint, :host => 'checkpoint.dev').to_s.should eq "http://checkpoint.dev/api/checkpoint/v1/"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "raises an error if :host and :base_uri are both specified as parameters" do
|
55
|
+
Pebblebed.config do
|
56
|
+
service :checkpoint
|
57
|
+
end
|
58
|
+
-> {Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev', :host => 'checkpoint.dev')}.should raise_error RuntimeError
|
59
|
+
-> {Pebblebed.root_url_for(:checkpoint, :base_url => 'https://checkpoint.dev', :host => 'checkpoint.dev')}.should raise_error RuntimeError
|
60
|
+
end
|
61
|
+
|
62
|
+
it "request_uri takes precedence over host" do
|
63
|
+
Pebblebed.config do
|
64
|
+
host "example.net"
|
65
|
+
service :checkpoint
|
66
|
+
service :foobar, :version => 2
|
67
|
+
end
|
68
|
+
Pebblebed.base_url = "https://example.org"
|
69
|
+
Pebblebed.root_url_for(:checkpoint).to_s.should eq "https://example.org/api/checkpoint/v1/"
|
70
|
+
Pebblebed.root_url_for(:checkpoint, :base_uri => 'https://checkpoint.dev').to_s.should eq "https://checkpoint.dev/api/checkpoint/v1/"
|
71
|
+
end
|
34
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebblebed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.37
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -326,18 +326,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
326
326
|
- - ! '>='
|
327
327
|
- !ruby/object:Gem::Version
|
328
328
|
version: '0'
|
329
|
-
segments:
|
330
|
-
- 0
|
331
|
-
hash: 808709011224488874
|
332
329
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
333
330
|
none: false
|
334
331
|
requirements:
|
335
332
|
- - ! '>='
|
336
333
|
- !ruby/object:Gem::Version
|
337
334
|
version: '0'
|
338
|
-
segments:
|
339
|
-
- 0
|
340
|
-
hash: 808709011224488874
|
341
335
|
requirements: []
|
342
336
|
rubyforge_project: pebblebed
|
343
337
|
rubygems_version: 1.8.24
|
@@ -359,3 +353,4 @@ test_files:
|
|
359
353
|
- spec/sinatra_spec.rb
|
360
354
|
- spec/spec_helper.rb
|
361
355
|
- spec/uid_spec.rb
|
356
|
+
has_rdoc:
|