bitly_quickly 0.0.5 → 0.0.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63dd1b93398c8f64dfedb5fd187f74257d4b612d
4
- data.tar.gz: 544f7bd45d92e35caaa34f859e20f198497a9b8c
3
+ metadata.gz: b7c550c1a0c10e31d3afe5836c7cbb9aae2551e0
4
+ data.tar.gz: a064475020ff8f03983c6e8a30e2b2f06295cd51
5
5
  SHA512:
6
- metadata.gz: 71141e4ae5b260e34aedd4f64caa75c374760a987d42d34c363ce229b7a303eccbae4bab153775eca41fda47b0acf89700cc56ce3da72242dbed87932a171f39
7
- data.tar.gz: 87b4d282ffe2bf6aa10da60ee922a0f0403ac7fec294e59667add7c98a10b90c1115efbdac9ab60b1bcf03519d86e5d1cdfbb6431fa0c93d31da26d51fa53a8e
6
+ metadata.gz: 2caffc56097c4b4697965c65888f74a9621155eaf34831e9c310c5ed05d93a9678747fa44d2e9373e48710b43aa779328517bdd1f99814c9256d455f4ef20a8d
7
+ data.tar.gz: e192e6b1fa33cc3c7010e1fca2ead80e04201e3367fc491dfeb8a2dabf3583098daa3d561088ca34e5d7d56f43ed4a8a0dab4be5939312ada1b85612029341d1
data/.gitignore CHANGED
@@ -1,17 +1,10 @@
1
1
  *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format documentation
3
+ --require spec_helper.rb
data/.rubocop-my.yml ADDED
@@ -0,0 +1,5 @@
1
+ Metrics/MethodLength:
2
+ Max: 15
3
+
4
+ Style/Documentation:
5
+ Enabled: false
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop-my.yml
data/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.1
5
- - 2.1.0
4
+ - 2.2.2
5
+ - 2.1.6
6
6
  - 2.0.0
7
7
  - 1.9.3
8
+ - jruby-19mode
8
9
 
9
10
  branches:
