Module: Rdwu::Write
- Included in:
- Api
- Defined in:
- lib/rdwu/write.rb
Instance Method Summary collapse
-
#create(payload) ⇒ Object
payload = { “web_redirect”: { “name”: “Api Name”, “to_url”: “ccd.com”, “is_permanent”: false, “is_enabled”: true, “expires_on”: “2025-12-28” } }.
- #delete(uuid) ⇒ Object
- #update(uuid, payload) ⇒ Object
Instance Method Details
#create(payload) ⇒ Object
payload = {
"web_redirect": {
"name": "Api Name",
"to_url": "http://ccd.com",
"is_permanent": false,
"is_enabled": true,
"expires_on": "2025-12-28"
}
}
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rdwu/write.rb', line 13 def create(payload) http = post_request('/api/v1/web_redirects', payload) if http.status == 200 || http.status == 201 body = JSON.parse(http.body) return body['data'] end return { 'errors': JSON.parse(http.body) } if http.status == 422 nil end |
#delete(uuid) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rdwu/write.rb', line 40 def delete(uuid) http = delete_request("/api/v1/web_redirects/#{uuid}") return true if http.status == 204 false end |
#update(uuid, payload) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rdwu/write.rb', line 26 def update(uuid, payload) http = post_request("/api/v1/web_redirects/#{uuid}", payload) if http.status == 200 body = JSON.parse(http.body) return body['data'] end return { 'errors': JSON.parse(http.body) } if http.status == 422 return { 'errors': { 'message': 'Not found!' } } if http.status == 404 nil end |