Last active
December 23, 2019 11:54
-
-
Save linqueta/b1c44cd3cca5e321893fdf3fa866c750 to your computer and use it in GitHub Desktop.
Integrating with JsonPlaceHolder API and Go Rest API - With Service and 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 'initializer' | |
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
Eezee.configure do |config| | |
config.add_service :json_place_holder_api, | |
raise_error: true, | |
logger: true, | |
url: 'jsonplaceholder.typicode.com', | |
protocol: :https, | |
headers: { 'Content-Type' => 'application/json' } | |
config.add_service :go_rest_api, | |
url: 'gorest.co.in/public-api', | |
protocol: :https, | |
logger: true, | |
headers: { | |
'Content-Type' => 'application/json', | |
Authorization: 'Bearer Kz79g8huqeRtFjPsd-P2Th095S1KjHoUbykT' | |
}, | |
raise_error: true | |
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 JsonPlaceHolder; end | |
module JsonPlaceHolder::Post | |
extend Eezee::Client | |
module_function | |
eezee_service :json_place_holder_api | |
eezee_request_options path: 'posts/:post_id' | |
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_service :go_rest_api | |
eezee_request_options path: 'users/:user_id' | |
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