link_shrink 0.0.3 → 0.0.4
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 +8 -0
- data/README.md +2 -3
- data/lib/link_shrink/request.rb +12 -5
- data/lib/link_shrink/version.rb +1 -1
- data/spec/link_shrink/json_parser_spec.rb +10 -0
- data/spec/link_shrink/request_spec.rb +16 -0
- data/spec/vcr_cassettes/LinkShrink/_shrink_url/creates_a_short_url.yml +33 -0
- metadata +2 -2
data/Changelog.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# LinkShrink Changelog
|
2
2
|
|
3
|
+
## 0.0.4
|
4
|
+
|
5
|
+
Released September 6, 2013 ([0.0.4](https://github.com/jonahoffline/link_shrink/tree/v0.0.4)).
|
6
|
+
|
7
|
+
* Refactor complex method in Request module (#process_response).
|
8
|
+
* Update version to 0.0.4
|
9
|
+
* Add coveralls badge.
|
10
|
+
|
3
11
|
## 0.0.3
|
4
12
|
|
5
13
|
Released September 6, 2013 ([0.0.3](https://github.com/jonahoffline/link_shrink/tree/v0.0.3)).
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
LinkShrink
|
2
|
-
|
1
|
+
# LinkShrink
|
2
|
+
[](https://travis-ci.org/jonahoffline/link_shrink) [](http://badge.fury.io/rb/link_shrink) [](https://gemnasium.com/jonahoffline/link_shrink) [](https://coveralls.io/r/jonahoffline/link_shrink?branch=master) [](https://codeclimate.com/github/jonahoffline/link_shrink)
|
3
3
|
|
4
4
|
A Ruby Gem and Command-Line Application for shrinking those long and nasty links into a shorter URL
|
5
5
|
|
@@ -68,7 +68,6 @@ LinkShrink::Config.api = 'TinyUrl'
|
|
68
68
|
LinkShrink.shrink_url('http://www.google.com')
|
69
69
|
=> "http://tinyurl.com/1c2"
|
70
70
|
|
71
|
-
|
72
71
|
```
|
73
72
|
|
74
73
|
|
data/lib/link_shrink/request.rb
CHANGED
@@ -11,11 +11,18 @@ module LinkShrink
|
|
11
11
|
module_function
|
12
12
|
|
13
13
|
def process_request(url, options, shrinker = LinkShrink::Config.api)
|
14
|
-
|
14
|
+
parse(request(url, shrinker).body, options, shrinker)
|
15
|
+
end
|
16
|
+
|
17
|
+
def parse(response, options, shrinker)
|
18
|
+
if shrinker.content_type.eql?('text/plain')
|
19
|
+
response
|
20
|
+
else
|
21
|
+
process_response(response, options, shrinker)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def process_response(response, options, shrinker, json = JSONParser)
|
18
|
-
return response if shrinker.content_type.eql?('text/plain')
|
19
26
|
option = Options.new(options)
|
20
27
|
parsed_json = json.parse_json(response)
|
21
28
|
plain = parsed_json['id']
|
@@ -45,12 +52,12 @@ module LinkShrink
|
|
45
52
|
# Calls URL API
|
46
53
|
# @see LinkShrink::Shrinkers::Base#api_url
|
47
54
|
# @see LinkShrink::Shrinkers::Base#body_parameters
|
48
|
-
def request(
|
49
|
-
shrinker.url =
|
55
|
+
def request(new_url, shrinker)
|
56
|
+
shrinker.url = new_url
|
50
57
|
Typhoeus::Request.new(
|
51
58
|
shrinker.api_url,
|
52
59
|
method: shrinker.http_method,
|
53
|
-
body: shrinker.body_parameters(url),
|
60
|
+
body: shrinker.body_parameters(shrinker.url),
|
54
61
|
headers: { 'Content-Type' => shrinker.content_type }
|
55
62
|
).run
|
56
63
|
end
|
data/lib/link_shrink/version.rb
CHANGED
@@ -18,4 +18,14 @@ describe LinkShrink::JSONParser do
|
|
18
18
|
.to eq('{"kind":"urlshortener#url","id":"http://goo.gl/fbsS","longUrl":"http://www.google.com/"}')
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
22
|
+
describe '.included' do
|
23
|
+
it 'extends self' do
|
24
|
+
dummy_class = Class.new do
|
25
|
+
include LinkShrink::JSONParser
|
26
|
+
end
|
27
|
+
|
28
|
+
expect(dummy_class.included_modules).to include(LinkShrink::JSONParser)
|
29
|
+
end
|
30
|
+
end
|
21
31
|
end
|
@@ -2,6 +2,10 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LinkShrink::Request do
|
4
4
|
include_examples 'shared_examples'
|
5
|
+
before :each do
|
6
|
+
LinkShrink.configure { |c| c.api = 'Google'}
|
7
|
+
end
|
8
|
+
|
5
9
|
let(:shrinker) { LinkShrink::Config.api }
|
6
10
|
let(:json_default) {{ :json => false }}
|
7
11
|
|
@@ -52,4 +56,16 @@ describe LinkShrink::Request do
|
|
52
56
|
.to be_kind_of(Typhoeus::Response)
|
53
57
|
end
|
54
58
|
end
|
59
|
+
|
60
|
+
describe '#parse' do
|
61
|
+
context 'when response is text/plain' do
|
62
|
+
it 'returns response' do
|
63
|
+
LinkShrink.configure { |c| c.api = 'TinyUrl'}
|
64
|
+
response = link_shrink.request(url, shrinker).body
|
65
|
+
|
66
|
+
expect(link_shrink.parse(response, {json: false}, shrinker))
|
67
|
+
.to eq('http://tinyurl.com/1c2')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
55
71
|
end
|
@@ -131,4 +131,37 @@ http_interactions:
|
|
131
131
|
\ ],\n \"code\": 400,\n \"message\": \"Bad Request\"\n }\n}\n"
|
132
132
|
http_version:
|
133
133
|
recorded_at: Fri, 06 Sep 2013 08:25:30 GMT
|
134
|
+
- request:
|
135
|
+
method: get
|
136
|
+
uri: http://tinyurl.com/api-create.php?url=http://www.google.com
|
137
|
+
body:
|
138
|
+
encoding: US-ASCII
|
139
|
+
string: ''
|
140
|
+
headers:
|
141
|
+
User-Agent:
|
142
|
+
- Typhoeus - https://github.com/typhoeus/typhoeus
|
143
|
+
Content-Type:
|
144
|
+
- text/plain
|
145
|
+
response:
|
146
|
+
status:
|
147
|
+
code: 200
|
148
|
+
message: OK
|
149
|
+
headers:
|
150
|
+
X-Powered-By:
|
151
|
+
- PHP/5.4.13
|
152
|
+
Content-Type:
|
153
|
+
- text/plain
|
154
|
+
Connection:
|
155
|
+
- close
|
156
|
+
Transfer-Encoding:
|
157
|
+
- chunked
|
158
|
+
Date:
|
159
|
+
- Fri, 06 Sep 2013 11:31:45 GMT
|
160
|
+
Server:
|
161
|
+
- TinyURL/1.6
|
162
|
+
body:
|
163
|
+
encoding: US-ASCII
|
164
|
+
string: http://tinyurl.com/1c2
|
165
|
+
http_version:
|
166
|
+
recorded_at: Fri, 06 Sep 2013 11:31:47 GMT
|
134
167
|
recorded_with: VCR 2.5.0
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '0'
|
231
231
|
segments:
|
232
232
|
- 0
|
233
|
-
hash:
|
233
|
+
hash: 1243110028426905467
|
234
234
|
requirements: []
|
235
235
|
rubyforge_project:
|
236
236
|
rubygems_version: 1.8.25
|