Skip to content

Instantly share code, notes, and snippets.

@linqueta
Last active December 23, 2019 11:54
Show Gist options
  • Save linqueta/7c9bf0988d2141c2f92aebe1b6613be5 to your computer and use it in GitHub Desktop.
Save linqueta/7c9bf0988d2141c2f92aebe1b6613be5 to your computer and use it in GitHub Desktop.
Integrating with JsonPlaceHolder API and Go Rest API - With Request options
# 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'
)
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
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