social-avatar-proxy 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.md +11 -9
- data/config.ru +7 -0
- data/lib/social_avatar_proxy.rb +5 -1
- data/lib/social_avatar_proxy/app.rb +0 -4
- data/lib/social_avatar_proxy/engine.rb +36 -0
- data/lib/social_avatar_proxy/version.rb +1 -1
- data/social-avatar-proxy.gemspec +2 -1
- data/spec/internal/config/routes.rb +5 -0
- data/spec/social_avatar_proxy/app_spec.rb +0 -9
- data/spec/social_avatar_proxy/engine_spec.rb +30 -0
- data/spec/spec_helper.rb +5 -0
- metadata +26 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -25,32 +25,34 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
|
28
|
+
# Rack
|
29
|
+
|
30
|
+
The Rack app is available at: SocialAvatarProxy::App
|
31
|
+
|
32
|
+
# Rails
|
29
33
|
|
30
34
|
In your `config/routes.rb` file:
|
31
35
|
|
32
36
|
```ruby
|
33
|
-
mount SocialAvatarProxy::
|
37
|
+
mount SocialAvatarProxy::Engine, at: "/avatars"
|
34
38
|
```
|
35
39
|
|
36
|
-
|
40
|
+
The engine is basically a proxy for the Rack app, it also adds the path helpers below:
|
37
41
|
|
38
42
|
In your views:
|
39
43
|
|
40
44
|
```ruby
|
41
45
|
# for a Twitter user, by username:
|
42
|
-
image_tag(
|
46
|
+
image_tag(twitter_avatar_path("username"))
|
43
47
|
# by ID:
|
44
|
-
image_tag(
|
48
|
+
image_tag(twitter_avatar_path(12345))
|
45
49
|
|
46
50
|
# for a Facebook user, by username:
|
47
|
-
image_tag(
|
51
|
+
image_tag(facebook_avatar_path("username"))
|
48
52
|
# by ID:
|
49
|
-
image_tag(
|
53
|
+
image_tag(facebook_avatar_path(12345))
|
50
54
|
```
|
51
55
|
|
52
|
-
The above path helper methods are provided by the `SocialAvatarProxy::PathHelpers` module. Note: `image_tag` is a Rails helper, replace with your framework's equivalent. You'll need to call `avatar_base_path=` with the mounted path prefix (in the example above we were mounted at `/avatars`, however Rails handles it automatically)
|
53
|
-
|
54
56
|
## Contributing
|
55
57
|
|
56
58
|
1. Fork it
|
data/config.ru
ADDED
data/lib/social_avatar_proxy.rb
CHANGED
@@ -2,4 +2,8 @@ require "social_avatar_proxy/version"
|
|
2
2
|
require "social_avatar_proxy/app"
|
3
3
|
require "social_avatar_proxy/avatar"
|
4
4
|
require "social_avatar_proxy/facebook_avatar"
|
5
|
-
require "social_avatar_proxy/twitter_avatar"
|
5
|
+
require "social_avatar_proxy/twitter_avatar"
|
6
|
+
|
7
|
+
if defined?(Rails) && defined?(Rails::Engine)
|
8
|
+
require "social_avatar_proxy/engine"
|
9
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "social_avatar_proxy/app"
|
2
|
+
require "social_avatar_proxy/path_helpers"
|
3
|
+
|
4
|
+
module SocialAvatarProxy
|
5
|
+
class Engine < ::Rails::Engine
|
6
|
+
endpoint App
|
7
|
+
|
8
|
+
def self.mounted_at
|
9
|
+
@mounted_at ||= calculate_mounted_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.calculate_mounted_at
|
13
|
+
route ||= Rails.application.routes.routes.detect do |route|
|
14
|
+
route.app == self
|
15
|
+
end
|
16
|
+
# if it's not found, it's not mounted
|
17
|
+
unless route
|
18
|
+
raise "#{self} is not yet mounted."
|
19
|
+
end
|
20
|
+
# return the route with it's slashes stripped
|
21
|
+
route.path.spec.to_s.gsub(/^\/|\/$/, "")
|
22
|
+
end
|
23
|
+
|
24
|
+
module Helpers
|
25
|
+
def twitter_avatar_path(identifier)
|
26
|
+
"/#{SocialAvatarProxy::Engine.mounted_at}/twitter/#{identifier}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def facebook_avatar_path(identifier)
|
30
|
+
"/#{SocialAvatarProxy::Engine.mounted_at}/facebook/#{identifier}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
ActionController::Base.send(:include, Helpers)
|
35
|
+
end
|
36
|
+
end
|
data/social-avatar-proxy.gemspec
CHANGED
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.add_dependency "rack"
|
23
23
|
|
24
|
+
s.add_development_dependency "combustion"
|
24
25
|
s.add_development_dependency "rake"
|
25
|
-
s.add_development_dependency "rspec"
|
26
|
+
s.add_development_dependency "rspec-rails"
|
26
27
|
s.add_development_dependency "simplecov"
|
27
28
|
s.add_development_dependency "foreman"
|
28
29
|
end
|
@@ -37,15 +37,6 @@ describe SocialAvatarProxy::App do
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
describe "#routes" do
|
41
|
-
subject { app }
|
42
|
-
|
43
|
-
it "should return a object providing the path helpers" do
|
44
|
-
expect(subject.routes.facebook_avatar_path("ryandtownsned")).to match(/^\/.*$/)
|
45
|
-
expect(subject.routes.twitter_avatar_path(2202971)).to match(/^\/.*$/)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
40
|
context "given an invalid path" do
|
50
41
|
it "should return a 404 response" do
|
51
42
|
path = "/unknown"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "social_avatar_proxy/engine"
|
3
|
+
|
4
|
+
describe SocialAvatarProxy::Engine do
|
5
|
+
subject do
|
6
|
+
SocialAvatarProxy::Engine
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#mounted_at" do
|
10
|
+
it "should match what is in the routes file" do
|
11
|
+
expect(subject.mounted_at).to eq("avatars/test")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "routing" do
|
16
|
+
subject do
|
17
|
+
ActionController::Base.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should define #twitter_avatar_path on ApplicationController" do
|
21
|
+
path = subject.twitter_avatar_path("ryantownsend")
|
22
|
+
expect(path).to eq "/avatars/test/twitter/ryantownsend"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should define #facebook_avatar_path on ApplicationController" do
|
26
|
+
path = subject.facebook_avatar_path("ryandtownsend")
|
27
|
+
expect(path).to eq "/avatars/test/facebook/ryandtownsend"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: combustion
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,7 +60,7 @@ dependencies:
|
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
46
62
|
- !ruby/object:Gem::Dependency
|
47
|
-
name: rspec
|
63
|
+
name: rspec-rails
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
49
65
|
none: false
|
50
66
|
requirements:
|
@@ -105,10 +121,12 @@ files:
|
|
105
121
|
- LICENSE.txt
|
106
122
|
- README.md
|
107
123
|
- Rakefile
|
124
|
+
- config.ru
|
108
125
|
- lib/social-avatar-proxy.rb
|
109
126
|
- lib/social_avatar_proxy.rb
|
110
127
|
- lib/social_avatar_proxy/app.rb
|
111
128
|
- lib/social_avatar_proxy/avatar.rb
|
129
|
+
- lib/social_avatar_proxy/engine.rb
|
112
130
|
- lib/social_avatar_proxy/facebook_avatar.rb
|
113
131
|
- lib/social_avatar_proxy/path_helpers.rb
|
114
132
|
- lib/social_avatar_proxy/remote_file_resolver.rb
|
@@ -116,8 +134,10 @@ files:
|
|
116
134
|
- lib/social_avatar_proxy/twitter_avatar.rb
|
117
135
|
- lib/social_avatar_proxy/version.rb
|
118
136
|
- social-avatar-proxy.gemspec
|
137
|
+
- spec/internal/config/routes.rb
|
119
138
|
- spec/social_avatar_proxy/app_spec.rb
|
120
139
|
- spec/social_avatar_proxy/avatar_spec.rb
|
140
|
+
- spec/social_avatar_proxy/engine_spec.rb
|
121
141
|
- spec/social_avatar_proxy/facebook_avatar_spec.rb
|
122
142
|
- spec/social_avatar_proxy/path_helpers_spec.rb
|
123
143
|
- spec/social_avatar_proxy/remote_file_resolver_spec.rb
|
@@ -140,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
160
|
version: '0'
|
141
161
|
segments:
|
142
162
|
- 0
|
143
|
-
hash: -
|
163
|
+
hash: -3423004338528291902
|
144
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
165
|
none: false
|
146
166
|
requirements:
|
@@ -149,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
169
|
version: '0'
|
150
170
|
segments:
|
151
171
|
- 0
|
152
|
-
hash: -
|
172
|
+
hash: -3423004338528291902
|
153
173
|
requirements: []
|
154
174
|
rubyforge_project:
|
155
175
|
rubygems_version: 1.8.24
|
@@ -157,8 +177,10 @@ signing_key:
|
|
157
177
|
specification_version: 3
|
158
178
|
summary: This gem acts as a proxy for avatars on Twitter & Facebook.
|
159
179
|
test_files:
|
180
|
+
- spec/internal/config/routes.rb
|
160
181
|
- spec/social_avatar_proxy/app_spec.rb
|
161
182
|
- spec/social_avatar_proxy/avatar_spec.rb
|
183
|
+
- spec/social_avatar_proxy/engine_spec.rb
|
162
184
|
- spec/social_avatar_proxy/facebook_avatar_spec.rb
|
163
185
|
- spec/social_avatar_proxy/path_helpers_spec.rb
|
164
186
|
- spec/social_avatar_proxy/remote_file_resolver_spec.rb
|