http_api_builder 0.2.2 → 0.2.3

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: 523e286569e92c9ac943a7d3fc0c985d27cd37bf
4
- data.tar.gz: 4aa788219c64c7c59c9ca3905b1de37fce5bbec4
3
+ metadata.gz: 16f4c4049c99b8b57a337a7bca40772764900cb4
4
+ data.tar.gz: 8374854880f0ad10a5ae4d771acd67f2aa296056
5
5
  SHA512:
6
- metadata.gz: f62f4f82d40d7fdb6cd2663524e47327318ca3a91f428cbb80e8b443eec9926000d124359ae6dc8169ad4823ab8829aaedd3539dfe10c058c97268110b4d90a6
7
- data.tar.gz: d565433c4d53f9802c3d110aa48cd6921c5aabd8ddefdb94f9468ec0ef0f272d530bcdec313dcb26587ba8be8210e3133ab88b18c97dee3ec1a708204d6f7cf4
6
+ metadata.gz: b3e8c5eb8d044ae54ae7560df211dad9047508232dad4a5ff0f77467f4ea2822f5220cd7c4f632c63aa26883391b36adb25b2dc11c203cb6cc822712338e39c4
7
+ data.tar.gz: 355de4a286c278978c3e908818e75b9a74fe3f864264bc2b2eae8a4bceb045cdf4db1315cc4ab2f80778cd5b91781741ef5481d8e1744d68dc973923e22ff8b8
@@ -12,7 +12,8 @@ module HttpApiBuilder
12
12
 
13
13
  # Perform the request, post processors, and return the result
14
14
  def perform(method, path, form: nil, query: nil, body: nil, json: nil, &_block) # rubocop:disable Metrics/ParameterLists
15
- response = request(method, path, form: form, query: query, body: body, json: json)
15
+ url = build_url(path)
16
+ response = request(method, url, form: form, query: query, body: body, json: json)
16
17
  status = response.status
17
18
  resource = response.body
18
19
  block_given? ? yield(resource, status, response) : resource
@@ -22,7 +23,7 @@ module HttpApiBuilder
22
23
  # Accepts these params, for you to do whatever you like with. See the HTTPrb_client implementation
23
24
  #
24
25
  # @param [Symbol] method The HTTP VERB to use
25
- # @param [String, URI] path The path, excluding base_url, which should be prepended inside your implementation
26
+ # @param [Addressable::URI] uri The url to make the request to
26
27
  # @param [Hash] form: nil Form data, for encoding into HTTP form encoding
27
28
  # @param [Hash] query: nil Query key/value pairs
28
29
  # @param [String] body: nil A raw body
@@ -1,4 +1,5 @@
1
1
  require 'http'
2
+ require 'addressable/template'
2
3
 
3
4
  module HttpApiBuilder
4
5
  module Client
@@ -6,8 +7,7 @@ module HttpApiBuilder
6
7
  # This is functional and pretty much production ready, but you can
7
8
  # easily rewrite it to use curb or typhoeus or anything else really
8
9
  module HttpRb
9
- def request(verb, path, form:, query:, body:, json:) # rubocop:disable Metrics/ParameterLists
10
- url = URI.join(self.class.base_url || '', path)
10
+ def request(verb, url, form:, query:, body:, json:) # rubocop:disable Metrics/ParameterLists
11
11
  HTTP.send(verb, url, form: form, params: query, body: body, json: json)
12
12
  end
13
13
  end
@@ -71,5 +71,22 @@ module HttpApiBuilder
71
71
 
72
72
  raise ArgumentError, "unrecognized arguments: #{unrecognized.join(', ')}"
73
73
  end
74
+
75
+ # Handle's building paths
76
+ def build_url(path)
77
+ parsed_base = Addressable::URI.parse(self.class.base_url)
78
+ parsed_basepath = parsed_base.path.split('/').reject(&:empty?)
79
+
80
+ addressable_path = Addressable::URI.parse(path)
81
+
82
+ return addressable_path unless addressable_path.relative?
83
+ parsed_path = addressable_path.path.split('/').reject(&:empty?)
84
+
85
+ parsed_basepath += parsed_path
86
+
87
+ parsed_base.path = parsed_basepath.join('/')
88
+
89
+ parsed_base
90
+ end
74
91
  end
75
92
  end
@@ -1,3 +1,3 @@
1
1
  module HttpApiBuilder
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_api_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandberg