wrapi 0.4.5 → 0.4.6
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/CHANGELOG.md +4 -1
- data/lib/wrapi/entity.rb +31 -19
- data/lib/wrapi/request.rb +7 -3
- 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: 5b7bed56656363a708f42ca25752e0d7235e9172e479a929e2f0c42674f42197
|
4
|
+
data.tar.gz: 0d0ea9163649d1da64a89c37c548dbb657a98f74fd0da8e3eb871c6994afe8f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81cc81edf7e4e9cf2d6b0c837e599332dd717d0914b87aba76ce56da736cdd588a43b863dcf9196e7eec8c86fbfb1df5e5d6586292a5f58c619487f8b7952bff
|
7
|
+
data.tar.gz: d1e12b22efcaf3ba181dd62407f9acf4e15e2f45f7c03848d8c076763fdd94ad9904f3b3751bd5491a00a820e0bec8ffd53bef60e910e4f541b4df9a04ed1be3
|
data/CHANGELOG.md
CHANGED
data/lib/wrapi/entity.rb
CHANGED
@@ -4,25 +4,31 @@ module WrAPI
|
|
4
4
|
# Defines HTTP request methods
|
5
5
|
module Request
|
6
6
|
class Entity
|
7
|
-
attr_reader :attributes
|
8
|
-
|
9
7
|
# factory method to create entity or array of entities
|
10
|
-
def self.create(
|
11
|
-
if
|
12
|
-
Entity.entify(
|
8
|
+
def self.create(attr)
|
9
|
+
if attr.is_a? Array
|
10
|
+
Entity.entify(attr)
|
13
11
|
else
|
14
|
-
Entity.new(
|
12
|
+
Entity.new(attr) if attr
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
def initialize(
|
19
|
-
case
|
16
|
+
def initialize(attr)
|
17
|
+
case attr
|
20
18
|
when Hash
|
21
|
-
@attributes =
|
19
|
+
@attributes = attr.clone.transform_keys(&:to_s)
|
22
20
|
else
|
23
|
-
@attributes =
|
21
|
+
@attributes = attr.clone
|
24
22
|
end
|
25
23
|
end
|
24
|
+
|
25
|
+
def attributes
|
26
|
+
@attributes || {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes= val
|
30
|
+
@attributes = val || {}
|
31
|
+
end
|
26
32
|
|
27
33
|
def method_missing(method_sym, *arguments, &block)
|
28
34
|
# assignment
|
@@ -40,6 +46,7 @@ module WrAPI
|
|
40
46
|
end
|
41
47
|
|
42
48
|
def respond_to?(method_sym, include_private = false)
|
49
|
+
@attributes ||= {}
|
43
50
|
if @attributes.include? method_sym.to_s
|
44
51
|
true
|
45
52
|
else
|
@@ -52,15 +59,15 @@ module WrAPI
|
|
52
59
|
end
|
53
60
|
|
54
61
|
def accessor(method)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
case @attributes[method]
|
63
|
+
when Hash
|
64
|
+
@attributes[method] = self.class.new(@attributes[method])
|
65
|
+
when Array
|
66
|
+
# make deep copy
|
67
|
+
@attributes[method] = Entity.entify(@attributes[method])
|
68
|
+
else
|
69
|
+
@attributes[method]
|
70
|
+
end
|
64
71
|
end
|
65
72
|
|
66
73
|
def clone
|
@@ -69,6 +76,11 @@ module WrAPI
|
|
69
76
|
c
|
70
77
|
end
|
71
78
|
|
79
|
+
def ==(other)
|
80
|
+
(self.class == other.class) && (self.attributes.eql? other.attributes)
|
81
|
+
end
|
82
|
+
alias eql? ==
|
83
|
+
|
72
84
|
def self.entify(a)
|
73
85
|
if ( a.count > 0 ) && ( a.first.is_a? Hash )
|
74
86
|
a.dup.map do |item|
|
data/lib/wrapi/request.rb
CHANGED
@@ -29,8 +29,7 @@ module WrAPI
|
|
29
29
|
# inject headers...
|
30
30
|
request_labda.call(req) if request_labda
|
31
31
|
end
|
32
|
-
|
33
|
-
d = Entity.create(d)
|
32
|
+
handle_data(response.body,pager) do |d|
|
34
33
|
if block_given?
|
35
34
|
yield(d)
|
36
35
|
else
|
@@ -114,7 +113,12 @@ module WrAPI
|
|
114
113
|
request.body = URI.encode_www_form(options) unless options.empty?
|
115
114
|
end
|
116
115
|
end
|
117
|
-
|
116
|
+
def handle_data(body,pager)
|
117
|
+
if d = pager.class.data(body)
|
118
|
+
d = Entity.create(d)
|
119
|
+
yield(d) if block_given?
|
120
|
+
end
|
121
|
+
end
|
118
122
|
# add data to array and check if data itself is an array
|
119
123
|
def add_data(result,data)
|
120
124
|
if data.is_a? Array
|
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.6
|
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-
|
11
|
+
date: 2024-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|