tg-firefly 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ *.sqlite3
2
+ *.sqlite3-journal
3
+ sinatra.log
4
+ config.ru
5
+ pkg
6
+ .rvmrc
7
+ *.swp
8
+ _site
9
+ _site/*
10
+ log/
11
+ log/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format progress --colour
@@ -0,0 +1,5 @@
1
+ script: rake spec
2
+ rvm:
3
+ - 1.8.7
4
+ - ree
5
+
data/Gemfile ADDED
@@ -0,0 +1,26 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in firefly.gemspec
4
+ gemspec
5
+
6
+ #gem "sinatra", "~> 1.3.2"
7
+ #gem "sinatra-contrib", "~> 1.3.1"
8
+ #gem "dm-core", "~> 1.2.0"
9
+ #gem "dm-migrations", "~> 1.2.0"
10
+ #gem "dm-transactions", "~> 1.2.0"
11
+ #gem "dm-aggregates", "~> 1.2.0"
12
+ #gem "dm-mysql-adapter", "~> 1.2.0"
13
+ #gem "haml", "~> 3.1.4"
14
+ #gem "escape_utils", "~> 0.2.4"
15
+ #gem "thin"
16
+
17
+ #group :development do
18
+ # gem "pry"
19
+ #end
20
+
21
+ #group :test do
22
+ # gem "rspec", "~> 2.8.0"
23
+ # gem "rack-test", "~> 0.6.1"
24
+ # gem "dm-sqlite-adapter", "~> 1.2.0"
25
+ # gem "database_cleaner", "~> 0.7.1"
26
+ #end
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ firefly (1.5.3)
5
+ dm-aggregates (~> 1.2.0)
6
+ dm-core (~> 1.2.0)
7
+ dm-migrations (~> 1.2.0)
8
+ dm-mysql-adapter (~> 1.2.0)
9
+ dm-transactions (~> 1.2.0)
10
+ escape_utils (~> 0.2.4)
11
+ haml (~> 3.1.4)
12
+ sinatra (~> 1.3.2)
13
+ sinatra-contrib (~> 1.3.1)
14
+ thin
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ addressable (2.2.8)
20
+ backports (2.6.1)
21
+ daemons (1.1.8)
22
+ data_objects (0.10.8)
23
+ addressable (~> 2.1)
24
+ database_cleaner (0.7.2)
25
+ diff-lcs (1.1.3)
26
+ dm-aggregates (1.2.0)
27
+ dm-core (~> 1.2.0)
28
+ dm-core (1.2.0)
29
+ addressable (~> 2.2.6)
30
+ dm-do-adapter (1.2.0)
31
+ data_objects (~> 0.10.6)
32
+ dm-core (~> 1.2.0)
33
+ dm-migrations (1.2.0)
34
+ dm-core (~> 1.2.0)
35
+ dm-mysql-adapter (1.2.0)
36
+ dm-do-adapter (~> 1.2.0)
37
+ do_mysql (~> 0.10.6)
38
+ dm-sqlite-adapter (1.2.0)
39
+ dm-do-adapter (~> 1.2.0)
40
+ do_sqlite3 (~> 0.10.6)
41
+ dm-transactions (1.2.0)
42
+ dm-core (~> 1.2.0)
43
+ do_mysql (0.10.8)
44
+ data_objects (= 0.10.8)
45
+ do_sqlite3 (0.10.8)
46
+ data_objects (= 0.10.8)
47
+ escape_utils (0.2.4)
48
+ eventmachine (0.12.10)
49
+ haml (3.1.6)
50
+ rack (1.4.1)
51
+ rack-protection (1.2.0)
52
+ rack
53
+ rack-test (0.6.1)
54
+ rack (>= 1.0)
55
+ rspec (2.8.0)
56
+ rspec-core (~> 2.8.0)
57
+ rspec-expectations (~> 2.8.0)
58
+ rspec-mocks (~> 2.8.0)
59
+ rspec-core (2.8.0)
60
+ rspec-expectations (2.8.0)
61
+ diff-lcs (~> 1.1.2)
62
+ rspec-mocks (2.8.0)
63
+ sinatra (1.3.2)
64
+ rack (~> 1.3, >= 1.3.6)
65
+ rack-protection (~> 1.2)
66
+ tilt (~> 1.3, >= 1.3.3)
67
+ sinatra-contrib (1.3.1)
68
+ backports (>= 2.0)
69
+ eventmachine
70
+ rack-protection
71
+ rack-test
72
+ sinatra (~> 1.3.0)
73
+ tilt (~> 1.3)
74
+ thin (1.3.1)
75
+ daemons (>= 1.0.9)
76
+ eventmachine (>= 0.12.6)
77
+ rack (>= 1.0.0)
78
+ tilt (1.3.3)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ database_cleaner (~> 0.7.1)
85
+ dm-sqlite-adapter (~> 1.2.0)
86
+ firefly!
87
+ rack-test (~> 0.6.1)
88
+ rspec (~> 2.8.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2012 Ariejan de Vroom
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,178 @@
1
+ # Firefly [![Build Status](http://travis-ci.org/ariejan/firefly.png)](http://travis-ci.org/ariejan/firefly)
2
+
3
+ Firefly is a URL-shortener app built using Sinatra. It can be easily hosted on Heroku and other platforms.
4
+
5
+ # Installation
6
+
7
+ sudo gem install firefly
8
+
9
+ After you have installed the Firefly gem you should create a `config.ru` file that tells your webserver what to do. Here is a sample `config.ru`:
10
+
11
+ require 'rubygems'
12
+ require 'firefly'
13
+
14
+ disable :run
15
+
16
+ app = Firefly::Server.new do
17
+ # The domain you use for shortening.
18
+ set :hostname, "localhost:9393"
19
+ # set :hostname, "aj.gs"
20
+
21
+ # Used for authenticating you.
22
+ set :api_key, "changeme"
23
+
24
+ # Default MySQL:
25
+ set :database, "mysql://root:password@localhost/firefly"
26
+
27
+ # Use Sqlite3: gem install dm-sqlite-adapter
28
+ # set :database, "sqlite3://#{Dir.pwd}/firefly.sqlite3"
29
+
30
+ # Set the number of recent urls to show in the overview.
31
+ # Defaults to 25
32
+ # set :recent_urls, 10
33
+
34
+ # Set the tweet template.
35
+ # The tag %short_url% will be replaced with the actual url.
36
+ #
37
+ # Default: Check this out: %short_url%
38
+ # set :tweet, "I loved this: %short_url% - Go check it out now!"
39
+
40
+ # If you want to enable 'share to sharing targets'
41
+
42
+ # A secure key to be used with 'share to sharing targets'
43
+ # set :sharing_key, "set-a-long-secure-key-here"
44
+
45
+ # Currently only twitter, hyves and facebook are supported
46
+ # set :sharing_targets, [:twitter, :hyves, :facebook]
47
+
48
+ # Set the TLDs (in URLs) that are allowed to be shortened
49
+ # set :sharing_domains, ["example.com", "mydomain.com"]
50
+
51
+ # Set your session secret here.
52
+ # If you're unsure what to use, open IRB console and run `'%x' % rand(2**255)`
53
+ set :session_secret, "change-me"
54
+ end
55
+
56
+ run app
57
+
58
+ Next you can start your web server. You may try thin:
59
+
60
+ thin start -R config.ru
61
+
62
+ Now visit `http://:hostname/` and enter your `:api_key`. Happy URL shortening!
63
+
64
+ # Configuration
65
+
66
+ All configuration is done in `config.ru`.
67
+
68
+ * `:hostname` sets the hostname to use for shortened URLs.
69
+ * `:api_key` sets the API key. This key is required when posting new URLs
70
+ * `:database` a database URI that [DataMapper][4] can understand.
71
+ * `:recent_urls` sets the number of URLs to show in the overview. Default: 25.
72
+ * `:tweet` set the template to use for tweets. Default: `"Check this out: %short_url%"`
73
+ * `:sharing_key` set this to something long and secure, used for
74
+ creating 'share to sharing targets' links.
75
+ * `:sharing_targets` set to `[:twitter, :hyves, :facebook]` if you want to enable sharing
76
+ to twitter, hyves or facebook
77
+ * `:sharing_domains` set to an array of TLDs. Only urls shared in those
78
+ domains will be allowed. Set to an empty array (`[]`) if you want to
79
+ accept all domains.
80
+
81
+ It's possible to use all kinds of backends with DataMapper. Sqlite3 and MySQL have been tested, but others may work as well.
82
+
83
+ # Usage
84
+
85
+ Simply visit `http://:hostname/` and enter your `:api_key`. You can now shorten URLs.
86
+
87
+ ## Using the API
88
+
89
+ You may also use the API to automate URL shortening. Here's how.
90
+
91
+ Adding a URL is done by doing a simple POST request that includes the URL and your API key.
92
+
93
+ curl -d "url=http://ariejan.net" -d "api_key=test" http://localhost:3000/api/add
94
+
95
+ If you're on a MacOSX you could add the following function to your `~/.profile` to automate URL shortening:
96
+
97
+ shorten(){
98
+ URL=$1
99
+ SHORT_URL=`curl -s -d "url=$URL&api_key=test" http://localhost:3000/api/add`
100
+ echo $SHORT_URL | pbcopy
101
+
102
+ echo "-- $URL => $SHORT_URL"
103
+ echo "Short URL copied to clipboard."
104
+ }
105
+
106
+ After you restart Terminal.app (or at least reload the `.profile` file) you can use it like this:
107
+
108
+ $ shorten http://ariejan.net
109
+ -- http://ariejan.net => http://aj.gs/1
110
+ Short URL copied to clipboard.
111
+
112
+ ## Using the social features (Twitter, Facebook, etc.)
113
+
114
+ The share to sharing targets feature allows you to create custom links on your
115
+ site. When clicked, the specified URL will be shortened and the user
116
+ will be redirect to Twitter to share the new short URL.
117
+
118
+ GET /api/share
119
+ POST /api/share
120
+
121
+ Parameters:
122
+ url - Long URL to share (required)
123
+ key - The sharing key, specified in `config.ru` (required)
124
+ target - Target to share to. E.g. `twitter` or `facebook` (required)
125
+ title - Title of text to use in the tweet (optional)
126
+
127
+ # Bugs, Feature Requests, etc.
128
+
129
+ * [Source][5]
130
+ * [Issue tracker][6]
131
+
132
+ Feel free to fork Firefly and create patches for it. Here are some basic instructions:
133
+
134
+ * [Fork][7] Firefly
135
+ * Create a topic branch - `git checkout -b my_branch`
136
+ * Write tests and code
137
+ * Push to your branch - `git push origin my_branch`
138
+ * Create a GitHub Pull Request so I can merge your changes
139
+ * That's it!
140
+
141
+ [1]: http://ariejan.net/2010/07/12/screencast-firefly-url-shortener-in-less-than-25-minutes/
142
+ [2]: http://ariejan.net/2010/06/06/setup-your-own-firefly-url-shortener-in-25-minutes/
143
+ [3]: http://heroku.com
144
+ [4]: http://datamapper.org/
145
+ [5]: http://github.com/ariejan/firefly
146
+ [6]: http://github.com/ariejan/firefly/issues
147
+ [7]: http://help.github.com/forking/
148
+ [8]: http://github.com/ariejan/firefly/issues
149
+
150
+ # Contributors
151
+
152
+ * Ariejan de Vroom - Original author
153
+ * Matthew Boeh - Contributor
154
+ * Joost Saanen - Contributor
155
+
156
+ # License
157
+
158
+ Copyright (c) 2009 Ariejan de Vroom
159
+
160
+ Permission is hereby granted, free of charge, to any person obtaining
161
+ a copy of this software and associated documentation files (the
162
+ "Software"), to deal in the Software without restriction, including
163
+ without limitation the rights to use, copy, modify, merge, publish,
164
+ distribute, sublicense, and/or sell copies of the Software, and to
165
+ permit persons to whom the Software is furnished to do so, subject to
166
+ the following conditions:
167
+
168
+ The above copyright notice and this permission notice shall be
169
+ included in all copies or substantial portions of the Software.
170
+
171
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
172
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
173
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
174
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
175
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
176
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
177
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
178
+
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require './lib/firefly'
3
+
4
+ disable :run
5
+
6
+ app = Firefly::Server.new do
7
+ set :hostname, "localhost:3000"
8
+ set :api_key, "test"
9
+
10
+ # Order urls random or sequential
11
+ set :order, :sequential
12
+
13
+ # Use Sqlite3 by default
14
+ set :database, "sqlite3://#{Dir.pwd}/firefly.sqlite3"
15
+
16
+ # Set number of recent urls to show
17
+ set :recent_urls, 10
18
+
19
+ # You can use MySQL as well.
20
+ # Make sure to install the do_mysql gem:
21
+ # sudo gem install do_mysql
22
+ # set :database, "mysql://root@localhost/firefly"
23
+
24
+ # If you want to enable 'share to twitter'
25
+
26
+ # A secure key to be used with 'share to twitter'
27
+ # set :sharing_key, "set-a-long-secure-key-here"
28
+ set :sharing_key, ""
29
+
30
+ # Currently only twitter is supported
31
+ # set :sharing_targets, [:twitter, :hyves, :facebook]
32
+ set :sharing_targets, []
33
+
34
+ # Set the TLDs (in URLs) that are allowed to be shortened
35
+ # set :sharing_domains, ["example.com", "mydomain.com"]
36
+ set :sharing_domain, []
37
+
38
+ # Set your session secret here.
39
+ # If you're unsure what to use, open IRB console and run `'%x' % rand(2**255)`
40
+ set :session_secret, "change-me"
41
+ end
42
+
43
+ run app
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/firefly/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Luke Wendling"]
6
+ gem.email = ["luke@example.com"]
7
+ gem.description = %q{A URL shortener forked from ariejan/firefly project. Adds user context to click tracking}
8
+ gem.summary = %q{A URL shortener with user tracking}
9
+ gem.homepage = "https://github.com/lukewendling/firefly"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "tg-firefly"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Firefly::VERSION
17
+ gem.add_dependency "sinatra", "~> 1.3.2"
18
+ gem.add_dependency "sinatra-contrib", "~> 1.3.1"
19
+ gem.add_dependency "dm-core", "~> 1.2.0"
20
+ gem.add_dependency "dm-migrations", "~> 1.2.0"
21
+ gem.add_dependency "dm-transactions", "~> 1.2.0"
22
+ gem.add_dependency "dm-aggregates", "~> 1.2.0"
23
+ gem.add_dependency "dm-mysql-adapter", "~> 1.2.0"
24
+ gem.add_dependency "haml", "~> 3.1.4"
25
+ gem.add_dependency "escape_utils", "~> 0.2.4"
26
+ gem.add_dependency "thin"
27
+ gem.add_development_dependency "rspec", "~> 2.8.0"
28
+ gem.add_development_dependency "rack-test", "~> 0.6.1"
29
+ gem.add_development_dependency "dm-sqlite-adapter", "~> 1.2.0"
30
+ gem.add_development_dependency "database_cleaner", "~> 0.7.1"
31
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'open-uri'
4
+ require 'cgi'
5
+ require 'yaml'
6
+ require 'sinatra'
7
+ require 'dm-core'
8
+ require 'dm-migrations'
9
+ require 'dm-transactions'
10
+ require 'dm-aggregates'
11
+
12
+ require 'escape_utils'
13
+ require 'escape_utils/url/rack'
14
+
15
+ $:.unshift(File.dirname(__FILE__)) unless
16
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
17
+
18
+ if ENV['RACK_ENV'] == 'development'
19
+ DataMapper::Logger.new($stdout, :debug)
20
+ end
21
+
22
+ module Firefly
23
+ # Get the current environment
24
+ def self.environment
25
+ ENV['RACK_ENV'] || "development"
26
+ end
27
+ end
28
+
29
+ require 'firefly/config'
30
+ require 'firefly/version'
31
+ require 'firefly/base62'
32
+ require 'firefly/code_factory'
33
+ require 'firefly/url'
34
+ require 'firefly/click'
35
+ require 'firefly/share'
36
+ require 'firefly/server'