phearb 1.0.1 → 1.1.0

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: 22bc3131cddf809780e9a7bdd8d2f3c08e82471c
4
- data.tar.gz: e0c6d31f128d5ba6513bb3541c7408481fee760e
3
+ metadata.gz: 9e84cc1692610bdae82f05d919ce92d819fe329c
4
+ data.tar.gz: 5c2dd78d4b1c9d4f2235e4b4e79337d9583f6bee
5
5
  SHA512:
6
- metadata.gz: 70280d364d983a9e5e7f74546222ca6b5bd05284cb12bd19b97ba3f1f3a6f74791c2e4742c75a6b4753c270c6a359517d64b1a0a1b175310709b279c04f4624e
7
- data.tar.gz: 5ad2927c60b0002b6b0f8ab94329fe4b3f3121f87078e6f1c82591be8d29321e95237bce82893cf18d0fc2fdd41ae19840443a2bdfe4c1d0fcb549eb45ae6815
6
+ metadata.gz: c1ea2f12f503cf0670754276979c3e2f84fcc0f2784ebf00381ba985ebadac2664d3376616423a5af1a3b1c57067e1004a39a73c4d20d9ff1614a506491e3236
7
+ data.tar.gz: 4e5df816ff94d67f8251b5b9de2d52df5abf2dbbfaf3c4275348345358fc1a6afea3b789940e3e35df2d7a05636bb80565a06ee43fc9c16b606cb1c4e1a45d00
data/README.md CHANGED
@@ -29,6 +29,7 @@ Put these lines in the configuration section of you app. In rails you should pro
29
29
  Phearb.configure do |config|
30
30
  config.host = <host> # Defaults to 'localhost'
31
31
  config.port = <port> # Defaults to 8100
32
+ config.timeout <timeout_in_seconds> # Defaults to 5
32
33
  end
33
34
  ```
34
35
 
@@ -39,7 +40,7 @@ puts response.content if response.success
39
40
  ```
40
41
 
41
42
  Simply calling `Phearb.fetch(<url>)` will do the job. It returns an `Phearb::Response` object wrapping the phearb server response with one method per key:
42
- ```
43
+ ```js
43
44
  {
44
45
  "success": true,
45
46
  "input_url": "http://such-website.com",
data/lib/phearb/agent.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rest_client'
2
2
  require 'phearb/response'
3
+ require 'phearb/error'
3
4
 
4
5
  module Phearb
5
6
  class Agent
@@ -9,8 +10,12 @@ module Phearb
9
10
  end
10
11
 
11
12
  def fetch
12
- http_response = RestClient.get(server_url, params: { fetch_url: @url })
13
- Response.from_json(http_response)
13
+ Timeout::timeout(Phearb.configuration.timeout.to_f) do
14
+ http_response = RestClient.get(server_url, params: { fetch_url: @url })
15
+ Response.from_json(http_response)
16
+ end
17
+ rescue Timeout::Error => exception
18
+ raise Error::Timeout
14
19
  end
15
20
 
16
21
  private
@@ -2,13 +2,16 @@ module Phearb
2
2
  class Configuration
3
3
  attr_accessor :host
4
4
  attr_accessor :port
5
+ attr_accessor :timeout
5
6
 
6
7
  DEFAULT_HOST = 'localhost'
7
8
  DEFAULT_PORT = 8100
9
+ DEFAULT_TIMEOUT = 5
8
10
 
9
11
  def initialize
10
12
  @host = DEFAULT_HOST
11
13
  @port = DEFAULT_PORT
14
+ @timeout = DEFAULT_TIMEOUT
12
15
  end
13
16
  end
14
17
  end
@@ -0,0 +1,3 @@
1
+ module Phearb::Error
2
+ class Timeout < StandardError; end
3
+ end
@@ -1,3 +1,3 @@
1
1
  module Phearb
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phearb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joaquín Moreira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-05 00:00:00.000000000 Z
11
+ date: 2016-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,6 +126,7 @@ files:
126
126
  - lib/phearb.rb
127
127
  - lib/phearb/agent.rb
128
128
  - lib/phearb/configuration.rb
129
+ - lib/phearb/error.rb
129
130
  - lib/phearb/response.rb
130
131
  - lib/phearb/version.rb
131
132
  - phearb.gemspec