wrapi 0.4.3 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/wrapi/entity.rb +10 -3
- data/lib/wrapi/request.rb +25 -13
- data/lib/wrapi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2879998432bd9b2be748b54c21024a68acf5cdba01ecc3040c9e9da45f02268
|
4
|
+
data.tar.gz: 63b482ee658b94a605f92faa52502efe1fa24bee5a918db27c773726f4a1e326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4913f5e123c1a2211e1c57b2b66e5712d1920ac667e38740d5047134fcc178aa82c1a509652da6f23ee16c54396025ed0959a4b95438d4026a2589b28de4d90e
|
7
|
+
data.tar.gz: 0772f0cdb948a5100df2f08a0fdaf356823f1fdfa0bb658817d3a3626540c54ec29cf92a9d1d4f83b2f957b990a73dce8c20bff8a537fd6e6c226aff7f956706
|
data/CHANGELOG.md
CHANGED
data/lib/wrapi/entity.rb
CHANGED
@@ -26,10 +26,11 @@ module WrAPI
|
|
26
26
|
|
27
27
|
def method_missing(method_sym, *arguments, &block)
|
28
28
|
# assignment
|
29
|
-
|
30
|
-
|
29
|
+
assignment = method_sym[/.*(?==\z)/m]
|
30
|
+
if assignment
|
31
|
+
raise ArgumentError, "wrong number of arguments (given #{arguments.length}, expected 1)", caller(1) unless arguments.length == 1
|
31
32
|
|
32
|
-
@attributes[
|
33
|
+
@attributes[assignment] = arguments[0]
|
33
34
|
elsif @attributes.include? method_sym.to_s
|
34
35
|
accessor(method_sym.to_s)
|
35
36
|
else
|
@@ -61,6 +62,12 @@ module WrAPI
|
|
61
62
|
@attributes[method]
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
def clone
|
67
|
+
c = super
|
68
|
+
c.attributes = @attributes.clone
|
69
|
+
c
|
70
|
+
end
|
64
71
|
|
65
72
|
def self.entify(a)
|
66
73
|
if ( a.count > 0 ) && ( a.first.is_a? Hash )
|
data/lib/wrapi/request.rb
CHANGED
@@ -5,11 +5,12 @@ module WrAPI
|
|
5
5
|
# Defines HTTP request methods
|
6
6
|
# required attributes format
|
7
7
|
module Request
|
8
|
-
|
8
|
+
CONTENT_TYPE_HDR = 'Content-Type'.freeze
|
9
9
|
# Perform an HTTP GET request and return entity incase format is :json
|
10
10
|
# @return if format is :json and !raw an [Entity] is returned, otherwhise the response body
|
11
11
|
def get(path, options = {}, raw=false)
|
12
12
|
response = request(:get, path, options) do |request|
|
13
|
+
# inject headers...
|
13
14
|
yield(request) if block_given?
|
14
15
|
end
|
15
16
|
entity_response(response, raw)
|
@@ -25,6 +26,7 @@ module WrAPI
|
|
25
26
|
pager = create_pager
|
26
27
|
while pager.more_pages?
|
27
28
|
response = request(:get, path, options.merge(pager.page_options)) do |req|
|
29
|
+
# inject headers...
|
28
30
|
request_labda.call(req) if request_labda
|
29
31
|
end
|
30
32
|
if d = pager.class.data(response.body)
|
@@ -32,11 +34,7 @@ module WrAPI
|
|
32
34
|
if block_given?
|
33
35
|
yield(d)
|
34
36
|
else
|
35
|
-
|
36
|
-
result += d
|
37
|
-
else
|
38
|
-
result << d
|
39
|
-
end
|
37
|
+
result = add_data(result,d)
|
40
38
|
end
|
41
39
|
end
|
42
40
|
pager.next_page!(response.body)
|
@@ -75,7 +73,7 @@ module WrAPI
|
|
75
73
|
format && 'json'.eql?(format.to_s)
|
76
74
|
end
|
77
75
|
|
78
|
-
|
76
|
+
private
|
79
77
|
|
80
78
|
def create_pager
|
81
79
|
pagination_class ? pagination_class.new(page_size) : WrAPI::RequestPagination::DefaultPager
|
@@ -85,7 +83,7 @@ module WrAPI
|
|
85
83
|
def request(method, path, options)
|
86
84
|
response = connection.send(method) do |request|
|
87
85
|
yield(request) if block_given?
|
88
|
-
request.headers[
|
86
|
+
request.headers[CONTENT_TYPE_HDR] = "application/#{format}" unless request.headers[CONTENT_TYPE_HDR]
|
89
87
|
uri = URI::Parser.new
|
90
88
|
_path = uri.parse(path)
|
91
89
|
_path.path = uri.escape(_path.path)
|
@@ -94,11 +92,7 @@ module WrAPI
|
|
94
92
|
request.url(_path.to_s, options)
|
95
93
|
when :post, :put
|
96
94
|
request.path = _path.to_s
|
97
|
-
|
98
|
-
request.body = options.to_json
|
99
|
-
else
|
100
|
-
request.body = URI.encode_www_form(options) unless options.empty?
|
101
|
-
end
|
95
|
+
set_body(request,options)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
response
|
@@ -111,5 +105,23 @@ module WrAPI
|
|
111
105
|
response
|
112
106
|
end
|
113
107
|
end
|
108
|
+
|
109
|
+
# set post body depending json content-type
|
110
|
+
def set_body(request,options)
|
111
|
+
if is_json? && !options.empty?
|
112
|
+
request.body = options.to_json
|
113
|
+
else
|
114
|
+
request.body = URI.encode_www_form(options) unless options.empty?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# add data to array and check if data itself is an array
|
119
|
+
def add_data(result,data)
|
120
|
+
if data.is_a? Array
|
121
|
+
result += data
|
122
|
+
else
|
123
|
+
result << data
|
124
|
+
end
|
125
|
+
end
|
114
126
|
end
|
115
127
|
end
|
data/lib/wrapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janco Tanis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|