Code Monkey home page Code Monkey logo

api_client_fun's Introduction

ApiClientFun

Welcome!

This is a basic ruby gem scaffold to create a client for call to an existing API endpoint.

The API's you will need to call is located at: https://blooming-savannah-20593.herokuapp.com/api/

You are tasked with creating a method that takes a user's name and returns their profile.

The api has two endpoints, responds with JSON, and is unauthenticated.

  1. https://blooming-savannah-20593.herokuapp.com/api/users

Returns a list of users.

  1. https://blooming-savannah-20593.herokuapp.com/api/users/{id}

Returns a specific user.

Zip up your code and send it along to the email instructed.

Have Fun!

=========================================================================================================

ApiClientFun sample output

Here, the main task is to fetch the user's profile details based on user name. Additionally allowing fetching users and fetching user by id from blooming savannah API to verify sample output.

run -> bundle exec ruby api_client_fun.rb

CASE I: With correct user name

shaik.basha@NITRVSP019LX api_client_fun (master) $ bundle exec ruby api_client_fun.rb

**************** START ******************

Calling Blooming Savannah API to fetch users

{"company"=>"Planet Express", "id"=>1, "name"=>"Philip J Fry", "position"=>"Delivery Boy", "profile"=>{"age"=>25, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>2, "name"=>"Turanga Leela", "position"=>"Captain", "profile"=>{"age"=>25, "gender"=>"F", "planet"=>"Earth", "species"=>"Mutant, Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>3, "name"=>"Bender Bending Rodríguez", "position"=>"Ship's Robot, Ship's Cook, Assistant Manager of Sales, Gunnery Chief", "profile"=>{"age"=>4, "gender"=>"M", "planet"=>"Earth", "species"=>"Robot", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>4, "name"=>"Planet Express Ship", "position"=>"Ship", "profile"=>{"age"=>"N/A", "gender"=>"N/A", "planet"=>"Earth", "species"=>"Robotic Spacecraft", "status"=>"N/A"}} {"company"=>"Planet Express", "id"=>5, "name"=>"Dr. John A. Zoidberg Ph.D", "position"=>"Staff Doctor", "profile"=>{"age"=>86, "gender"=>"M", "planet"=>"Decapod 10", "species"=>"Decapodian", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>6, "name"=>"Zapp Brannigan", "position"=>"Captain", "profile"=>{"age"=>28, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>7, "name"=>"Kif Kroker", "position"=>"Lieutenant", "profile"=>{"age"=>24, "gender"=>"M", "planet"=>"Amphibios 9", "species"=>"Amphibiosans", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>8, "name"=>"Philip J Fry", "position"=>"Delivery Boy", "profile"=>{"age"=>25, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>9, "name"=>"Turanga Leela", "position"=>"Captain", "profile"=>{"age"=>25, "gender"=>"F", "planet"=>"Earth", "species"=>"Mutant, Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>10, "name"=>"Bender Bending Rodríguez", "position"=>"Ship's Robot, Ship's Cook, Assistant Manager of Sales, Gunnery Chief", "profile"=>{"age"=>4, "gender"=>"M", "planet"=>"Earth", "species"=>"Robot", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>11, "name"=>"Planet Express Ship", "position"=>"Ship", "profile"=>{"age"=>"N/A", "gender"=>"N/A", "planet"=>"Earth", "species"=>"Robotic Spacecraft", "status"=>"N/A"}} {"company"=>"Planet Express", "id"=>12, "name"=>"Dr. John A. Zoidberg Ph.D", "position"=>"Staff Doctor", "profile"=>{"age"=>86, "gender"=>"M", "planet"=>"Decapod 10", "species"=>"Decapodian", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>13, "name"=>"Zapp Brannigan", "position"=>"Captain", "profile"=>{"age"=>28, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>14, "name"=>"Kif Kroker", "position"=>"Lieutenant", "profile"=>{"age"=>24, "gender"=>"M", "planet"=>"Amphibios 9", "species"=>"Amphibiosans", "status"=>"Alive"}}

Calling Blooming Savannah API to fetch user by passing ID

Enter User ID: 7

User Details: {"company"=>"Democratic Order of Planets", "id"=>7, "name"=>"Kif Kroker", "position"=>"Lieutenant", "profile"=>{"age"=>24, "gender"=>"M", "planet"=>"Amphibios 9", "species"=>"Amphibiosans", "status"=>"Alive"}}

Calling Blooming Savannah API to fetch user's profile info using username

Enter User Name: Planet Express Ship

Profile Details of user Planet Express Ship {"age"=>"N/A", "gender"=>"N/A", "planet"=>"Earth", "species"=>"Robotic Spacecraft", "status"=>"N/A"}

**************** END ******************

CASE II: With incorrect user name

**************** START ******************

Calling Blooming Savannah API to fetch users

{"company"=>"Planet Express", "id"=>1, "name"=>"Philip J Fry", "position"=>"Delivery Boy", "profile"=>{"age"=>25, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>2, "name"=>"Turanga Leela", "position"=>"Captain", "profile"=>{"age"=>25, "gender"=>"F", "planet"=>"Earth", "species"=>"Mutant, Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>3, "name"=>"Bender Bending Rodríguez", "position"=>"Ship's Robot, Ship's Cook, Assistant Manager of Sales, Gunnery Chief", "profile"=>{"age"=>4, "gender"=>"M", "planet"=>"Earth", "species"=>"Robot", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>4, "name"=>"Planet Express Ship", "position"=>"Ship", "profile"=>{"age"=>"N/A", "gender"=>"N/A", "planet"=>"Earth", "species"=>"Robotic Spacecraft", "status"=>"N/A"}} {"company"=>"Planet Express", "id"=>5, "name"=>"Dr. John A. Zoidberg Ph.D", "position"=>"Staff Doctor", "profile"=>{"age"=>86, "gender"=>"M", "planet"=>"Decapod 10", "species"=>"Decapodian", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>6, "name"=>"Zapp Brannigan", "position"=>"Captain", "profile"=>{"age"=>28, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>7, "name"=>"Kif Kroker", "position"=>"Lieutenant", "profile"=>{"age"=>24, "gender"=>"M", "planet"=>"Amphibios 9", "species"=>"Amphibiosans", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>8, "name"=>"Philip J Fry", "position"=>"Delivery Boy", "profile"=>{"age"=>25, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>9, "name"=>"Turanga Leela", "position"=>"Captain", "profile"=>{"age"=>25, "gender"=>"F", "planet"=>"Earth", "species"=>"Mutant, Human", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>10, "name"=>"Bender Bending Rodríguez", "position"=>"Ship's Robot, Ship's Cook, Assistant Manager of Sales, Gunnery Chief", "profile"=>{"age"=>4, "gender"=>"M", "planet"=>"Earth", "species"=>"Robot", "status"=>"Alive"}} {"company"=>"Planet Express", "id"=>11, "name"=>"Planet Express Ship", "position"=>"Ship", "profile"=>{"age"=>"N/A", "gender"=>"N/A", "planet"=>"Earth", "species"=>"Robotic Spacecraft", "status"=>"N/A"}} {"company"=>"Planet Express", "id"=>12, "name"=>"Dr. John A. Zoidberg Ph.D", "position"=>"Staff Doctor", "profile"=>{"age"=>86, "gender"=>"M", "planet"=>"Decapod 10", "species"=>"Decapodian", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>13, "name"=>"Zapp Brannigan", "position"=>"Captain", "profile"=>{"age"=>28, "gender"=>"M", "planet"=>"Earth", "species"=>"Human", "status"=>"Alive"}} {"company"=>"Democratic Order of Planets", "id"=>14, "name"=>"Kif Kroker", "position"=>"Lieutenant", "profile"=>{"age"=>24, "gender"=>"M", "planet"=>"Amphibios 9", "species"=>"Amphibiosans", "status"=>"Alive"}}

Calling Blooming Savannah API to fetch user by passing ID Enter User ID: 100

User Details: No user found with ID: 100

Calling Blooming Savannah API to fetch user's profile info using username Enter User Name: Abcd Xyz

Profile Details of user Abcd Xyz: No Profile found for user Abcd Xyz

**************** END ******************

api_client_fun's People

Contributors

lambcr avatar fazalbasha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.