bitly_quickly 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/bitly_quickly.rb +11 -3
- data/lib/bitly_quickly/version.rb +1 -1
- data/spec/lib/bitly_quickly_spec.rb +7 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d359577bdaa34c60135ce813d2df657b16c69a4
|
4
|
+
data.tar.gz: 50d8201cc818ce629dd95f6e5a4fa2146308922c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad9bab5c499ea454db79bcb8cd57b9f9b7709ffa5abf0568d45da2adab39462ccc55b6557880b32ecd0ff47c32dcbb65bb4c609599961aa20b3617cd5bb8f500
|
7
|
+
data.tar.gz: 61ba5554b55af1bd439f0f1cb2e645ffcacbd0bcbffb4da66aecb0099723b4c914bf165af0344cc3380dfaaacda6201ec75e96f9688d4e61242360ffcf423ad0
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
There are many great [bit.ly](https://bitly.com/) gems, it's just that I wanted something as fast and as simple as possible.
|
4
4
|
It can only shorten URLs. :-)
|
5
5
|
|
6
|
-
It uses [
|
6
|
+
It uses [Typhoeus](https://github.com/typhoeus/typhoeus) which is an awesome HTTP library for fast
|
7
7
|
and parallel networking. It also uses [Oj](https://github.com/ohler55/oj) which is a fast JSON parser.
|
8
8
|
|
9
9
|
## Installation
|
@@ -23,8 +23,8 @@ Or install it yourself as:
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
client = BitlyQuickly.new(access_token: 'token')
|
26
|
-
shortened_url = client.shorten('http://www.google.com/')
|
27
|
-
shortened_urls = client.shorten([
|
26
|
+
shortened_url = client.shorten('http://www.google.com/') # returns String
|
27
|
+
shortened_urls = client.shorten([ # returns Hash
|
28
28
|
'https://www.google.com/',
|
29
29
|
'https://www.youtube.com/',
|
30
30
|
'https://www.yahoo.com/',
|
data/lib/bitly_quickly.rb
CHANGED
@@ -33,14 +33,14 @@ class BitlyQuickly
|
|
33
33
|
|
34
34
|
def get_many_responses(array_of_long_urls)
|
35
35
|
hydra = Typhoeus::Hydra.new
|
36
|
-
responses =
|
36
|
+
responses = {}
|
37
37
|
|
38
38
|
array_of_long_urls.each do |long_url|
|
39
39
|
request = make_shorten_request long_url
|
40
40
|
|
41
41
|
request.on_complete do |response|
|
42
42
|
json_response = response_to_json response
|
43
|
-
responses
|
43
|
+
responses[ response.request.long_url ] = json_response[:data][:url]
|
44
44
|
end
|
45
45
|
|
46
46
|
hydra.queue request
|
@@ -60,7 +60,7 @@ class BitlyQuickly
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def make_shorten_request(long_url)
|
63
|
-
Typhoeus::Request.new(
|
63
|
+
request = Typhoeus::Request.new(
|
64
64
|
api_url('/v3/shorten'),
|
65
65
|
{
|
66
66
|
params: {
|
@@ -72,6 +72,14 @@ class BitlyQuickly
|
|
72
72
|
}
|
73
73
|
}
|
74
74
|
)
|
75
|
+
|
76
|
+
# I need to access this later in the result
|
77
|
+
class << request
|
78
|
+
attr_accessor :long_url
|
79
|
+
end
|
80
|
+
|
81
|
+
request.long_url = long_url
|
82
|
+
request
|
75
83
|
end
|
76
84
|
|
77
85
|
def get_response(long_url)
|
@@ -81,13 +81,13 @@ describe BitlyQuickly do
|
|
81
81
|
'http://www.google.com/5',
|
82
82
|
]
|
83
83
|
|
84
|
-
response_urls =
|
85
|
-
'http://pht.io/1eyUhF1',
|
86
|
-
'http://pht.io/1eyUhF2',
|
87
|
-
'http://pht.io/1eyUhF3',
|
88
|
-
'http://pht.io/1eyUhF4',
|
89
|
-
'http://pht.io/1eyUhF5',
|
90
|
-
|
84
|
+
response_urls = {
|
85
|
+
'http://www.google.com/1' => 'http://pht.io/1eyUhF1',
|
86
|
+
'http://www.google.com/2' => 'http://pht.io/1eyUhF2',
|
87
|
+
'http://www.google.com/3' => 'http://pht.io/1eyUhF3',
|
88
|
+
'http://www.google.com/4' => 'http://pht.io/1eyUhF4',
|
89
|
+
'http://www.google.com/5' => 'http://pht.io/1eyUhF5',
|
90
|
+
}
|
91
91
|
|
92
92
|
expect(@client.shorten(request_urls)).to eq(response_urls)
|
93
93
|
end
|