social-avatar-proxy 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/social_avatar_proxy/app.rb +16 -7
- data/lib/social_avatar_proxy/version.rb +1 -1
- metadata +3 -3
@@ -5,13 +5,12 @@ require "rack"
|
|
5
5
|
module SocialAvatarProxy
|
6
6
|
class App
|
7
7
|
def self.call(env, options = {})
|
8
|
-
new(
|
8
|
+
new(options).call(env)
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :options
|
11
|
+
attr_reader :options, :request
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@request = Rack::Request.new(env)
|
13
|
+
def initialize(options = {})
|
15
14
|
@options = {
|
16
15
|
expires: 86400, # 1 day from now
|
17
16
|
cache_control: {
|
@@ -22,13 +21,19 @@ module SocialAvatarProxy
|
|
22
21
|
}.merge(options)
|
23
22
|
end
|
24
23
|
|
25
|
-
def
|
26
|
-
Rack::
|
24
|
+
def call(env)
|
25
|
+
@request = Rack::Request.new(env)
|
26
|
+
# return the response
|
27
|
+
response.finish
|
28
|
+
end
|
29
|
+
|
30
|
+
def path_prefix
|
31
|
+
request.env["SCRIPT_NAME"].gsub(/\/$/, "")
|
27
32
|
end
|
28
33
|
|
29
34
|
def response
|
30
35
|
# ensure this is a valid avatar request
|
31
|
-
unless
|
36
|
+
unless request.path =~ /^#{path_prefix}\/(facebook|twitter)\/([\w\-\.]+)(\.(jpe?g|png|gif|bmp))?$/i
|
32
37
|
return not_found
|
33
38
|
end
|
34
39
|
# load the avatar
|
@@ -63,6 +68,10 @@ module SocialAvatarProxy
|
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
71
|
+
def not_found
|
72
|
+
Rack::Response.new("Not Found", 404)
|
73
|
+
end
|
74
|
+
|
66
75
|
private
|
67
76
|
def load_avatar(service, id)
|
68
77
|
# titleize the service name
|
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: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash: -
|
139
|
+
hash: -4225642886398576553
|
140
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
141
|
none: false
|
142
142
|
requirements:
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
segments:
|
147
147
|
- 0
|
148
|
-
hash: -
|
148
|
+
hash: -4225642886398576553
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
151
|
rubygems_version: 1.8.24
|