http_api_builder 0.2.2 → 0.2.3
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 +4 -4
- data/lib/http_api_builder.rb +3 -2
- data/lib/http_api_builder/client/http_rb.rb +2 -2
- data/lib/http_api_builder/helpers.rb +17 -0
- data/lib/http_api_builder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16f4c4049c99b8b57a337a7bca40772764900cb4
|
4
|
+
data.tar.gz: 8374854880f0ad10a5ae4d771acd67f2aa296056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3e8c5eb8d044ae54ae7560df211dad9047508232dad4a5ff0f77467f4ea2822f5220cd7c4f632c63aa26883391b36adb25b2dc11c203cb6cc822712338e39c4
|
7
|
+
data.tar.gz: 355de4a286c278978c3e908818e75b9a74fe3f864264bc2b2eae8a4bceb045cdf4db1315cc4ab2f80778cd5b91781741ef5481d8e1744d68dc973923e22ff8b8
|
data/lib/http_api_builder.rb
CHANGED
@@ -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
|
-
|
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 [
|
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,
|
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
|