link_shrink 0.0.7 → 0.0.8
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/.travis.yml +2 -0
- data/Changelog.md +7 -0
- data/README.md +9 -3
- data/lib/link_shrink.rb +1 -0
- data/lib/link_shrink/shrinkers/karmacracy.rb +47 -0
- data/lib/link_shrink/version.rb +1 -1
- data/spec/link_shrink/shrinkers/karmacracy_spec.rb +75 -0
- metadata +5 -2
data/.travis.yml
CHANGED
@@ -16,3 +16,5 @@ env:
|
|
16
16
|
global:
|
17
17
|
- secure: bPqqN6twAJeRIpUEGozFIV3+dW2TSRxYQRrQhpzJ6Bx2ZXmk8UWl1O57Scf9/ZrCjo23MSvWKY1Rt1eyncaUVfzr4PjR6GjUwwdE7SPHQFKvGeNLIlJElzcz1ywcX6RU8+6JPYnx3NxR2O5VM8rf7wLwma00nuaDunM5NgKMMdQ=
|
18
18
|
- secure: JfAnh3FV1Q5Sz+QydZ7hFCCvCTiJoYqM4h0ztzZU/fqDNKo6d1/h8RWGZL++d7Ofl3Z7Jrfbj/1R4f8UiwNJVdqRMPgSrbbif8LfVBmsTtZm/gFcL5WFhm/kzIi7Jp7FmzNQc6Hx+EiI3T2mtLw51fi7lNNonVhevyEetUSvG2Q=
|
19
|
+
- secure: DLNt3OAr07xhgYc7Ju1qVSAeykaz9tOgdG0ya6VVRK7cUmJYzHhMWQErvixgEMnInJoGgdJPe8Bg9NdCrYTxk8gF6sCPAyK2g28NJSiqfkPSMUgS70r/YdcGISjTC+k9H2chB034qN0JDfWYg8tY4l69JB7sCtApBlIfjmK4Aso=
|
20
|
+
- secure: QpcuL9NkCD1MP/gJsrnlfnIMV7p9uARHNM5uPnumBYeisd0QCrt1gLBz5fGBpqbMF/peK5cnCVYbjRyteAygKi4sy/CfiA+YqIIPs72Gn2OvZKOWkwvq7UT0oMBhSrF+NGwX7JVSQRgeOqJFpVnkpp5ddW13e27ho/nuOcz3rTs=
|
data/Changelog.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# LinkShrink Changelog
|
2
2
|
|
3
|
+
## 0.0.8
|
4
|
+
|
5
|
+
Released January 19, 2014 ([0.0.7](https://github.com/jonahoffline/link_shrink/tree/v0.0.8)).
|
6
|
+
|
7
|
+
* Add Karmacracy Shrinker (available automatically in the command-line)
|
8
|
+
* Update version to 0.0.8
|
9
|
+
|
3
10
|
## 0.0.7
|
4
11
|
|
5
12
|
Released January 19, 2014 ([0.0.7](https://github.com/jonahoffline/link_shrink/tree/v0.0.7)).
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ A Ruby Gem and Command-Line Application for shrinking those long and nasty links
|
|
9
9
|
* TinyUrl
|
10
10
|
* IsGd
|
11
11
|
* Owly
|
12
|
+
* Karmacracy
|
12
13
|
* **More to come...**
|
13
14
|
|
14
15
|
## Installation
|
@@ -19,8 +20,7 @@ A Ruby Gem and Command-Line Application for shrinking those long and nasty links
|
|
19
20
|
|
20
21
|
## Setup
|
21
22
|
|
22
|
-
You can use any shrinker listed without worrying about the api key except for
|
23
|
-
Google let's you use its api without an api key, but providing one will generate metrics in their dashboard.
|
23
|
+
You can use any shrinker listed without worrying about the api key except for **Owly** and **Karmacracy**. Google let's you use its api without an api key, but providing one will generate metrics in their dashboard.
|
24
24
|
|
25
25
|
## Google
|
26
26
|
Works best with a Google URL API key. You can sign-up for a free one at
|
@@ -35,6 +35,8 @@ in the section titled "Simple API Access."
|
|
35
35
|
## Owly
|
36
36
|
Sign-up for a free API key at [Owly](http://ow.ly/).
|
37
37
|
|
38
|
+
## Karmacracy
|
39
|
+
Sign-up for a free API key at [Karmacracy](http://karmacracy.com/).
|
38
40
|
|
39
41
|
#### Configuration
|
40
42
|
|
@@ -43,6 +45,9 @@ Set your apikey as an environment variable:
|
|
43
45
|
$ export GOOGLE_URL_KEY='your_api_key_here'
|
44
46
|
|
45
47
|
$ export OWLY_URL_KEY='your_api_key_here'
|
48
|
+
|
49
|
+
$ export KARMACRACY_URL_KEY='your_api_key_here'
|
50
|
+
$ export KARMACRACY_USERNAME='your_username_here'
|
46
51
|
|
47
52
|
You could also save it in your `~/.bash_profile` or `~/.zshrc`
|
48
53
|
|
@@ -98,7 +103,8 @@ Shrinkers:
|
|
98
103
|
* -t, --tinyurl - use TinyUrl API
|
99
104
|
* -i, --isgd - use Is.gd API
|
100
105
|
* -om --owly - use Owly API
|
101
|
-
* -g, --google - use Google API (Default)
|
106
|
+
* -g, --google - use Google API (Default)
|
107
|
+
* -k --karmacracy - use Karmacracy API
|
102
108
|
|
103
109
|
Additional options:
|
104
110
|
|
data/lib/link_shrink.rb
CHANGED
@@ -8,6 +8,7 @@ require 'link_shrink/shrinkers/google'
|
|
8
8
|
require 'link_shrink/shrinkers/tinyurl'
|
9
9
|
require 'link_shrink/shrinkers/isgd'
|
10
10
|
require 'link_shrink/shrinkers/owly'
|
11
|
+
require 'link_shrink/shrinkers/karmacracy'
|
11
12
|
require 'link_shrink/config'
|
12
13
|
|
13
14
|
# @author Jonah Ruiz <jonah@pixelhipsters.com>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module LinkShrink
|
2
|
+
module Shrinkers
|
3
|
+
# @author Jonah Ruiz <jonah@pixelhipsters.com>
|
4
|
+
# Implements Karmacracy's URL Shortener API
|
5
|
+
class Karmacracy < Base
|
6
|
+
# Defines response structure to be parsed
|
7
|
+
response_options do
|
8
|
+
collection 'data'
|
9
|
+
short_url 'url'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns URL base for API
|
13
|
+
# @return [String] api base url
|
14
|
+
def base_url
|
15
|
+
'http://kcy.me/api/'
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns URL query parameters
|
19
|
+
# @return [String] query parameters to be used in request
|
20
|
+
def api_query_parameter
|
21
|
+
"?u=#{api_username}&key=#{api_key}&format=json&url=#{url}"
|
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
|
+
|
30
|
+
# Predicate method for checking if the API key exists
|
31
|
+
# @return [TrueClass, FalseClass]
|
32
|
+
def api_username?
|
33
|
+
ENV.has_key?("#{sub_klass.upcase}_USERNAME")
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns API Key
|
37
|
+
# @return [String] API key or nil
|
38
|
+
def api_username
|
39
|
+
api_username? ? ENV["#{sub_klass.upcase}_USERNAME"] : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def sanitize_url(new_url)
|
43
|
+
URI::encode(new_url)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/link_shrink/version.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinkShrink::Shrinkers::Karmacracy do
|
4
|
+
include_examples 'shared_examples'
|
5
|
+
|
6
|
+
let(:link_shrink) { described_class.new }
|
7
|
+
let(:karmacracy) { 'http://kcy.me/api/' }
|
8
|
+
let(:key) { ENV['KARMACRACY_URL_KEY'] }
|
9
|
+
let(:username) { ENV['KARMACRACY_USERNAME'] }
|
10
|
+
let(:long_url) { 'http://www.google.com' }
|
11
|
+
|
12
|
+
describe '#sub_klass' do
|
13
|
+
it 'returns the inherited subclass name' do
|
14
|
+
expect(link_shrink.sub_klass).to eq('Karmacracy')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#base_url' do
|
19
|
+
it 'returns the base_url for the API' do
|
20
|
+
expect(link_shrink.base_url).to eq(karmacracy)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#api_key' do
|
25
|
+
it 'returns the API key' do
|
26
|
+
expect(link_shrink.api_key).to eq(key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#api_url' do
|
31
|
+
it 'returns full api url' do
|
32
|
+
link_shrink.stub(:url).and_return(long_url)
|
33
|
+
url ="#{karmacracy}?u=#{username}&key=#{key}&format=json&url=#{long_url}"
|
34
|
+
|
35
|
+
expect(link_shrink.api_url).to eq(url)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#api_query_parameter' do
|
40
|
+
it 'returns query parameter' do
|
41
|
+
link_shrink.stub(:url).and_return(long_url)
|
42
|
+
|
43
|
+
expect(link_shrink.api_query_parameter)
|
44
|
+
.to eq("?u=#{username}&key=#{key}&format=json&url=#{long_url}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#content_type' do
|
49
|
+
it 'returns text/plain' do
|
50
|
+
expect(link_shrink.content_type).to eq('application/json')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#collection_key' do
|
55
|
+
it 'returns key of collection' do
|
56
|
+
expect(link_shrink.class.collection_key).to eq('data')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#url_key' do
|
61
|
+
it 'returns key used to extract data from response' do
|
62
|
+
expect(link_shrink.class.url_key).to eq('url')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'integration' do
|
67
|
+
it 'returns correct shortUrl' do
|
68
|
+
link_shrink.stub(:url).and_return(long_url)
|
69
|
+
LinkShrink.configure { |config| config.api = 'Karmacracy' }
|
70
|
+
|
71
|
+
expect(LinkShrink.shrink_url('www.google.com'))
|
72
|
+
.to eq('http://kcy.me/x3o2')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/link_shrink/shrinkers/base.rb
|
185
185
|
- lib/link_shrink/shrinkers/google.rb
|
186
186
|
- lib/link_shrink/shrinkers/isgd.rb
|
187
|
+
- lib/link_shrink/shrinkers/karmacracy.rb
|
187
188
|
- lib/link_shrink/shrinkers/owly.rb
|
188
189
|
- lib/link_shrink/shrinkers/tinyurl.rb
|
189
190
|
- lib/link_shrink/util.rb
|
@@ -199,6 +200,7 @@ files:
|
|
199
200
|
- spec/link_shrink/request_spec.rb
|
200
201
|
- spec/link_shrink/shrinkers/google_spec.rb
|
201
202
|
- spec/link_shrink/shrinkers/isgd_spec.rb
|
203
|
+
- spec/link_shrink/shrinkers/karmacracy_spec.rb
|
202
204
|
- spec/link_shrink/shrinkers/owly_spec.rb
|
203
205
|
- spec/link_shrink/shrinkers/shrinker_base_spec.rb
|
204
206
|
- spec/link_shrink/shrinkers/tiny_url_spec.rb
|
@@ -235,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
237
|
version: '0'
|
236
238
|
segments:
|
237
239
|
- 0
|
238
|
-
hash:
|
240
|
+
hash: 2601120498495095577
|
239
241
|
requirements: []
|
240
242
|
rubyforge_project:
|
241
243
|
rubygems_version: 1.8.25
|
@@ -253,6 +255,7 @@ test_files:
|
|
253
255
|
- spec/link_shrink/request_spec.rb
|
254
256
|
- spec/link_shrink/shrinkers/google_spec.rb
|
255
257
|
- spec/link_shrink/shrinkers/isgd_spec.rb
|
258
|
+
- spec/link_shrink/shrinkers/karmacracy_spec.rb
|
256
259
|
- spec/link_shrink/shrinkers/owly_spec.rb
|
257
260
|
- spec/link_shrink/shrinkers/shrinker_base_spec.rb
|
258
261
|
- spec/link_shrink/shrinkers/tiny_url_spec.rb
|