Class: Outbrain::Request
Constant Summary
Constants inherited from Config
Class Method Summary collapse
- .all(resource, options = {}) ⇒ Object
- .create(resource, options = {}) ⇒ Object
- .find(resource_path, id, options = {}) ⇒ Object
- .where(resource_path, query = {}, options = {}) ⇒ Object
Methods inherited from Config
Class Method Details
.all(resource, options = {}) ⇒ Object
16 17 18 |
# File 'lib/outbrain/request.rb', line 16 def self.all(resource, ={}) where(resource, {}, ) end |
.create(resource, options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/outbrain/request.rb', line 35 def self.create(resource, ={}) attributes = .fetch(:attributes, {}) response = api.post("/amplify/#{api_version}/#{resource}", attributes.to_json) json_body = JSON.parse(response.body) if response.status == 200 [:as].new(json_body) else a = [:as].new a.errors.push(json_body) a end end |
.find(resource_path, id, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/outbrain/request.rb', line 20 def self.find(resource_path, id, ={}) response = api.get("/amplify/#{api_version}/#{resource_path}/#{id}") json_body = JSON.parse(response.body) fail InvalidOption 'requires an as option' unless [:as] if response.status == 200 [:as].new(json_body) else a = [:as].new a.errors.push(json_body) a end end |
.where(resource_path, query = {}, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/outbrain/request.rb', line 4 def self.where(resource_path, query={}, ={}) response = api.get("/amplify/#{api_version}/#{resource_path}") resource_name = .fetch(:resource_name, resource_path) json_body = JSON.parse(response.body) # catch and raise proper api error fail InvalidOption 'requires an as option' unless [:as] json_body[resource_name].map do |obj| [:as].new(obj) end end |