thiagoolsilva / twitterKtx

It is a kotlin library used to support developers to use the twitter API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project description

The goal of the project is help developers to use the twitter API

License Apache 2.0 minSdkVersion 23 compileSdkVersion 29

Project characteristics

This project brings to table set of best practices, tools, and solutions:

  • 100% Kotlin
  • Testing In progress
  • Dependency Injection
  • Static code analyse In progress
  • CI integration by gihub actions In progress

Tech-stack

What this project does not cover?

This project cover only the api standard Search Tweets. It is expected in the future to implement other API.

Setup

Create the required twitter.properties file

In order to the library works properly you must create a new file named twitter.properties on root folder with the key baseUrl.

// file project/twitter.properties
baseUrl="https://api.twitter.com/"

Gradle

There are a few ways to open this project.

Current Version

// latest stable
twitterktx_version = '1.0.0-beta-1'

Android Studio

  1. Android Studio -> File -> New -> From Version control -> Git
  2. Enter https://github.com/thiagoolsilva/twitterKtx into URL field

Command-line + Android Studio

  1. Run git clone https://github.com/thiagoolsilva/twitterKtx

Importing the lib on Android Studio

  1. With your project opened, go to settings.gradle file and insert the follow code
include ':twitterktx'
project(":twitterktx").projectDir = new File('TWITTERKTX_FOLDER')
  1. Finally, go to your preference module and insert the follow code to use the library on it
 implementation project(path: ':twitterktx')

QuickStart

Starting library

Init the twitterKtx in an application Android class.

There is two approach to do it on Application class.
  1. If you Koin as your dependency inject, you must use the code TwitterKtx.initKoinDependencies() after call startKoin{}.
 override fun onCreate() {
    startKoin{
        ...
    }
    TwitterKtx.initKoinDependencies()
 }

You can check it out this code on Application

  1. If you don't use Koin as your dependency inject, you must use the code TwitterKtx.init(this@Application).
override fun onCreate() {
    super.onCreate()
    TwitterKtx.init(this@Application)
 }

You can check it out this code on Application

Config Oauth2 bearer token

  1. First of all, you must get a valid oauth2bearer token running the follow curl code.
curl -X POST \
  https://api.twitter.com/oauth2/token \
  -H 'authorization: Basic INSERT_YOUR_TOKEN_HERE' \
  -H 'cache-control: no-cache' 
  -H 'content-type: application/x-www-form-urlencoded;charset=UTF-8'
The INSERT_YOUR_TOKEN_HERE  is a token in base64 composed by consumer key and secret. For more details go to [twitter](https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0)

It will return something like this:

{
    "token_type": "bearer",
    "access_token": "your_oauth2_token"
}

  1. Provide a valid oauth2 bearer token to library calling the function TwitterKtx.configToken(tokenAuth)

For more details about it you can go to FirstFragment

Using the library

  1. As the library uses coroutines, you must create a coroutine context to use it. In order to exemplify you can do it on Fragment as shown below.
viewModelScope.launch {

        ...
}

Don't forget to get the library implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$2.3.0-alpha02"

  1. Create a new instance of API library
 val standardSearchTweet = SearchTweetFactory().createStandardApi<StandardSearchTweetV1>(SearchTweetFactory.ApiType.V1)
  1. Call the API providing the required and optional parameters.
val tweets = standardSearchTweet.searchTweet(
                    query, mutableListOf(
                        StandardSearchTweetV1Api.COUNT to 20
                    )
                )
  1. Get the results. Happy coding! :D

Features

This section is related to the features/bug fixes of project.

Do you want to contribute?

I'd love if you contribute with the upcoming features or bug fixes. Go ahead and read the CONTRIBUTING file.

Upcoming features

You can check it out for new features on github.

Author

Follow me

Follow me Linkedin Twitter

License

Copyright (c) 2020  Thiago Lopes da Silva

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
`

About

It is a kotlin library used to support developers to use the twitter API

License:Other


Languages

Language:Kotlin 100.0%