link_shrink 0.0.4 → 0.0.5

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/Changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # LinkShrink Changelog
2
2
 
3
+ ## 0.0.5
4
+
5
+ Released September 7, 2013 ([0.0.5](https://github.com/jonahoffline/link_shrink/tree/v0.0.5)).
6
+
7
+ * Add Is.gd Shrinker
8
+ * Add option for selecting Is.gd Shrinker in command-line application.
9
+ * Update version to 0.0.5
10
+
3
11
  ## 0.0.4
4
12
 
5
13
  Released September 6, 2013 ([0.0.4](https://github.com/jonahoffline/link_shrink/tree/v0.0.4)).
data/README.md CHANGED
@@ -3,6 +3,13 @@
3
3
 
4
4
  A Ruby Gem and Command-Line Application for shrinking those long and nasty links into a shorter URL
5
5
 
6
+ ## Supported Url Shortener APIs
7
+
8
+ * Google
9
+ * TinyUrl
10
+ * IsGd
11
+ * **More to come...**
12
+
6
13
  Installation
7
14
  ---------------------
8
15
 
@@ -63,7 +70,7 @@ end
63
70
 
64
71
  # or
65
72
 
66
- LinkShrink::Config.api = 'TinyUrl'
73
+ LinkShrink::Config.api = 'IsGd'
67
74
 
68
75
  LinkShrink.shrink_url('http://www.google.com')
69
76
  => "http://tinyurl.com/1c2"
@@ -79,10 +86,18 @@ In your terminal:
79
86
  $ linkshrink --tinyurl http://www.rubyrogues.com
80
87
  http://tinyurl.com/k2butj9
81
88
 
89
+ $ linkshrink --isgd http://www.rubyrogues.com
90
+ http://is.gd/6ZNRWe
82
91
  ### Command-Line Options ###
83
92
 
93
+ Shrinkers:
94
+
84
95
  * -t, --tinyurl - use TinyUrl API
85
- * -g, --google - use Google API (Default)
96
+ * -i, --isgd - use Is.gd API
97
+ * -g, --google - use Google API (Default)
98
+
99
+ Format and additional options:
100
+
86
101
  * -j, --json - return JSON response
87
102
  * -q, --qrcode - return QR Code
88
103
  * -h, --help - show help message
@@ -18,6 +18,7 @@ module LinkShrink
18
18
  @qr_code = false
19
19
  @tiny_url = false
20
20
  @google = false
21
+ @is_gd = false
21
22
  opts.version = LinkShrink::VERSION
22
23
  opts.banner = <<MSG
23
24
  Usage: link_shrink [OPTION] [URL]
@@ -31,6 +32,10 @@ MSG
31
32
  @tiny_url = :true
32
33
  end
33
34
 
35
+ opts.on_head('-i', '--isgd', 'use Is.gd') do
36
+ @is_gd = :true
37
+ end
38
+
34
39
  opts.on_head('-g', '--google', 'use Google (Default)') do
35
40
  @google = :true
36
41
  end
@@ -64,12 +69,24 @@ MSG
64
69
  end
65
70
 
66
71
  def process_url
67
- LinkShrink.configure { |c| c.api = 'TinyUrl' } if @tiny_url
72
+ api = select_api
73
+ LinkShrink.configure { |c| c.api = api }
68
74
  LinkShrink.shrink_url(@args.last, { json: @json, qr_code: @qr_code })
69
75
  end
70
76
 
71
77
  def url_present?
72
78
  !!(@args.last =~ /^(http?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/)
73
79
  end
80
+
81
+ def select_api
82
+ case
83
+ when @tiny_url
84
+ 'TinyUrl'
85
+ when @is_gd
86
+ 'IsGd'
87
+ else
88
+ 'Google'
89
+ end
90
+ end
74
91
  end
75
92
  end
@@ -0,0 +1,31 @@
1
+ module LinkShrink
2
+ module Shrinkers
3
+ # @author Jonah Ruiz <jonah@pixelhipsters.com>
4
+ # Implements Is.gd Shortener API
5
+ class IsGd < Base
6
+ # Returns URL base for API
7
+ # @return [String] api base url
8
+ def base_url
9
+ 'http://is.gd/create.php'
10
+ end
11
+
12
+ # URL query parameters
13
+ # @return [String] query parameters to be used in request
14
+ def api_query_parameter
15
+ "?format=simple&url=#{url}"
16
+ end
17
+
18
+ # Returns Content-Type to be used in Request headers
19
+ # @return [String] text/plain as content-type
20
+ def content_type
21
+ 'text/plain'
22
+ end
23
+
24
+ # Returns full api url
25
+ # @return [String] full api url with query parameters
26
+ def api_url
27
+ base_url.concat api_query_parameter
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module LinkShrink
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/link_shrink.rb CHANGED
@@ -5,6 +5,7 @@ require 'link_shrink/json_parser'
5
5
  require 'link_shrink/shrinkers/base'
6
6
  require 'link_shrink/shrinkers/google'
7
7
  require 'link_shrink/shrinkers/tinyurl'
8
+ require 'link_shrink/shrinkers/isgd'
8
9
  require 'link_shrink/config'
9
10
 
10
11
  # @author Jonah Ruiz <jonah@pixelhipsters.com>
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe LinkShrink::Shrinkers::IsGd do
4
+ include_examples 'shared_examples'
5
+
6
+ let(:link_shrink) { described_class.new }
7
+ let(:is_gd) { 'http://is.gd/create.php' }
8
+
9
+ describe '#sub_klass' do
10
+ it 'returns the inherited subclass name' do
11
+ expect(link_shrink.sub_klass).to eq('IsGd')
12
+ end
13
+ end
14
+
15
+ describe '#base_url' do
16
+ it 'returns the base_url for the API' do
17
+ expect(link_shrink.base_url)
18
+ .to eq(is_gd)
19
+ end
20
+ end
21
+
22
+ describe '#api_url' do
23
+ it 'returns full api url' do
24
+ link_shrink.stub(:url).and_return('www.google.com')
25
+
26
+ expect(link_shrink.api_url)
27
+ .to eq('http://is.gd/create.php?format=simple&url=www.google.com')
28
+ end
29
+ end
30
+
31
+ describe '#api_query_parameter' do
32
+ it 'returns query parameter' do
33
+ link_shrink.stub(:url).and_return('www.google.com')
34
+ expect(link_shrink.api_query_parameter).to eq('?format=simple&url=www.google.com')
35
+ end
36
+ end
37
+
38
+ describe '#content_type' do
39
+ it 'returns text/plain' do
40
+ expect(link_shrink.content_type).to eq('text/plain')
41
+ end
42
+ end
43
+ end
@@ -60,11 +60,12 @@ describe LinkShrink::Request do
60
60
  describe '#parse' do
61
61
  context 'when response is text/plain' do
62
62
  it 'returns response' do
63
- LinkShrink.configure { |c| c.api = 'TinyUrl'}
63
+ LinkShrink.configure { |c| c.api = 'TinyUrl' }
64
64
  response = link_shrink.request(url, shrinker).body
65
65
 
66
66
  expect(link_shrink.parse(response, {json: false}, shrinker))
67
67
  .to eq('http://tinyurl.com/1c2')
68
+ LinkShrink.configure { |c| c.api = 'Google' }
68
69
  end
69
70
  end
70
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: link_shrink
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-06 00:00:00.000000000 Z
12
+ date: 2013-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -183,6 +183,7 @@ files:
183
183
  - lib/link_shrink/request.rb
184
184
  - lib/link_shrink/shrinkers/base.rb
185
185
  - lib/link_shrink/shrinkers/google.rb
186
+ - lib/link_shrink/shrinkers/isgd.rb
186
187
  - lib/link_shrink/shrinkers/tinyurl.rb
187
188
  - lib/link_shrink/version.rb
188
189
  - link_shrink.gemspec
@@ -191,6 +192,7 @@ files:
191
192
  - spec/fixtures/response_qr_code_custom.json
192
193
  - spec/link_shrink/config_spec.rb
193
194
  - spec/link_shrink/google_spec.rb
195
+ - spec/link_shrink/isgd_spec.rb
194
196
  - spec/link_shrink/json_parser_spec.rb
195
197
  - spec/link_shrink/link_shrink_spec.rb
196
198
  - spec/link_shrink/options_spec.rb
@@ -230,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
232
  version: '0'
231
233
  segments:
232
234
  - 0
233
- hash: 1243110028426905467
235
+ hash: -545326906188575545
234
236
  requirements: []
235
237
  rubyforge_project:
236
238
  rubygems_version: 1.8.25
@@ -243,6 +245,7 @@ test_files:
243
245
  - spec/fixtures/response_qr_code_custom.json
244
246
  - spec/link_shrink/config_spec.rb
245
247
  - spec/link_shrink/google_spec.rb
248
+ - spec/link_shrink/isgd_spec.rb
246
249
  - spec/link_shrink/json_parser_spec.rb
247
250
  - spec/link_shrink/link_shrink_spec.rb
248
251
  - spec/link_shrink/options_spec.rb