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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17cb39c19898b60d73e95bd5978331074f749ae8
4
- data.tar.gz: 0a16234d8845c2cf02c3a847eb0aa22734eeb6ec
3
+ metadata.gz: 6d359577bdaa34c60135ce813d2df657b16c69a4
4
+ data.tar.gz: 50d8201cc818ce629dd95f6e5a4fa2146308922c
5
5
  SHA512:
6
- metadata.gz: 8b9acad3207d9542f1a0d720256542e96a21f55c51e49d6d0163be891f16ad47e0a667a3f6f49aaa22f193b5c2b10f50c46ac6f112fc9e3fb48f07e7510db9d5
7
- data.tar.gz: 796293f24eefd7cef97f2be42f855d67a8ea5a7b09a936193812616e2088de4807d7ae657b85cb57be8076e4f35afad7607f9051c8d39c7486f57fa364b44efe
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 [Quickly](https://github.com/typhoeus/typhoeus) which is an awesome HTTP library for fast
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 << json_response[:data][:url]
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)
@@ -1,3 +1,3 @@
1
1
  class BitlyQuickly
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitly_quickly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oldrich Vetesnik