Code Monkey home page Code Monkey logo

swapi-android's Introduction

SWAPI SDK

SWAPI.co:

Download Demo App

This project is the main subject of the talk Declarative Dynamic UI, hosted by Android Developers Italia.

YouTube Video (italian) | Slides

Why?

This SDK and Demo App are made to have a common ground to promote discussions about:

  • Architecture
  • Technologies
  • Modeling
  • UI/UX
  • Approaches
  • ...whatever else comes to mind

Too often, we as developers are tied to the specific business domain on which we are working on and when the time comes to exchange ideas with other developers, some effort has to be made to de-contextualize what we are doing in our day-to-day job to present it to others.

This is a complete app which has various challenges to solve. It's not perfect and probably never will be, so feel free to open discussions about every aspect and tell your ideas. Also, this is only one in a million ways to achieve the same result.

You have many ways to use this repository:

  • Use the SDK as a Gradle dependency
  • Fork the project and modify the demo app, the SDK or both
  • Study it
  • Use it like a template for other projects
  • Contribute to this project with your own additions. Motivate them in Pull Requests.

Technology Stack

  • Kotlin + Coroutines
  • OkHttp 4
  • Moshi
  • Retrofit
  • ThreeTenABP

Using the library

implementation 'net.gotev:swapi-sdk:x.y.z'

Replace x.y.z with Download

Initialize it in your Application

class App : Application() {
    override fun onCreate() {
        super.onCreate()

        initializeSwapiClient(this)
    }
}

And then you can make requests from Coroutine Scopes to get data for each resource.

You can also pass in your own OkHttpClient instance if you have a global one in your app and decide if you want to use mirror or origin API server.

By default, to reduce loads on SWAPI.co, the client will point to the SWAPI mirror hosted on this project's GitHub Pages: https://gotev.github.io/swapi-android

All the domain models are also Parcelable so you can safely pass them as arguments.

swapiClient.species()
swapiClient.characters()
swapiClient.films()
swapiClient.species()
swapiClient.vehicles()
swapiClient.starships()

You will get a PagedResponse<T> from those API calls. From each one you can request previousPage() and nextPage().

To request a specific page of data for species, characters, films, species, vehicles and starships, you can pass a page value:

swapiClient.species(page = 2)

It's also possible to fetch a single resource from its URL. Each domain model has a unique URL. For example, to fetch https://swapi.co/api/people/1/

val lukeSkywalker = swapiClient.character("https://swapi.co/api/people/1/")

Mirror

This project has the ability to make a complete API mirror from SWAPI.co. Go into mirror directory and launch:

./fetch

This will update:

  • The JSONs used in SWAPI SDK unit tests, saved in fetched sub directory
  • The SWAPI.co API mirror in the docs directory, which is the GitHub Pages source

Dependency Updates

Keeping dependencies always up to date can be annoying. To ease things, a gradle plugin has been added which automatically checks for new versions. Just run:

./gradlew dependencyUpdates

And you will see a complete report of actual and new dependencies versions.

Release

Library can be released:

  • locally: ./release local. This is going to create a releases directory which can be used as a Maven Repository.

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.