endpointer 0.0.3 → 0.0.4

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: 80103af678623b6b3a044fb127198464eeeb71a8
4
- data.tar.gz: dfb7c6566395d2b087c70bbf7ef90fcd16dccd27
3
+ metadata.gz: e705dec6f55d6ae9e87f60e415451ec35f1826d7
4
+ data.tar.gz: f99559081ebf4ff13bc782e5c4d3dbe13a0f7fc1
5
5
  SHA512:
6
- metadata.gz: 93a4cdf6e55b2843ec0bd7eed665201f17953a816fcc521e6021b99f58b8fc74802eabc67e1295a6ee3208564ec627288c4162c5ed78d512e4d9089d861174ef
7
- data.tar.gz: e30e9d22a95f63a12cedd110d5f97a0038a2d16789db8ef069cd6fe67b582cf8e3da0e89acc7df18bb33e4d94173551e21c4c216fa620051f445dde955e5d9d1
6
+ metadata.gz: 231c82787a365665c0c322f0c4dd6c70a03c3a461db9771d98de63c37fa4b6c6f67ce6a90b10d580a59f88d19e8df4370b0a3c02336b27f54680f7c4ab85dffd
7
+ data.tar.gz: 2292181e7d9aaf294428cca8189d7ce6fae38a14ca37424b13d0a9842c929524530038d49c2dd230d92cb089cb9c58bd5cd035b2290210ae92cc95037a1d9b25
@@ -57,7 +57,7 @@ module Endpointer
57
57
  end
58
58
 
59
59
  def config_file?(argument)
60
- argument.match(/.json$/) || File.exists?(argument)
60
+ argument.match(/.json$/) || File.exist?(argument)
61
61
  end
62
62
 
63
63
  end
@@ -43,7 +43,7 @@ module Endpointer
43
43
  def initialize_path(path)
44
44
  begin
45
45
  @path = path
46
- Dir.mkdir(@path) unless File.exists?(@path)
46
+ Dir.mkdir(@path) unless File.exist?(@path)
47
47
  rescue Errno::ENOENT => e
48
48
  raise Endpointer::Errors::InvalidCacheDirError.new(e.message)
49
49
  end
@@ -15,8 +15,7 @@ module Endpointer
15
15
 
16
16
  def execute_method(method, request, resource)
17
17
  begin
18
- url = File.join(create_hostname(resource), create_path(request))
19
- response = RestClient::Request.execute(method: method, url: url, headers: create_headers(request, resource))
18
+ response = RestClient::Request.execute(method: method, url: construct_uri(request, resource), headers: create_headers(request, resource))
20
19
  rescue RestClient::ExceptionWithResponse => e
21
20
  response = e.response
22
21
  end
@@ -18,17 +18,16 @@ module Endpointer
18
18
  "HTTP_#{header_name.upcase.tr('-', '_')}"
19
19
  end
20
20
 
21
- def create_hostname(resource)
22
- host = URI.parse(resource.url).host
23
- port = URI.parse(resource.url).port
24
- "#{host}:#{port}"
25
- end
21
+ def construct_uri(request, resource)
22
+ parsed_request_url = URI.parse(request.url)
23
+ parsed_resource_url = URI.parse(resource.url)
24
+
25
+ parsed_request_url.scheme = parsed_resource_url.scheme
26
+ parsed_request_url.userinfo = parsed_resource_url.userinfo
27
+ parsed_request_url.host = parsed_resource_url.host
28
+ parsed_request_url.port = parsed_resource_url.port
26
29
 
27
- def create_path(request)
28
- path = request.path
29
- query_string = request.env['QUERY_STRING']
30
- path << "?#{query_string}" unless query_string.nil?
31
- path
30
+ parsed_request_url.to_s
32
31
  end
33
32
  end
34
33
  end
@@ -15,9 +15,8 @@ module Endpointer
15
15
 
16
16
  def execute_method(method, request, resource)
17
17
  begin
18
- url = File.join(create_hostname(resource), create_path(request))
19
18
  response = RestClient.send(method,
20
- url,
19
+ construct_uri(request, resource),
21
20
  request.body.read,
22
21
  create_headers(request, resource)
23
22
  )
@@ -7,7 +7,7 @@ module Endpointer
7
7
  def perform(request, resource, options)
8
8
  begin
9
9
  cache(options.cache_dir).get(resource)
10
- rescue Endpointer::Errors::CachedItemNotFoundError => e
10
+ rescue Endpointer::Errors::CachedItemNotFoundError
11
11
  response = Endpointer::PerformerFactory.create(resource.method).execute(request, resource)
12
12
  cache(options.cache_dir).set(resource, response)
13
13
  response
@@ -13,13 +13,13 @@ module Endpointer
13
13
 
14
14
  def uglify_headers(headers)
15
15
  headers.inject({}) { |out, (key, value)|
16
- out[key.to_s.upcase.gsub('_', '-')] = value
16
+ out[key.to_s.upcase.tr('_', '-')] = value
17
17
  out
18
18
  }
19
19
  end
20
20
 
21
21
  def sanitise_headers(headers)
22
- headers.reject {|header, value|
22
+ headers.reject {|header, _|
23
23
  header.match(/TRANSFER-ENCODING/)
24
24
  }
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Endpointer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: endpointer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zen Kyprianou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler