Last active
December 23, 2019 11:54
-
-
Save linqueta/7c9bf0988d2141c2f92aebe1b6613be5 to your computer and use it in GitHub Desktop.
Integrating with JsonPlaceHolder API and Go Rest API - With Request options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GUIDE: https://jsonplaceholder.typicode.com/guide.html | |
# GUIDE: https://gorest.co.in/ | |
require 'eezee' | |
require 'post' | |
require 'user' | |
post_id = JsonPlaceHolder::Post.create!( | |
title: 'My new post', | |
body: 'It is my new post', | |
userId: 1 | |
).body[:id] | |
post = JsonPlaceHolder::Post.find!(100).body | |
post = JsonPlaceHolder::Post.update!( | |
post[:id], | |
title: 'My new post (Updated)', | |
body: 'It is my new post (Updated)' | |
).body | |
JsonPlaceHolder::Post.destroy!(post_id) | |
JsonPlaceHolder::Post.index! | |
GoRest::User.create!( | |
first_name: 'Linqueta', | |
last_name: 'Lincoln', | |
email: "linqueta_#{Random.rand(10..1000)}@linqueta.com", | |
gender: 'male' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JsonPlaceHolder; end | |
module JsonPlaceHolder::Post | |
extend Eezee::Client | |
module_function | |
eezee_request_options url: 'jsonplaceholder.typicode.com', | |
path: 'posts/:post_id', | |
protocol: :https, | |
logger: true, | |
headers: { 'Content-Type' => 'application/json' } | |
def index! | |
get | |
end | |
def find!(id) | |
get(params: { post_id: id }) | |
end | |
def create!(payload) | |
post(payload: payload) | |
end | |
def update!(id, payload) | |
put(params: { post_id: id }, payload: payload) | |
end | |
def destroy!(id) | |
delete(params: { post_id: id }) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GoRest; end | |
module GoRest::User | |
extend Eezee::Client | |
module_function | |
eezee_request_options url: 'gorest.co.in/public-api', | |
path: 'users/:user_id', | |
protocol: :https, | |
logger: true, | |
headers: { | |
'Content-Type' => 'application/json', | |
Authorization: 'Bearer Kz79g8huqeRtFjPsd-P2Th095S1KjHoUbykT' | |
}, | |
raise_error: true | |
def create!(payload) | |
post(payload: payload) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment