firefly-client 0.4.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/.rvmrc +1 -0
- data/HISTORY +3 -0
- data/LICENSE +20 -0
- data/README.md +61 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/firefly-client.rb +7 -0
- data/lib/firefly/client.rb +59 -0
- data/lib/firefly_client.rb +1 -0
- data/spec/firefly-client_spec.rb +35 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +12 -0
- metadata +129 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.8.7-p249@firefly-client
|
data/HISTORY
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 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.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# FireFly Client
|
2
|
+
|
3
|
+
FireFly is a simple URL shortener for personal use. This is the client to be used in conjunction with a server installation.
|
4
|
+
|
5
|
+
See [http://github.com/ariejan/firefly][1] for details on the server.
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
sudo gem install firefly-client
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
require 'rubygems'
|
14
|
+
require 'firefly-client'
|
15
|
+
|
16
|
+
firefly = Firefly::Client.new("http://aj.gs", "my_api_key")
|
17
|
+
firefly.shorten("http://google.com") => "http://aj.gs/8ds"
|
18
|
+
|
19
|
+
# Bugs, Feature Requests, etc.
|
20
|
+
|
21
|
+
* [Source][2]
|
22
|
+
* [Issue tracker][3]
|
23
|
+
|
24
|
+
[1]: http://github.com/ariejan/firefly
|
25
|
+
[2]: http://github.com/ariejan/firefly-client
|
26
|
+
[3]: http://github.com/ariejan/firefly/issues
|
27
|
+
|
28
|
+
Feel free to fork Firefly Client and create patches for it. Here are some basic instructions:
|
29
|
+
|
30
|
+
* [Fork][4] Firefly Client
|
31
|
+
* Create a topic branch - `git checkout -b my_branch`
|
32
|
+
* Push to your branch - `git push origin my_branch`
|
33
|
+
* Create an [Issue][5] with a link to your branch
|
34
|
+
* That's it!
|
35
|
+
|
36
|
+
[4]: http://help.github.com/forking/
|
37
|
+
[5]: http://github.com/ariejan/firefly-client/issues
|
38
|
+
|
39
|
+
# License
|
40
|
+
|
41
|
+
Copyright (c) 2010 Ariejan de Vroom
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
"Software"), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
57
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
58
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
59
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
60
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
61
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "firefly-client"
|
8
|
+
gem.summary = %Q{A client for the Firefly URL shortener server}
|
9
|
+
gem.description = %Q{This is a client Gem for the Firefly URL shortener. It allows you Ruby application to call Firefly directly to shorten URLs.}
|
10
|
+
gem.email = "ariejan@ariejan.net"
|
11
|
+
gem.homepage = "http://github.com/ariejan/firefly-client"
|
12
|
+
gem.authors = ["Ariejan de Vroom"]
|
13
|
+
gem.add_dependency "httparty", ">= 0.5.2"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
gem.add_development_dependency "fakeweb", ">= 1.2.8"
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "firefly-client #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Firefly
|
2
|
+
|
3
|
+
# Firefly::Client allows you to shorten URLs quickily through a Firefly server.
|
4
|
+
#
|
5
|
+
# Usage is easy:
|
6
|
+
#
|
7
|
+
# firefly = Firefly::Client.new(url, api_key)
|
8
|
+
# firefly.shorten("http://google.com")
|
9
|
+
#
|
10
|
+
class Client
|
11
|
+
|
12
|
+
# Creates a new instance to shorten Firefly URLs
|
13
|
+
#
|
14
|
+
# +url+ is the URL to your Firefly server. E.g. "http://aj.gs".
|
15
|
+
# Note: do not include a trailing slash
|
16
|
+
# +api_key+ is your Firefly API Key.
|
17
|
+
def initialize(url, api_key)
|
18
|
+
@firefly_url = url
|
19
|
+
@api_key = api_key
|
20
|
+
end
|
21
|
+
|
22
|
+
# Shortens the given URL or array of URLs.
|
23
|
+
#
|
24
|
+
# shorten("http://google.com") => "http://aj.gs/7dZ"
|
25
|
+
#
|
26
|
+
# shorten(["http://google.com", "http://yahoo.com"])
|
27
|
+
# => { "http://google.com/" => "http://aj.gs/7dZ",
|
28
|
+
# "http://yahoo.com/" => "http://aj.gs/8Yt" }
|
29
|
+
def shorten(input)
|
30
|
+
if input.is_a?(String)
|
31
|
+
return create_url(input)
|
32
|
+
elsif input.is_a?(Array)
|
33
|
+
result = {}
|
34
|
+
input.each do |inp|
|
35
|
+
result[inp] = create_url(inp)
|
36
|
+
end
|
37
|
+
return result
|
38
|
+
else
|
39
|
+
raise ArgumentError.new('Shorten requires either a url or an array of urls')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
# Shortend +long_url+ and returns the short_url on success
|
46
|
+
def create_url(long_url)
|
47
|
+
begin
|
48
|
+
options = { :query => { :url => long_url, :api_key => @api_key } }
|
49
|
+
result = HTTParty.post(@firefly_url + '/api/add', options)
|
50
|
+
|
51
|
+
if result =~ /Permission denied/i
|
52
|
+
raise "Permission denied. Is your API Key set correctly?" if result.status = 401
|
53
|
+
else
|
54
|
+
return result
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'firefly-client'
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "FireflyClient" do
|
4
|
+
|
5
|
+
describe "successful calls" do
|
6
|
+
before(:each) do
|
7
|
+
FakeWeb.register_uri(:post, /^http:\/\/tst\.hst\/api\/add.*google\.com$/, :body => "http://tst.hst/7dX")
|
8
|
+
FakeWeb.register_uri(:post, /^http:\/\/tst\.hst\/api\/add.*yahoo\.com$/, :body => "http://tst.hst/rX9")
|
9
|
+
@client = Firefly::Client.new('http://tst.hst', 'test')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should call http://test.host/api/add correctly" do
|
13
|
+
@client.shorten("http://google.com").should eql("http://tst.hst/7dX")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should shorten multiple urls correctly" do
|
17
|
+
result = @client.shorten(["http://google.com", "http://yahoo.com"])
|
18
|
+
result["http://google.com"].should eql("http://tst.hst/7dX")
|
19
|
+
result["http://yahoo.com"].should eql("http://tst.hst/rX9")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "API permission errors" do
|
24
|
+
before(:each) do
|
25
|
+
FakeWeb.register_uri(:post, /^http:\/\/tst\.hst\/api\/add.*google\.com$/, :status => 401, :body => "Permission denied")
|
26
|
+
@client = Firefly::Client.new('http://tst.hst', 'fail')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise an error" do
|
30
|
+
lambda {
|
31
|
+
@client.shorten("http://google.com")
|
32
|
+
}.should raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'firefly-client'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
require 'fakeweb'
|
7
|
+
|
8
|
+
FakeWeb.allow_net_connect = false
|
9
|
+
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firefly-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ariejan de Vroom
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-06 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: httparty
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 5
|
33
|
+
- 2
|
34
|
+
version: 0.5.2
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 2
|
49
|
+
- 9
|
50
|
+
version: 1.2.9
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: fakeweb
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 2
|
65
|
+
- 8
|
66
|
+
version: 1.2.8
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description: This is a client Gem for the Firefly URL shortener. It allows you Ruby application to call Firefly directly to shorten URLs.
|
70
|
+
email: ariejan@ariejan.net
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
files:
|
79
|
+
- .document
|
80
|
+
- .gitignore
|
81
|
+
- .rvmrc
|
82
|
+
- HISTORY
|
83
|
+
- LICENSE
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/firefly-client.rb
|
88
|
+
- lib/firefly/client.rb
|
89
|
+
- lib/firefly_client.rb
|
90
|
+
- spec/firefly-client_spec.rb
|
91
|
+
- spec/spec.opts
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://github.com/ariejan/firefly-client
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options:
|
99
|
+
- --charset=UTF-8
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.7
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: A client for the Firefly URL shortener server
|
127
|
+
test_files:
|
128
|
+
- spec/firefly-client_spec.rb
|
129
|
+
- spec/spec_helper.rb
|