Last active
March 23, 2022 02:16
-
-
Save rslhdyt/e5bd3222b07f0243acb4d7611dac788b to your computer and use it in GitHub Desktop.
Revisions
-
rslhdyt revised this gist
Mar 23, 2022 . 1 changed file with 22 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,32 +2,32 @@ class Api def initialize; end def get(path, params: {}) client.get(path, params) end def post(path, params: {}) client.post(path, params) end def put(path, params: {}) client.put(path, params) end def delete(path, params: {}) client.delete(path, params) end private def client @client ||= Faraday.new(base_url) do |faraday| faraday.adapter Faraday.default_adapter end end def base_url 'https://reqres.in/api/' end end -
rslhdyt revised this gist
Mar 23, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ require 'faraday' class Api def initialize; end def get(path, params: {}) client.get(path, params) end -
rslhdyt revised this gist
Mar 23, 2022 . No changes.There are no files selected for viewing
-
rslhdyt revised this gist
Mar 23, 2022 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,4 +24,18 @@ client = Api.new response = client.get('users') response_json = JSON.parse(response.body) response_json['data'] ``` ### result ``` [ {"id"=>1, "email"=>"[email protected]", "first_name"=>"George", "last_name"=>"Bluth", "avatar"=>"https://reqres.in/img/faces/1-image.jpg"}, {"id"=>2, "email"=>"[email protected]", "first_name"=>"Janet", "last_name"=>"Weaver", "avatar"=>"https://reqres.in/img/faces/2-image.jpg"}, {"id"=>3, "email"=>"[email protected]", "first_name"=>"Emma", "last_name"=>"Wong", "avatar"=>"https://reqres.in/img/faces/3-image.jpg"}, {"id"=>4, "email"=>"[email protected]", "first_name"=>"Eve", "last_name"=>"Holt", "avatar"=>"https://reqres.in/img/faces/4-image.jpg"}, {"id"=>5, "email"=>"[email protected]", "first_name"=>"Charles", "last_name"=>"Morris", "avatar"=>"https://reqres.in/img/faces/5-image.jpg"}, {"id"=>6, "email"=>"[email protected]", "first_name"=>"Tracey", "last_name"=>"Ramos", "avatar"=>"https://reqres.in/img/faces/6-image.jpg"} ] ``` -
rslhdyt created this gist
Mar 23, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ # Reqres.in API please see the link (https://reqres.in/) for list of endpoints ## Dependencies This API wrapper use Faraday client, please install faraday client in your local env ``` gem install faraday ``` ## How to use the API 1. save the api.rb 2. open IRB and load the api.rb ``` irb -I . -r api.rb ``` 3. call the API methods ``` client = Api.new response = client.get('users') response_json = JSON.parse(response.body) ``` This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ require 'faraday' class Api def initialize; end def get(path, params: {}) client.get(path, params) end def post(path, params: {}) client.post(path, params) end def put(path, params: {}) client.put(path, params) end def delete(path, params: {}) client.delete(path, params) end private def client @client ||= Faraday.new(base_url) do |faraday| faraday.adapter Faraday.default_adapter end end def base_url 'https://reqres.in/api/' end end