polr 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +2 -0
- data/Rakefile +7 -5
- data/bin/console +4 -3
- data/lib/polr.rb +2 -0
- data/lib/polr/api.rb +19 -13
- data/lib/polr/version.rb +3 -1
- data/polr.gemspec +14 -13
- metadata +19 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 67c16ae753e255a2bc68fac6d20e442977be1fb440d35e07b5363957d5338425
|
4
|
+
data.tar.gz: 4badac999202579468694af07a16a9cdf899996a1cac171763c009a63b95b3b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1d16a0fcf3a7c5e0b6380283ce3fa4ed620edc04c8d6d28e5b60147f15f5def391c45cba4326ef660e1d8a4dbcc2ba9ac83a1d3d71aabaf6d0b9c4decf77aa2
|
7
|
+
data.tar.gz: 7dbec61407b464ee3a052a8719abac3491bdd33686f6494869fad8cf8dcfbc3e786998f1ea41ecaed503d2be827f785254be8e0b0f18945083846d93aff02865
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
7
9
|
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'polr'
|
5
6
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +11,5 @@ require "polr"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/lib/polr.rb
CHANGED
data/lib/polr/api.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rest-client'
|
2
4
|
require 'json'
|
3
5
|
|
4
6
|
module Polr
|
5
|
-
API_VERSION = 'v2'
|
7
|
+
API_VERSION = 'v2'.freeze
|
6
8
|
|
7
9
|
Error = Class.new StandardError
|
8
10
|
|
9
11
|
module Api
|
10
|
-
def self.api_url
|
11
|
-
%
|
12
|
+
def self.api_url(path = nil)
|
13
|
+
%(#{Polr.configuration.api_url}/api/#{API_VERSION}/action/#{path})
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.api_key
|
@@ -18,26 +20,30 @@ module Polr
|
|
18
20
|
def self.process
|
19
21
|
JSON.parse(yield).with_indifferent_access
|
20
22
|
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e # API unreachable
|
21
|
-
raise Polr::Error
|
23
|
+
raise Polr::Error, 'Polr API is unreachable'
|
22
24
|
rescue RestClient::Exception => e # HTTP status error
|
23
|
-
result = (
|
24
|
-
|
25
|
+
result = (begin
|
26
|
+
JSON.parse(e.response)
|
27
|
+
rescue StandardError
|
28
|
+
{}
|
29
|
+
end)
|
30
|
+
raise Polr::Error, result['error'] || 'undefined error'
|
25
31
|
rescue JSON::ParserError => e # JSON error
|
26
|
-
raise Polr::Error
|
32
|
+
raise Polr::Error, e.message
|
27
33
|
end
|
28
34
|
|
29
|
-
def self.request
|
30
|
-
RestClient.get(
|
35
|
+
def self.request(path, params)
|
36
|
+
RestClient.get(Api.api_url(path.to_s), params: params.merge(key: Api.api_key, response_type: :json), content_type: :json, accept: :json, timeout: 10)
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
34
40
|
# Actions to use
|
35
41
|
|
36
|
-
def self.shorten
|
37
|
-
Api
|
42
|
+
def self.shorten(url, **options)
|
43
|
+
Api.process { Api.request(:shorten, { url: url }.merge(options)) }
|
38
44
|
end
|
39
45
|
|
40
|
-
def self.lookup
|
41
|
-
Api
|
46
|
+
def self.lookup(url_ending, **options)
|
47
|
+
Api.process { Api.request(:lookup, { url_ending: url_ending }.merge(options)) }
|
42
48
|
end
|
43
49
|
end
|
data/lib/polr/version.rb
CHANGED
data/polr.gemspec
CHANGED
@@ -1,26 +1,27 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'polr/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'polr'
|
8
9
|
spec.version = Polr::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Fabien Dobat']
|
11
|
+
spec.email = ['fabien.dobat@seniormedia.fr']
|
11
12
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
13
|
+
spec.summary = 'Ruby wrapper for Polr API'
|
14
|
+
spec.description = 'A simple ruby wrapper to use your self hosted Polr API'
|
15
|
+
spec.homepage = 'https://github.com/SeniorMedia/polr-ruby'
|
16
|
+
spec.license = 'MIT'
|
16
17
|
|
17
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
20
21
|
|
21
|
-
spec.add_dependency 'rest-client'
|
22
|
+
spec.add_dependency 'rest-client', '~> 2'
|
22
23
|
|
23
|
-
spec.add_development_dependency 'bundler', '~>
|
24
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
25
25
|
spec.add_development_dependency 'minitest'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
27
|
end
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabien Dobat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
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: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '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: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
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: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '10.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '10.0'
|
69
69
|
description: A simple ruby wrapper to use your self hosted Polr API
|
70
70
|
email:
|
71
71
|
- fabien.dobat@seniormedia.fr
|
@@ -105,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
|
109
|
-
rubygems_version: 2.5.1
|
108
|
+
rubygems_version: 3.0.3
|
110
109
|
signing_key:
|
111
110
|
specification_version: 4
|
112
111
|
summary: Ruby wrapper for Polr API
|