10
11
  only:
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --protected
2
+ --private
3
+ --embed-mixins
4
+ lib/**/*.rb
5
+ -
6
+ README.md
7
+ LICENSE.txt
data/LICENSE.txt CHANGED
@@ -1,22 +1,21 @@
1
- Copyright (c) 2014 Oldrich Vetesnik
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2014-2015 Oldrich Vetesnik
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # BitlyQuickly
2
-
3
- [![Build Status](https://travis-ci.org/ollie/bitly_quickly.png?branch=master)](https://travis-ci.org/ollie/bitly_quickly)
1
+ # BitlyQuickly [![Build Status](https://img.shields.io/travis/ollie/bitly_quickly/master.svg)](https://travis-ci.org/ollie/bitly_quickly) [![Code Climate](https://img.shields.io/codeclimate/github/ollie/bitly_quickly.svg)](https://codeclimate.com/github/ollie/bitly_quickly) [![Gem Version](https://img.shields.io/gem/v/bitly_quickly.svg)](https://rubygems.org/gems/bitly_quickly)
4
2
 
5
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.
6
4
  It can only shorten URLs. :-)
@@ -8,13 +6,6 @@ It can only shorten URLs. :-)
8
6
  It uses [Typhoeus](https://github.com/typhoeus/typhoeus) which is an awesome HTTP library for fast
9
7
  and parallel networking. It also uses [Oj](https://github.com/ohler55/oj) which is a fast JSON parser.
10
8
 
11
- ## Tested on
12
-
13
- * 2.1.1
14
- * 2.1.0
15
- * 2.0.0
16
- * 1.9.3
17
-
18
9
  ## Installation
19
10
 
20
11
  Add this line to your application's Gemfile:
@@ -31,14 +22,34 @@ Or install it yourself as:
31
22
 
32
23
  ## Usage
33
24
 
34
- client = BitlyQuickly.new(access_token: 'token')
35
- shortened_url = client.shorten('http://www.google.com/') # returns String
36
- shortened_urls = client.shorten([ # returns Hash
37
- 'https://www.google.com/',
38
- 'https://www.youtube.com/',
39
- 'https://www.yahoo.com/',
40
- ])
25
+ ```ruby
26
+ client = BitlyQuickly.new(access_token: 'token')
27
+ shortened_url = client.shorten('http://www.google.com/') # Returns shortened URL.
28
+ shortened_urls = client.shorten([ # Returns original => shortend URL hash.
29
+ 'https://www.google.com/',
30
+ 'https://www.youtube.com/',
31
+ 'https://www.yahoo.com/'
32
+ ])
33
+
34
+ shortened_url == 'http://pht.io/1eyUhFo'
35
+
36
+ shortened_urls == {
37
+ 'https://www.yahoo.com/' => 'http://pht.io/1ezI6Z6',
38
+ 'https://www.youtube.com/' => 'http://pht.io/1ezI8Qz',
39
+ 'https://www.google.com/' => 'http://pht.io/1ezI8QA'
40
+ }
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
48
 
42
49
  ## Contributing
43
50
 
44
- You know the routine…
51
+ 1. Fork it (https://github.com/ollie/bitly_quickly/fork)
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ task default: :combo
2
+
3
+ desc 'Run tests, rubocop and generate documentation'
4
+ task :combo do
5
+ sh 'bundle exec rspec'
6
+ sh('bundle exec rubocop') {} # ignore status > 0
7
+ sh 'bundle exec yardoc'
8
+ end
9
+
10
+ desc 'Same as :combo but build a gem, too'
11
+ task mega_combo: :combo do
12
+ sh 'gem build bitly_quickly.gemspec'
13
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bitly_quickly'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -8,21 +8,37 @@ Gem::Specification.new do |spec|
8
8
  spec.version = BitlyQuickly::VERSION
9
9
  spec.authors = ['Oldrich Vetesnik']
10
10
  spec.email = ['oldrich.vetesnik@gmail.com']
11
- spec.summary = %q{Shorten URLs with bit.ly API}
12
- spec.description = %q{Shorten URLs with bit.ly API, make parallel requests.}
11
+
12
+ spec.summary = 'Shorten URLs with bit.ly API'
13
+ spec.description = 'Shorten URLs with bit.ly API, make parallel requests.'
13
14
  spec.homepage = 'https://github.com/ollie/bitly_quickly'
14
15
  spec.license = 'MIT'
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ # rubocop:disable Metrics/LineLength
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
21
  spec.require_paths = ['lib']
20
22
 
21
- spec.add_development_dependency 'bundler', '~> 1.5'
22
- spec.add_development_dependency 'rspec', '~> 2.14'
23
- spec.add_development_dependency 'webmock', '~> 1.17'
24
- spec.add_development_dependency 'simplecov', '~> 0.8'
23
+ # System
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+
26
+ # Test
27
+ spec.add_development_dependency 'rspec', '~> 3.2'
28
+ spec.add_development_dependency 'webmock', '~> 1.21'
29
+ spec.add_development_dependency 'simplecov', '~> 0.10'
30
+
31
+ # Code style, debugging, docs
32
+ spec.add_development_dependency 'rubocop', '~> 0.31'
33
+ spec.add_development_dependency 'pry', '~> 0.10'
34
+ spec.add_development_dependency 'yard', '~> 0.8'
35
+ spec.add_development_dependency 'rake', '~> 10.4'
36
+
37
+ # Runtime
25
38
 
26
- spec.add_runtime_dependency 'typhoeus', '~> 0.6'
27
- spec.add_runtime_dependency 'oj', '~> 2.5'
39
+ # Networking
40
+ # Fast networking
41
+ spec.add_runtime_dependency 'typhoeus', '~> 0.7'
42
+ # A common interface to multiple JSON libraries
43
+ spec.add_runtime_dependency 'multi_json', '~> 1.11'
28
44
  end
data/lib/bitly_quickly.rb CHANGED
@@ -1,51 +1,100 @@
1
1
  require 'typhoeus'
2
- require 'oj'
2
+ require 'multi_json'
3
3
 
4
4
  require 'bitly_quickly/version'
5
-
6
- # V3 Wrapper
5
+ require 'bitly_quickly/error'
6
+
7
+ # Wrapper around Bitly V3 API.
8
+ #
9
+ # @example
10
+ # client = BitlyQuickly.new(access_token: 'token')
11
+ # shortened_url = client.shorten('http://www.google.com/')
12
+ # shortened_urls = client.shorten([
13
+ # 'https://www.google.com/',
14
+ # 'https://www.youtube.com/',
15
+ # 'https://www.yahoo.com/'
16
+ # ])
17
+ #
18
+ # shortened_url == 'http://pht.io/1eyUhFo'
19
+ #
20
+ # shortened_urls == {
21
+ # 'https://www.yahoo.com/' => 'http://pht.io/1ezI6Z6',
22
+ # 'https://www.youtube.com/' => 'http://pht.io/1ezI8Qz',
23
+ # 'https://www.google.com/' => 'http://pht.io/1ezI8QA'
24
+ # }
7
25
  class BitlyQuickly
8
- class BitlyError < StandardError; end
9
- class RateLimitExceededError < BitlyError; end # 403
10
- class TemporarilyUnavailableError < BitlyError; end # 503
11
- class NotFoundError < BitlyError; end # 404
12
- class InvalidRequestOrResponseError < BitlyError; end # 500
13
- class UnknownError < BitlyError; end
14
-
26
+ # Bitly API server.
15
27
  DEFAULT_API_ADDRESS = 'https://api-ssl.bitly.com'
16
- OJ_OPTIONS = {
17
- mode: :compat, # Converts values with to_hash or to_json
18
- symbol_keys: true, # Symbol keys to string keys
19
- time_format: :xmlschema, # ISO8061 format
20
- second_precision: 0, # No include milliseconds
21
- }
22
-
23
- attr_reader :access_token,
24
- :api_address
25
-
26
- def initialize(options)
27
- @access_token = options.delete(:access_token) || raise( ArgumentError.new('Missing access_token option') )
28
- @api_address = options.delete(:api_address) || DEFAULT_API_ADDRESS
28
+
29
+ # API Access Token.
30
+ #
31
+ # @return [String]
32
+ attr_reader :access_token
33
+
34
+ # Alternate API server URL.
35
+ #
36
+ # @return [String]
37
+ attr_reader :api_address
38
+
39
+ # Init with access token and api address.
40
+ #
41
+ # @param config [Hash] Config settings.
42
+ # @option config :access_token [String] API Access Token.
43
+ # @option config :api_address [String] Alternate API server URL, optional.
44
+ def initialize(config)
45
+ @access_token = config.delete(:access_token) || fail(
46
+ ArgumentError, 'Missing access_token option'
47
+ )
48
+
49
+ @api_address = config.delete(:api_address) || DEFAULT_API_ADDRESS
29
50
  end
30
51
 
52
+ # Shorten URL or array of URLs. In case single URL is passed, it returns
53
+ # the shortened URL. If an array is passed, it returns a hash where keys
54
+ # are original URLs and values are shortened URLs.
55
+ #
56
+ # @param long_url_or_array [String, Array<String>]
57
+ #
58
+ # @return [String, Hash<String, String>]
31
59
  def shorten(long_url_or_array)
32
- if long_url_or_array.respond_to? :each
33
- get_many_responses long_url_or_array
60
+ if long_url_or_array.respond_to?(:each)
61
+ get_many_responses(long_url_or_array)
34
62
  else
35
- get_single_response long_url_or_array
63
+ get_single_response(long_url_or_array)
36
64
  end
37
65
  end
38
66
 
67
+ # Create endpoint URL.
68
+ #
69
+ # @param path [String] Endpoint path.
70
+ #
71
+ # @return [String] Endpoint URL.
72
+ def endpoint_url(path)
73
+ URI.join(api_address, path).to_s
74
+ end
75
+
76
+ ##########################
77
+ # Private instance methods
78
+ ##########################
79
+
80
+ private
81
+
82
+ # Shorten each URL and return a hash where keys
83
+ # are original URLs and values are shortened URLs.
84
+ #
85
+ # @param array_of_long_urls [String, Array<String>]
86
+ #
87
+ # @return [Hash<String, String>]
39
88
  def get_many_responses(array_of_long_urls)
40
89
  hydra = Typhoeus::Hydra.new
41
90
  responses = {}
42
91
 
43
92
  array_of_long_urls.each do |long_url|
44
- request = make_shorten_request long_url
93
+ request = make_shorten_request(long_url)
45
94
 
46
95
  request.on_complete do |response|
47
- json_response = response_to_json response
48
- responses[ response.request.long_url ] = json_response[:data][:url]
96
+ json_response = response_to_json(response)
97
+ responses[long_url] = json_response[:data][:url]
49
98
  end
50
99
 
51
100
  hydra.queue request
@@ -55,61 +104,65 @@ class BitlyQuickly
55
104
  responses
56
105
  end
57
106
 
107
+ # Shorten single URL.
108
+ #
109
+ # @param long_url [String] Original URL.
110
+ #
111
+ # @return [String] Shortened URL.
58
112
  def get_single_response(long_url)
59
- response = get_response long_url
60
- response[:data][:url]
61
- end
113
+ request = make_shorten_request(long_url)
114
+ response = request.run
115
+ json_response = response_to_json(response)
62
116
 
63
- def api_url(path)
64
- URI.join(api_address, path).to_s
117
+ json_response[:data][:url]
65
118
  end
66
119
 
120
+ # Prepare Typhoeus shorten request.
121
+ #
122
+ # @param long_url [String] Original URL.
123
+ #
124
+ # @return [Typhoues::Request]
67
125
  def make_shorten_request(long_url)
68
- request = Typhoeus::Request.new(
69
- api_url('/v3/shorten'),
70
- {
71
- params: {
72
- access_token: access_token,
73
- longUrl: long_url
74
- },
126
+ Typhoeus::Request.new(
127
+ endpoint_url('/v3/shorten'),
128
+ params: {
129
+ access_token: access_token,
130
+ longUrl: long_url
75
131
  }
76
132
  )
77
-
78
- # I need to access this later in the result
79
- class << request
80
- attr_accessor :long_url
81
- end
82
-
83
- request.long_url = long_url
84
- request
85
- end
86
-
87
- def get_response(long_url)
88
- request = make_shorten_request long_url
89
- response = request.run
90
- response_to_json response
91
133
  end
92
134
 
135
+ # Check response code and raise an appropriate error.
136
+ # Otherwise return parsed JSON body.
137
+ #
138
+ # @param response [Typhoues::Response]
139
+ #
140
+ # @return [Hash]
93
141
  def response_to_json(response)
94
- json_response = parse_response response
142
+ json_response = parse_json(response.body)
95
143
 
96
144
  case json_response[:status_code]
97
145
  when 200
98
146
  return json_response
99
147
  when 403
100
- raise RateLimitExceededError, json_response[:status_txt]
148
+ fail Error::RateLimitExceeded, json_response[:status_txt]
101
149
  when 404
102
- raise NotFoundError, json_response[:status_txt]
150
+ fail Error::NotFound, json_response[:status_txt]
103
151
  when 500
104
- raise InvalidRequestOrResponseError, json_response[:status_txt]
152
+ fail Error::InvalidRequestOrResponse, json_response[:status_txt]
105
153
  when 503
106
- raise TemporarilyUnavailableError, json_response[:status_txt]
154
+ fail Error::TemporarilyUnavailable, json_response[:status_txt]
107
155
  else
108
- raise UnknownError, json_response[:status_txt]
156
+ fail Error::UnknownError, json_response[:status_txt]
109
157
  end
110
158
  end
111
159
 
112
- def parse_response(response)
113
- Oj.load response.body, OJ_OPTIONS
160
+ # Parse JSON string into Ruby hash.
161
+ #
162
+ # @param json [String] JSON string.
163
+ #
164
+ # @return [Hash]
165
+ def parse_json(json)
166
+ MultiJson.load(json, symbolize_keys: true)
114
167
  end
115
168
  end
@@ -0,0 +1,11 @@
1
+ class BitlyQuickly
2
+ # # Error classes.
3
+ # rubocop:disable Style/SpaceAroundOperators
4
+ class Error < StandardError
5
+ class RateLimitExceeded < Error; end # 403
6
+ class TemporarilyUnavailable < Error; end # 503
7
+ class NotFound < Error; end # 404
8
+ class InvalidRequestOrResponse < Error; end # 500
9
+ class UnknownError < Error; end # Huh?
10
+ end
11
+ end
@@ -1,3 +1,4 @@
1
1
  class BitlyQuickly
2
- VERSION = '0.0.5'
2
+ # Version number, happy now?
3
+ VERSION = '0.0.6'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitly_quickly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oldrich Vetesnik
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-03-19 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,44 +16,86 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.14'
33
+ version: '3.2'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.14'
40
+ version: '3.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: webmock
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.17'
47
+ version: '1.21'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.17'
54
+ version: '1.21'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.31'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.31'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - "~>"
@@ -66,34 +108,48 @@ dependencies:
66
108
  - - "~>"
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.4'
69
125
  - !ruby/object:Gem::Dependency
70
126
  name: typhoeus
71
127
  requirement: !ruby/object:Gem::Requirement
72
128
  requirements:
73
129
  - - "~>"
74
130
  - !ruby/object:Gem::Version
75
- version: '0.6'
131
+ version: '0.7'
76
132
  type: :runtime
77
133
  prerelease: false
78
134
  version_requirements: !ruby/object:Gem::Requirement
79
135
  requirements:
80
136
  - - "~>"
81
137
  - !ruby/object:Gem::Version
82
- version: '0.6'
138
+ version: '0.7'
83
139
  - !ruby/object:Gem::Dependency
84
- name: oj
140
+ name: multi_json
85
141
  requirement: !ruby/object:Gem::Requirement
86
142
  requirements:
87
143
  - - "~>"
88
144
  - !ruby/object:Gem::Version
89
- version: '2.5'
145
+ version: '1.11'
90
146
  type: :runtime
91
147
  prerelease: false
92
148
  version_requirements: !ruby/object:Gem::Requirement
93
149
  requirements:
94
150
  - - "~>"
95
151
  - !ruby/object:Gem::Version
96
- version: '2.5'
152
+ version: '1.11'
97
153
  description: Shorten URLs with bit.ly API, make parallel requests.
98
154
  email:
99
155
  - oldrich.vetesnik@gmail.com
@@ -103,16 +159,20 @@ extra_rdoc_files: []
103
159
  files:
104
160
  - ".gitignore"
105
161
  - ".rspec"
162
+ - ".rubocop-my.yml"
163
+ - ".rubocop.yml"
106
164
  - ".travis.yml"
165
+ - ".yardopts"
107
166
  - Gemfile
108
167
  - LICENSE.txt
109
168
  - README.md
169
+ - Rakefile
170
+ - bin/console
171
+ - bin/setup
110
172
  - bitly_quickly.gemspec
111
173
  - lib/bitly_quickly.rb
174
+ - lib/bitly_quickly/error.rb
112
175
  - lib/bitly_quickly/version.rb
113
- - spec/lib/bitly_quickly_spec.rb
114
- - spec/request_stubs.rb
115
- - spec/spec_helper.rb
116
176
  homepage: https://github.com/ollie/bitly_quickly
117
177
  licenses:
118
178
  - MIT
@@ -133,12 +193,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
193
  version: '0'
134
194
  requirements: []
135
195
  rubyforge_project:
136
- rubygems_version: 2.2.2
196
+ rubygems_version: 2.4.6
137
197
  signing_key:
138
198
  specification_version: 4
139
199
  summary: Shorten URLs with bit.ly API
140
- test_files:
141
- - spec/lib/bitly_quickly_spec.rb
142
- - spec/request_stubs.rb
143
- - spec/spec_helper.rb
200
+ test_files: []
144
201
  has_rdoc:
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BitlyQuickly do
4
- it 'fails to make a client' do
5
- expect { BitlyQuickly.new }.to raise_error
6
- end
7
-
8
- context 'With access_token' do
9
- before do
10
- @client = BitlyQuickly.new access_token: 'token'
11
- end
12
-
13
- it 'access_token' do
14
- expect(@client.access_token).to eq('token')
15
- end
16
-
17
- it 'api_address' do
18
- expect(@client.api_address).to eq(BitlyQuickly::DEFAULT_API_ADDRESS)
19
- end
20
- end
21
-
22
- context 'With access_token and api_address' do
23
- before do
24
- @client = BitlyQuickly.new access_token: 'token', api_address: 'http://api.bitly.com'
25
- end
26
-
27
- it 'api_address' do
28
- expect(@client.api_address).to eq('http://api.bitly.com')
29
- end
30
- end
31
-
32
- context 'Methods' do
33
- before do
34
- @client = BitlyQuickly.new access_token: 'token'
35
- end
36
-
37
- it 'api_url' do
38
- expect(@client.api_url('/test')).to eq('https://api-ssl.bitly.com/test')
39
- end
40
-
41
- it 'makes request' do
42
- expect(@client.make_shorten_request('http://example.org/1')).to be_kind_of(Typhoeus::Request)
43
- end
44
- end
45
-
46
- # Success
47
-
48
- context 'Response with valid token' do
49
- before do
50
- @client = BitlyQuickly.new access_token: 'valid_token'
51
- end
52
-
53
- it 'raises an execption' do
54
- expect { @client.shorten('http://example.org/200/1') }.to_not raise_error
55
- end
56
-
57
- it 'status code' do
58
- expect(@client.shorten('http://example.org/200/1')).to eq('http://pht.io/1eyUhF1')
59
- end
60
- end
61
-
62
- context 'Many requests' do
63
- before do
64
- @client = BitlyQuickly.new access_token: 'valid_token'
65
- end
66
-
67
- it 'makes many requests' do
68
- request_urls = [
69
- 'http://example.org/200/1',
70
- 'http://example.org/200/2',
71
- 'http://example.org/200/3',
72
- 'http://example.org/200/4',
73
- 'http://example.org/200/5',
74
- ]
75
-
76
- response_urls = {
77
- 'http://example.org/200/1' => 'http://pht.io/1eyUhF1',
78
- 'http://example.org/200/2' => 'http://pht.io/1eyUhF2',
79
- 'http://example.org/200/3' => 'http://pht.io/1eyUhF3',
80
- 'http://example.org/200/4' => 'http://pht.io/1eyUhF4',
81
- 'http://example.org/200/5' => 'http://pht.io/1eyUhF5',
82
- }
83
-
84
- expect(@client.shorten(request_urls)).to eq(response_urls)
85
- end
86
- end
87
-
88
- # Errors
89
-
90
- context 'Response 403' do
91
- before do
92
- @client = BitlyQuickly.new access_token: 'token'
93
- end
94
-
95
- it 'raises an execption' do
96
- expect { @client.shorten('http://example.org/403') }.to raise_error(BitlyQuickly::RateLimitExceededError)
97
- end
98
- end
99
-
100
- context 'Response 503' do
101
- before do
102
- @client = BitlyQuickly.new access_token: 'token'
103
- end
104
-
105
- it 'raises an execption' do
106
- expect { @client.shorten('http://example.org/503') }.to raise_error(BitlyQuickly::TemporarilyUnavailableError)
107
- end
108
- end
109
-
110
- context 'Response 404' do
111
- before do
112
- @client = BitlyQuickly.new access_token: 'token'
113
- end
114
-
115
- it 'raises an execption' do
116
- expect { @client.shorten('http://example.org/404') }.to raise_error(BitlyQuickly::NotFoundError)
117
- end
118
- end
119
-
120
- context 'Response 500' do
121
- before do
122
- @client = BitlyQuickly.new access_token: 'token'
123
- end
124
-
125
- it 'raises an execption' do
126
- expect { @client.shorten('http://example.org/500') }.to raise_error(BitlyQuickly::InvalidRequestOrResponseError)
127
- end
128
- end
129
-
130
- context 'Response 666' do
131
- before do
132
- @client = BitlyQuickly.new access_token: 'token'
133
- end
134
-
135
- it 'raises an execption' do
136
- expect { @client.shorten('http://example.org/666') }.to raise_error(BitlyQuickly::UnknownError)
137
- end
138
- end
139
- end
@@ -1,37 +0,0 @@
1
- 1.upto(5) do |n|
2
- WebMock.stub_request(:get, %(https://api-ssl.bitly.com/v3/shorten?access_token=valid_token&longUrl=http://example.org/200/#{ n })).
3
- to_return(
4
- status: 200,
5
- body: %({ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/example.org\/200\/#{ n }", "url": "http:\/\/pht.io\/1eyUhF#{ n }", "hash": "1eyUhFo", "global_hash": "2V6CFi", "new_hash": 0 } })
6
- )
7
- end
8
-
9
- WebMock.stub_request(:get, 'https://api-ssl.bitly.com/v3/shorten?access_token=token&longUrl=http://example.org/403').
10
- to_return(
11
- status: 200,
12
- body: '{ "data": null, "status_code": 403, "status_txt": "RATE_LIMIT_EXCEEDED" }'
13
- )
14
-
15
- WebMock.stub_request(:get, 'https://api-ssl.bitly.com/v3/shorten?access_token=token&longUrl=http://example.org/404').
16
- to_return(
17
- status: 200,
18
- body: '{ "data": null, "status_code": 404, "status_txt": "NOT_FOUND" }'
19
- )
20
-
21
- WebMock.stub_request(:get, 'https://api-ssl.bitly.com/v3/shorten?access_token=token&longUrl=http://example.org/500').
22
- to_return(
23
- status: 200,
24
- body: '{ "data": null, "status_code": 500, "status_txt": "INVALID_URI" }'
25
- )
26
-
27
- WebMock.stub_request(:get, 'https://api-ssl.bitly.com/v3/shorten?access_token=token&longUrl=http://example.org/503').
28
- to_return(
29
- status: 200,
30
- body: '{ "data": null, "status_code": 503, "status_txt": "UNKNOWN_ERROR" }'
31
- )
32
-
33
- WebMock.stub_request(:get, 'https://api-ssl.bitly.com/v3/shorten?access_token=token&longUrl=http://example.org/666').
34
- to_return(
35
- status: 200,
36
- body: '{ "data": null, "status_code": 666, "status_txt": "WHO_KNOWS" }'
37
- )
data/spec/spec_helper.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'bundler/setup'
2
-
3
- require 'simplecov'
4
- require 'webmock' # Disable all HTTP access
5
-
6
- # Coverage tool, needs to be started as soon as possible
7
- SimpleCov.start do
8
- add_filter '/spec/' # Ignore spec directory
9
- end
10
-
11
- require 'request_stubs'
12
- require 'bitly_quickly'