vericred 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vericred/api_resource.rb +32 -19
- data/lib/vericred/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33dc91cd863234fdc18029ae075c592013916e44
|
4
|
+
data.tar.gz: a2d1989b06607f9bfb26d587a1985db654022734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fee62b0ece4317956b7d54cfa9745bf3a8cb0e5a4217f898360921dc386f679bae4d6900728ef96f9c6b359264b5af5b3e091acfe36a56019b65c452c84effb1
|
7
|
+
data.tar.gz: 34611b966590b139577978efbc6693b45c3d69441483430ac83d04efed1065cc580ec1c134c342f310e568d3f5eb3e97e7fd164a8b426213a8dbbf93a9444a7a
|
@@ -53,16 +53,14 @@ module Vericred
|
|
53
53
|
(data[root_name.pluralize] || []).map { |row| new(row, data) }
|
54
54
|
end
|
55
55
|
|
56
|
-
def initialize(
|
57
|
-
parse_relationships(
|
58
|
-
@data = OpenStruct.new(
|
56
|
+
def initialize(attrs, full_data = {})
|
57
|
+
parse_relationships(attrs, full_data)
|
58
|
+
@data = OpenStruct.new(attrs)
|
59
59
|
end
|
60
60
|
|
61
61
|
private
|
62
62
|
|
63
|
-
def self.
|
64
|
-
logger.info { "#{verb.to_s.upcase} #{uri} with #{args}"}
|
65
|
-
response = connection.send(verb, "#{BASE_URL}#{uri}", *args)
|
63
|
+
def self.handle_response(response)
|
66
64
|
case response.status
|
67
65
|
when 200..299 then JSON.parse(response.content)
|
68
66
|
when 401 then fail Vericred::UnauthenticatedError, response
|
@@ -73,26 +71,41 @@ module Vericred
|
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
74
|
+
def self.make_request(verb, uri, *args)
|
75
|
+
logger.info { "#{verb.to_s.upcase} #{uri} with #{args}"}
|
76
|
+
response = nil
|
77
|
+
ActiveSupport::Notifications
|
78
|
+
.instrument "vericred.http_request", opts: [verb, uri, *args] do
|
79
|
+
response = connection.send(verb, "#{BASE_URL}#{uri}", *args)
|
80
|
+
end
|
81
|
+
handle_response(response)
|
82
|
+
end
|
83
|
+
|
76
84
|
def method_missing(m, *args, &block)
|
77
85
|
return @data.send(m, *args, &block) if @data.respond_to?(m)
|
78
86
|
super
|
79
87
|
end
|
80
88
|
|
81
|
-
def
|
89
|
+
def parse_plural_relationship(relationship, attrs, full_data)
|
90
|
+
attrs[relationship.root_name] =
|
91
|
+
full_data[relationship.root_name]
|
92
|
+
.select { |row| attrs[relationship.foreign_key].include?(row['id'])}
|
93
|
+
.map { |row| OpenStruct.new(row) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_singular_relationship(relationship, attrs, full_data)
|
97
|
+
record = full_data[relationship.root_name]
|
98
|
+
.find { |row| row['id'] == attrs[relationship.foreign_key] }
|
99
|
+
attrs[relationship.root_name.singularize] =
|
100
|
+
record ? OpenStruct.new(record) : nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def parse_relationships(attrs, full_data)
|
82
104
|
relationships.values.map(&:values).flatten.each do |relationship|
|
83
105
|
next if full_data[relationship.root_name].blank?
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
attributes[relationship.root_name.singularize] =
|
89
|
-
record ? OpenStruct.new(record) : nil
|
90
|
-
else
|
91
|
-
attributes[relationship.root_name] =
|
92
|
-
full_data[relationship.root_name]
|
93
|
-
.select { |row| attributes[relationship.foreign_key].include?(row['id'])}
|
94
|
-
.map { |row| OpenStruct.new(row) }
|
95
|
-
end
|
106
|
+
relationship.singular? ?
|
107
|
+
parse_singular_relationship(relationship, attrs, full_data) :
|
108
|
+
parse_plural_relationship(relationship, attrs, full_data)
|
96
109
|
end
|
97
110
|
end
|
98
111
|
end
|
data/lib/vericred/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vericred
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Langevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|