Module: Useless::Doc::Serialization::Load
- Defined in:
- lib/useless/doc/serialization/load.rb
Class Method Summary collapse
-
.api(json) ⇒ Core::API
Converts a JSON represntation to an instance of
Core::API. - .body(json) ⇒ Object private
- .body_attribute(json) ⇒ Object private
-
.domain(json) ⇒ Core::Domain
Converts a JSON represntation to an instance of
Core::Domain. - .header(json) ⇒ Object private
-
.json_to_hash(json) ⇒ Hash
Converts a JSON representation to a hash.
- .load(json) ⇒ Object
- .request(json) ⇒ Object private
- .request_parameter(json) ⇒ Object private
-
.resource(json) ⇒ Core::Resource
Converts a JSON represntation to an instance of
Core::Resource. - .response(json) ⇒ Object private
Class Method Details
.api(json) ⇒ Core::API
Converts a JSON represntation to an instance of Core::API
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/useless/doc/serialization/load.rb', line 76 def self.api(json) hash = json_to_hash json resources = (hash['resources'] || []).map do |json| resource json end = begin Time.parse(hash['timestamp']) rescue TypeError, ArgumentError nil end Useless::Doc::Core::API.new \ name: hash['name'], url: hash['url'], timestamp: , description: hash['description'], resources: resources end |
.body(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/useless/doc/serialization/load.rb', line 189 def self.body(json) hash = json_to_hash json attributes = (hash['attributes'] || []).map do |json| body_attribute json end Useless::Doc::Core::Body.new \ content_type: hash['content_type'], attributes: attributes end |
.body_attribute(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/useless/doc/serialization/load.rb', line 202 def self.body_attribute(json) hash = json_to_hash json Useless::Doc::Core::Body::Attribute.new \ key: hash['key'], type: hash['type'], required: hash['required'], default: hash['default'], description: hash['description'] end |
.domain(json) ⇒ Core::Domain
Converts a JSON represntation to an instance of Core::Domain
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/useless/doc/serialization/load.rb', line 47 def self.domain(json) hash = json_to_hash json apis = (hash['apis'] || []).map do |json| api json end = begin Time.parse(hash['timestamp']) rescue TypeError, ArgumentError nil end Useless::Doc::Core::Domain.new \ name: hash['name'], url: hash['url'], timestamp: , description: hash['description'], apis: apis end |
.header(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
180 181 182 183 184 185 186 |
# File 'lib/useless/doc/serialization/load.rb', line 180 def self.header(json) hash = json_to_hash json Useless::Doc::Core::Header.new \ key: hash['key'], description: hash['description'] end |
.json_to_hash(json) ⇒ Hash
Converts a JSON representation to a hash.
23 24 25 |
# File 'lib/useless/doc/serialization/load.rb', line 23 def self.json_to_hash(json) json.is_a?(Hash) ? json : Oj.load(json) end |
.load(json) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/useless/doc/serialization/load.rb', line 27 def self.load(json) hash = json_to_hash json if hash['apis'] self.domain(hash) elsif hash['url'] self.api(hash) elsif hash['path'] self.resource(hash) end end |
.request(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/useless/doc/serialization/load.rb', line 119 def self.request(json) hash = json_to_hash json parameters = (hash['parameters'] || []).map do |json| request_parameter json end headers = (hash['headers'] || []).map do |json| header json end if hash['body'] body = body hash['body'] end responses = (hash['responses'] || []).map do |json| response json end Useless::Doc::Core::Request.new \ method: hash['method'], description: hash['description'], authentication_required: hash['authentication_required'], parameters: parameters, headers: headers, body: body, responses: responses end |
.request_parameter(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/useless/doc/serialization/load.rb', line 168 def self.request_parameter(json) hash = json_to_hash json Useless::Doc::Core::Request::Parameter.new \ type: hash['type'], key: hash['key'], required: hash['required'], default: hash['default'], description: hash['description'] end |
.resource(json) ⇒ Core::Resource
Converts a JSON represntation to an instance of Core::Resource
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/useless/doc/serialization/load.rb', line 105 def self.resource(json) hash = json_to_hash json requests = (hash['requests'] || []).map do |json| request json end Useless::Doc::Core::Resource.new \ path: hash['path'], description: hash['description'], requests: requests end |
.response(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/useless/doc/serialization/load.rb', line 149 def self.response(json) hash = json_to_hash json headers = (hash['headers'] || []).map do |json| header json end if hash['body'] body = body hash['body'] end Useless::Doc::Core::Response.new \ code: hash['code'], description: hash['description'], headers: headers, body: body end |