gadafi 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gadafi.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2011 by Chris Adams <wave@chrisadams.me.uk>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gadafi/cli'
4
+ Gadafi::CLI.start
5
+
@@ -0,0 +1,10 @@
1
+ Feature: Gadafi
2
+ In order to quickly shorten urls
3
+ As a CLI
4
+ I want to shorten urls on the commandline
5
+
6
+ Scenario: Gadafi gives me a short url back
7
+ When I run "gadafi http://en.wikipedia.org/wiki/URL_shortening"
8
+ Then the output should contain "http://www.gadaf.fi/1"
9
+
10
+
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gadafi/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "gadafi"
7
+ s.version = Gadafi::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Adams"]
10
+ s.email = ["wave@chrisadams.me.uk"]
11
+ s.homepage = "http://chrisdams.me.uk"
12
+ s.summary = %q{A simple wrapper for the gadaf.fi url shortening service.}
13
+ s.description = %q{This gem was written largely to get familiar with aruba, and minitest, bundler and thor when making gems with a CLI}
14
+
15
+ s.rubyforge_project = "gadafi"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.add_development_dependency "minitest"
22
+ s.add_development_dependency "cucumber"
23
+ s.add_development_dependency "aruba"
24
+ s.add_development_dependency "ruby-debug"
25
+ s.add_development_dependency "rake"
26
+ s.add_dependency "rest-client"
27
+ s.add_dependency "thor"
28
+ end
@@ -0,0 +1,23 @@
1
+ require 'thor'
2
+ require 'gadafi/gadafi'
3
+ require 'ruby-debug'
4
+
5
+ module Gadafi
6
+
7
+ class CLI < Thor
8
+
9
+ desc 'shorten', 'fetch a shortened url'
10
+ def shorten url
11
+ g = Gadafi.new
12
+ puts g.short_url url
13
+ end
14
+
15
+ def method_missing argument
16
+ shorten argument
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+
@@ -0,0 +1,12 @@
1
+ require 'rest-client'
2
+
3
+ module Gadafi
4
+
5
+ class Gadafi
6
+
7
+ def short_url url
8
+ RestClient.get("http://gadaf.fi/api.php?url=#{url}")
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Gadafi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,48 @@
1
+ # gadafi gem
2
+
3
+ This gem is a simple wrapper around the gadafi url shortening service, available at [http://gadaf.fi].
4
+
5
+ ## Installation
6
+
7
+ As with most ruby gems, just type this on the command line.
8
+
9
+ $ gem install gadafi
10
+
11
+ ## Usage
12
+
13
+ It's a pretty simple gem - just paste in the url you want to shorten, and it'll print the url for the short url to STDOUT:
14
+
15
+ $ gadafi http://en.wikipedia.org/wiki/URL_shortening # http://www.gadaf.fi/1
16
+
17
+ ## TODO / Thoughts
18
+
19
+ * I largely created it as a an exercise to help me learn how to make gems using bundler, by following along [this tutorial here][] by [radar][].
20
+ * I'm aware that this gem is a somewhat comical example of over-engineering - this could be accomplished much quicker by simply using an alias to curl for example, but the aim of this gem was learning how to make gems, rather than development minimalism :)
21
+ * It uses minitest instead of rspec for testing, but otherwise, I've tried to follow it fairly faithfully.
22
+ * I don't really expect any, but if you find this useful, I'd be happy to take feature requests, and pull requests.
23
+ * TODO use mocks with the tests to stop hitting an actual api endpoint.
24
+ * TODO use a local storage of some kind to cache already queried urls. Suggestions welcome!
25
+
26
+
27
+ # Author
28
+
29
+ * [Chris Adams][]
30
+
31
+ ## License
32
+
33
+ [MIT LICENSE][]
34
+
35
+ # Thanks
36
+
37
+ [Christoffer Bjorkskog][] - for making a cool url service in the first place
38
+ [Ryan Bigg][] (on github as [radar][]) - for making such a great guide to follow.
39
+
40
+ <!-- links -->
41
+
42
+ [Christoffer Bjorkskog]: http://toffe.wordpress.com
43
+ [Chris Adams]: http://chrisadams.me.uk
44
+ [this tutorial here]: https://github.com/radar/guides/blob/master/gem-development.md
45
+ [MIT LICENSE]: https://github.com/mrchrisadams/gadafi/blob/master/MIT-LICENSE
46
+ [Ryan Bigg]: https://github.com/radar
47
+ [radar]: https://github.com/radar
48
+
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require 'gadafi/gadafi'
3
+
4
+
5
+ describe Gadafi::Gadafi do
6
+
7
+ before do
8
+ @gadafi = Gadafi::Gadafi.new
9
+ @long_url = "http://en.wikipedia.org/wiki/URL_shortening"
10
+ @short_url = "http://www.gadaf.fi/1"
11
+ end
12
+
13
+ describe "when passed a full length valid url" do
14
+ it "must respond with a shortcode url" do
15
+ @gadafi.short_url(@long_url).must_equal @short_url
16
+ end
17
+
18
+ it "must return an okay status code" do
19
+ @gadafi.short_url(@long_url).code.must_equal 200
20
+ end
21
+
22
+ end
23
+
24
+ describe "when passed a bad url" do
25
+ it "must not return an ok status code" do
26
+ skip
27
+ @gadafi.short_url("not an url").code.wont_equal 200
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gadafi
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Chris Adams
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-14 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: minitest
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: cucumber
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: aruba
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: ruby-debug
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: rake
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: rest-client
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: thor
107
+ prerelease: false
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ type: :runtime
118
+ version_requirements: *id007
119
+ description: This gem was written largely to get familiar with aruba, and minitest, bundler and thor when making gems with a CLI
120
+ email:
121
+ - wave@chrisadams.me.uk
122
+ executables:
123
+ - gadafi
124
+ extensions: []
125
+
126
+ extra_rdoc_files: []
127
+
128
+ files:
129
+ - .gitignore
130
+ - Gemfile
131
+ - MIT-LICENSE
132
+ - Rakefile
133
+ - bin/gadafi
134
+ - features/cli_url_shortening.feature
135
+ - features/setup.rb
136
+ - gadafi.gemspec
137
+ - lib/gadafi/cli.rb
138
+ - lib/gadafi/gadafi.rb
139
+ - lib/gadafi/version.rb
140
+ - readme.md
141
+ - test/gadafi_test.rb
142
+ has_rdoc: true
143
+ homepage: http://chrisdams.me.uk
144
+ licenses: []
145
+
146
+ post_install_message:
147
+ rdoc_options: []
148
+
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ hash: 3
166
+ segments:
167
+ - 0
168
+ version: "0"
169
+ requirements: []
170
+
171
+ rubyforge_project: gadafi
172
+ rubygems_version: 1.6.2
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: A simple wrapper for the gadaf.fi url shortening service.
176
+ test_files:
177
+ - features/cli_url_shortening.feature
178
+ - features/setup.rb
179
+ - test/gadafi_test.rb