Skip to content

Instantly share code, notes, and snippets.

View harshpyati's full-sized avatar
🎯
Focusing

Harsh Pyati harshpyati

🎯
Focusing
  • Bengaluru
View GitHub Profile
class RetroRepo {
val webservice: ApiInterface
init {
val builder = Retrofit.Builder()
.baseUrl("https://apodapis.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().create()))
.build()
webservice = builder.create(ApiInterface::class.java)
}
data class Photos(
val apod_site: String = "",
val copyright: String = "",
val date: String = "",
val description: String = "",
val hdurl: String = "",
val media_type: String = "",
val title: String = "",
val url: String = ""
)
interface ApiInterface {
@GET("/api/")
suspend fun getPhotos() : Photos
}
dependencies{
/* YOUR EXISTING DEPENDENCIES */
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha01"
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.core:core-ktx:1.2.0'
}
data class UserModel(
val userName : String?,
val userEmailId: String?,
val uuid: String?,
val accountCreatedAt: String?,
)
@harshpyati
harshpyati / streams3.dart
Created January 22, 2019 13:50
A gist to show the usage of streams in Dart
import 'dart:html';
import 'dart:async';
void main(){
final InputElement input = querySelector('input');
final DivElement div = querySelector('div');
final validator = new StreamTransformer.fromHandlers(
handleData: (inputValue,sink){
@harshpyati
harshpyati / streams2.dart
Created January 22, 2019 13:22
A gist to show the usage of Streams in Dart
// Model a Chocolate Cake factory using Streams
import 'dart:async';
void main(){
final controller = new StreamController();
/*once the controller is created, it gets 2 attributes
1. Sink - The order taker
2. Factory - Where the processing is done*/
@harshpyati
harshpyati / streams1.dart
Created January 22, 2019 13:21
A gist to show the usage of Streams in Dart.
import 'dart:html';
void main(){
final ButtonElement button = querySelector('button');
// Game: Click the button atleast once in a second otherwise you lose it
button.onClick
.timeout(
new Duration(seconds: 1),
@harshpyati
harshpyati / handling_future.dart
Created January 19, 2019 18:30
Gist to show the handling of Future while making 'get' http calls in Flutter
import 'dart:async';
main() async{
/*print('About to fetch the data');
get('http:/dkjsbkdsjbdl')
.then((result){
print(result);
});
*/
// Async Await Syntax:
@harshpyati
harshpyati / json.dart
Created January 19, 2019 17:55
A gist describing how data from json can be received in dart language
import 'dart:convert';
class ImageModel{
int id;
String url;
ImageModel(this.id,this.url);
ImageModel.fromJson(parsedJson){
this.id = parsedJson['id'];
this.url = parsedJson['url'];