Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'social_hyves' of https://github.com/stalkert/firefly in…

…to stalkert-social_hyves
  • Loading branch information...
commit dc1e810558be5dd3588ee5d957c0286464f2472d 2 parents 326753e + eac4043
@ariejan authored
View
2  config.ru.example
@@ -25,7 +25,7 @@ app = Firefly::Server.new do
set :sharing_key, ""
# Currently only twitter is supported
- # set :sharing_targets, [:twitter]
+ # set :sharing_targets, [:twitter, :hyves]
set :sharing_targets, []
# Set the TLDs (in URLs) that are allowed to be shortened
View
12 lib/firefly/config.rb
@@ -2,11 +2,13 @@ module Firefly
class Config < Hash
DEFAULTS = {
- :hostname => "localhost:3000",
- :api_key => "test",
- :database => "sqlite3://#{Dir.pwd}/firefly_#{ENV['RACK_ENV']}.sqlite3",
- :recent_urls => 25,
- :tweet => "Check this out: %short_url%"
+ :hostname => "localhost:3000",
+ :api_key => "test",
+ :database => "sqlite3://#{Dir.pwd}/firefly_#{ENV['RACK_ENV']}.sqlite3",
+ :recent_urls => 25,
+ :tweet => "Check this out: %short_url%",
+ :hyves_title => "Check this out",
+ :hyves_body => "Check this out: %short_url%"
}
def initialize obj
View
25 lib/firefly/server.rb
@@ -104,6 +104,8 @@ def is_highlighted?(url)
end
# Format a tweet
+ #
+ # redirect(URI.escape("http://twitter.com/home?status=#{tweet("http://#{config[:hostname]}/#{@code}", params[:title])}"))
def tweet(url, message = nil)
if message.nil? || message == ""
config[:tweet].gsub('%short_url%', url)
@@ -112,6 +114,20 @@ def tweet(url, message = nil)
[message.strip.slice(0...max_length), url].join(' ')
end
end
+
+ # Format a hyves post
+ # {"http://www.hyves.nl/profielbeheer/toevoegen/tips/?name=#{name_of_titel}&text=#{tekst_met_url)}&type=12&rating=5"
+ def hyves_post(url, title = nil, body = nil)
+ if title.nil? || title == ""
+ title = config[:hyves_title]
+ end
+
+ if body.nil? || body == ""
+ body = config[:hyves_body].gsub('%short_url%', url)
+ end
+
+ return "name=#{title.strip}&text=#{body.strip}&type=12&rating=5"
+ end
def store_api_key(key)
if key == config[:api_key]
@@ -175,9 +191,12 @@ def store_api_key(key)
@code, @result = generate_short_url(@url, nil)
invalid = @code.nil?
- if params[:target].downcase.to_sym == :twitter
- redirect(URI.escape("http://twitter.com/home?status=#{tweet("http://#{config[:hostname]}/#{@code}", params[:title])}"))
- end
+ case (params[:target].downcase.to_sym)
+ when :twitter
+ redirect(URI.escape("http://twitter.com/home?status=#{tweet("http://#{config[:hostname]}/#{@code}", params[:title])}"))
+ when :hyves
+ redirect(URI.escape("http://www.hyves.nl/profielbeheer/toevoegen/tips/?#{hyves_post("http://#{config[:hostname]}/#{@code}", params[:title])}"))
+ end
}
get '/api/share', &api_share
View
98 spec/firefly/sharing_hyves_spec.rb
@@ -0,0 +1,98 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe "Sharing" do
+ include Rack::Test::Methods
+
+ def app
+ @@app
+ end
+
+ before(:each) do
+ @params = {
+ :url => 'http://example.com/test',
+ :key => 'asdfasdf',
+ :target => 'hyves',
+ :title => 'Test post'
+ }
+ end
+
+ [:post, :get].each do |verb|
+ describe "hyves" do
+ it "should create a shortened URL" do
+ lambda {
+ self.send verb, '/api/share', @params
+ }.should change(Firefly::Url, :count).by(1)
+ end
+
+ it "should redirect to hyves with status" do
+ self.send verb, '/api/share', @params
+ last_response.should be_redirect
+ last_response['Location'].should match(/hyves.nl/i)
+ end
+
+ it "should post the title to hyves" do
+ self.send verb, '/api/share', @params
+ url = Firefly::Url.first(:url => @params[:url])
+ last_response['Location'].should include(URI.escape("#{@params[:title]}"))
+ end
+
+ it "should post the title and short url to hyves" do
+ self.send verb, '/api/share', @params
+ url = Firefly::Url.first(:url => @params[:url])
+ last_response['Location'].should include(URI.escape("http://test.host/#{url.code}"))
+ end
+
+ it "should not allow sharing of example.org URL" do
+ self.send verb, '/api/share', @params.merge(:url => 'http://example.org/test123')
+ last_response.status.should eql(401)
+ last_response.body.should match(/cannot share that URL/i)
+ end
+
+ it "should not create a short URL for example.org URL" do
+ lambda {
+ self.send verb, '/api/share', @params.merge(:url => 'http://example.org/test123')
+ }.should_not change(Firefly::Url, :count)
+ end
+
+ it "should not share to other social network" do
+ self.send verb, '/api/share', @params.merge(:target => 'other')
+ last_response.status.should eql(401)
+ last_response.body.should match(/cannot share that URL/i)
+ end
+
+ it "should not create a short URL for other social network" do
+ lambda {
+ self.send verb, '/api/share', @params.merge(:target => 'other')
+ }.should_not change(Firefly::Url, :count)
+ end
+
+ it "should strip the title to remove any unnecessary white space" do
+ title = " Test post "
+ self.send verb, '/api/share', @params.merge(:title => title)
+ url = Firefly::Url.first(:url => @params[:url])
+
+ last_response['Location'].should include(URI.escape("Test post"))
+ last_response['Location'].should_not include(URI.escape(title))
+ end
+
+ it "should strip the body to remove any unnecessary white space" do
+ title = " This is the test body "
+ self.send verb, '/api/share', @params.merge(:title => title)
+ url = Firefly::Url.first(:url => @params[:url])
+
+ last_response['Location'].should include(URI.escape("http://test.host/#{url.code}"))
+ last_response['Location'].should_not include(URI.escape(title))
+ end
+
+
+ it "should escape UTF-8 correctly" do
+ title = "Chávez"
+ self.send verb, '/api/share', @params.merge(:title => title)
+ url = Firefly::Url.first(:url => @params[:url])
+
+ last_response['Location'].should include("Ch%C3%A1vez")
+ last_response['Location'].should_not include("Ch%E1vez")
+ end
+ end
+ end
+end
View
0  spec/firefly/sharing_spec.rb → spec/firefly/sharing_twitter_spec.rb
File renamed without changes
View
2  spec/spec_helper.rb
@@ -22,7 +22,7 @@
set :database, "mysql://root@localhost/firefly_test"
set :sharing_key, "asdfasdf"
- set :sharing_targets, [:twitter]
+ set :sharing_targets, [:twitter, :hyves]
set :sharing_domains, ["example.com", "example.net"]
end
Please sign in to comment.
Something went wrong with that request. Please try again.