Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show followers and followings #40

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/common/translations/languages/de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class DeTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/en_gb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class EnGBTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/en_us.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class EnUSTranslations {
'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
Strings.followers: 'followers',
Strings.followings: 'followings',
Strings.events: 'Events',
Strings.poaps: 'POAPs',
Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ESTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
7 changes: 5 additions & 2 deletions lib/common/translations/languages/fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class FRTranslations {
'Vous ne semblez pas avoir de POAP pour l\'instant. Mais il n\'est pas trop tard ! Vous pouvez découvrir les POAPs en créeant votre premier POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
Strings.events: 'Évènements',
Strings.poaps: 'POAPs',
Strings.growth: 'croissance',
Expand Down Expand Up @@ -59,15 +61,16 @@ class FRTranslations {
Strings.newTagHint: 'nouveau tag d\'évènement',

/// Moments
Strings.momentsDesc: '''Votre collection de POAPs est votre identité numérique.
Strings.momentsDesc:
'''Votre collection de POAPs est votre identité numérique.
Elle montre au monde qui vous êtes : où vous êtes allé, ce que vous avez accompli et qui vous avez rencontré.
Moments est un moyen d'ajouter de la valeur à votre souvenir numérique en sauvegardant des instants de vie dans un POAP, pour toujours.''',
Strings.uploadMoments: 'Publier des moments sur welook.io',

/// GitPOAP
Strings.gitPOAPDesc:
'''Un GitPOAP est un POAP ordinaire (avec un petit extra) qui est frappé par la plateforme GitPOAP pour les contributions significatives apportées aux projets open source.
Les propriétaires de repos distribuent automatiquement des GitPOAPs à leurs contributeurs en reconnaissance du travail accompli.''',
Les propriétaires de repos distribuent automatiquement des GitPOAPs à leurs contributeurs en reconnaissance du travail accompli.''',
Strings.gitPOAPStart: 'Contribuer à POAPin',

/// Watchlist(Initial state)
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class JaTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/ko.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class KoTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class RuTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/th.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ThTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/tr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TrTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class UkTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/vi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ViTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/zh_cn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ZhCNTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/zh_hk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ZhHKTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
2 changes: 2 additions & 0 deletions lib/common/translations/languages/zh_tw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ZhTWTranslations {
// 'You don\'t appear to have any POAP right now.\nBut it\'s not too late!\n\nBegin learning about POAP by creating a POAP.',

/// Home(available)
// Strings.followers: 'followers',
// Strings.followings: 'followings',
// Strings.events: 'Events',
// Strings.poaps: 'POAPs',
// Strings.growth: 'growth',
Expand Down
4 changes: 4 additions & 0 deletions lib/common/translations/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Strings {

static const noPOAP = 'no_poap';

static const followers = 'followers';
static const followings = 'followings';
static const events = 'events';
static const poaps = 'poaps';
static const growth = 'growth';
Expand Down Expand Up @@ -119,6 +121,8 @@ String get strInvalidAddress => Strings.invalidAddress.tr;

String get strNoPOAP => Strings.noPOAP.tr;

String get strFollowers => Strings.followers.tr;
String get strFollowings => Strings.followings.tr;
String get strEvents => Strings.events.tr;
String get strPOAPs => Strings.poaps.tr;
String get strGrowth => Strings.growth.tr;
Expand Down
17 changes: 17 additions & 0 deletions lib/data/network/api/constant/poap_social.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// POAP followers backend
/// https://followers.poap.tech/api-doc/
class POAPSocialConstant {
POAPSocialConstant._();

static const String poapSocialUrl = "https://followers.poap.tech/v1";

/// ------------------------------------------------------------
/// Endpoints
/// ------------------------------------------------------------

/// Returns the accounts a specific account follows
static String followings(String address) => '/accounts/$address/followings';

/// Returns the accounts that follow the given account
static String followers(String address) => '/accounts/$address/followers';
}
31 changes: 31 additions & 0 deletions lib/data/network/api/poap_social.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:dio/dio.dart';
import 'package:poapin/data/network/api/constant/poap_social.dart';
import 'package:poapin/data/network/client/dio_poap_social.dart';

class POAPSocialAPI {
final DioPOAPSocialClient dioClient;

POAPSocialAPI({required this.dioClient});

Future<Response> getFollowings(String address) async {
try {
final Response response = await dioClient.get(
POAPSocialConstant.followings(address),
);
return response;
} catch (e) {
rethrow;
}
}

Future<Response> getFollowers(String address) async {
try {
final Response response = await dioClient.get(
POAPSocialConstant.followers(address),
);
return response;
} catch (e) {
rethrow;
}
}
}
113 changes: 113 additions & 0 deletions lib/data/network/client/dio_poap_social.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:dio/dio.dart';
import 'package:poapin/data/network/api/constant/base.dart';
import 'package:poapin/data/network/api/constant/poap_social.dart';

class DioPOAPSocialClient {
final Dio _dio = Dio();

DioPOAPSocialClient() {
_dio
..options.baseUrl = POAPSocialConstant.poapSocialUrl
..options.connectTimeout = BaseConstant.connectionTimeout
..options.receiveTimeout = BaseConstant.receiveTimeout
..options.responseType = ResponseType.json
..options.headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
};
}

Future<Response> get(
String url, {
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onReceiveProgress,
}) async {
try {
final Response response = await _dio.get(
url,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
onReceiveProgress: onReceiveProgress,
);
return response;
} catch (e) {
rethrow;
}
}

Future<Response> post(
String url, {
data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
try {
final Response response = await _dio.post(
url,
data: data,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
return response;
} catch (e) {
rethrow;
}
}

Future<Response> put(
String url, {
data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
try {
final Response response = await _dio.put(
url,
data: data,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress,
);
return response;
} catch (e) {
rethrow;
}
}

Future<dynamic> delete(
String url, {
data,
Map<String, dynamic>? queryParameters,
Options? options,
CancelToken? cancelToken,
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress,
}) async {
try {
final Response response = await _dio.delete(
url,
data: data,
queryParameters: queryParameters,
options: options,
cancelToken: cancelToken,
);
return response.data;
} catch (e) {
rethrow;
}
}
}
39 changes: 39 additions & 0 deletions lib/data/repository/poap_social_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:dio/dio.dart';
import 'package:poapin/data/network/api/poap_social.dart';
import 'package:poapin/data/network/exceptions.dart';

class POAPSocialRepository {
final POAPSocialAPI poapSocialAPI;

POAPSocialRepository(this.poapSocialAPI);

Future<List<String>> getFollowings(String address) async {
try {
final response = await poapSocialAPI.getFollowings(address);
if (response.statusCode == 200) {
final followings =
(response.data as List).map((f) => f.toString()).toList();
return followings;
}
return [];
} on DioError catch (e) {
final errorMessage = DioExceptions.fromDioError(e).toString();
throw errorMessage;
}
}

Future<List<String>> getFollowers(String address) async {
try {
final response = await poapSocialAPI.getFollowers(address);
if (response.statusCode == 200) {
final followings =
(response.data as List).map((f) => f.toString()).toList();
return followings;
}
return [];
} on DioError catch (e) {
final errorMessage = DioExceptions.fromDioError(e).toString();
throw errorMessage;
}
}
}
Loading