social-avatar-proxy 0.0.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -4
- data/lib/social_avatar_proxy/app.rb +9 -1
- data/lib/social_avatar_proxy/version.rb +1 -1
- data/spec/social_avatar_proxy/app_spec.rb +19 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -25,10 +25,6 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
# Rack
|
29
|
-
|
30
|
-
The Rack app is available at: SocialAvatarProxy::App
|
31
|
-
|
32
28
|
# Rails
|
33
29
|
|
34
30
|
In your `config/routes.rb` file:
|
@@ -53,6 +49,16 @@ image_tag(facebook_avatar_path("username"))
|
|
53
49
|
image_tag(facebook_avatar_path(12345))
|
54
50
|
```
|
55
51
|
|
52
|
+
# Rack
|
53
|
+
|
54
|
+
The Rack app is available at: SocialAvatarProxy::App.
|
55
|
+
|
56
|
+
Both the class and an instance respond to `call` so either can be mounted. The reason for this is that you might wish to set some options first, example:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
use SocialAvatarProxy::App.new(cache_control: false)
|
60
|
+
```
|
61
|
+
|
56
62
|
## Contributing
|
57
63
|
|
58
64
|
1. Fork it
|
@@ -9,6 +9,10 @@ module SocialAvatarProxy
|
|
9
9
|
new(options).call(env)
|
10
10
|
end
|
11
11
|
|
12
|
+
def self.routes(options = {})
|
13
|
+
new(options).routes
|
14
|
+
end
|
15
|
+
|
12
16
|
attr_reader :options, :request
|
13
17
|
|
14
18
|
def initialize(options = {})
|
@@ -29,7 +33,7 @@ module SocialAvatarProxy
|
|
29
33
|
end
|
30
34
|
|
31
35
|
def path_prefix
|
32
|
-
request && request.env["SCRIPT_NAME"].gsub(/\/$/, "")
|
36
|
+
(options[:path_prefix] || (request && request.env["SCRIPT_NAME"]) || "").gsub(/\/$/, "")
|
33
37
|
end
|
34
38
|
|
35
39
|
def response
|
@@ -73,6 +77,10 @@ module SocialAvatarProxy
|
|
73
77
|
Rack::Response.new("Not Found", 404)
|
74
78
|
end
|
75
79
|
|
80
|
+
def routes
|
81
|
+
Routes.new(self)
|
82
|
+
end
|
83
|
+
|
76
84
|
private
|
77
85
|
def load_avatar(service, id)
|
78
86
|
# titleize the service name
|
@@ -37,6 +37,25 @@ describe SocialAvatarProxy::App do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
describe "::routes" do
|
41
|
+
subject { SocialAvatarProxy::App }
|
42
|
+
|
43
|
+
it "should return a object providing the path helpers" do
|
44
|
+
options = { path_prefix: "/test" }
|
45
|
+
expect(subject.routes(options).facebook_avatar_path("ryandtownsend")).to match(/^\/.*$/)
|
46
|
+
expect(subject.routes(options).twitter_avatar_path(2202971)).to match(/^\/.*$/)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#routes" do
|
51
|
+
subject { app }
|
52
|
+
|
53
|
+
it "should return a object providing the path helpers" do
|
54
|
+
expect(subject.routes.facebook_avatar_path("ryandtownsend")).to match(/^\/.*$/)
|
55
|
+
expect(subject.routes.twitter_avatar_path(2202971)).to match(/^\/.*$/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
40
59
|
context "given an invalid path" do
|
41
60
|
it "should return a 404 response" do
|
42
61
|
path = "/unknown"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social-avatar-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -160,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
segments:
|
162
162
|
- 0
|
163
|
-
hash: -
|
163
|
+
hash: -264408388201805182
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
165
|
none: false
|
166
166
|
requirements:
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
segments:
|
171
171
|
- 0
|
172
|
-
hash: -
|
172
|
+
hash: -264408388201805182
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
175
|
rubygems_version: 1.8.24
|