Skip to content

Commit

Permalink
Setup remote config for ApiUrl and ApiKey
Browse files Browse the repository at this point in the history
  • Loading branch information
SriramPatibanda authored and abhibhaw committed Aug 17, 2021
1 parent 0a8e908 commit 155db44
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 5 deletions.
14 changes: 12 additions & 2 deletions aptiche/lib/services/graphql.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import 'package:aptiche/services/net/remote_config.dart';
import 'package:aptiche/utils/mutation.dart';
import 'package:aptiche/utils/query.dart';
import 'package:aptiche/datamodels/api_models.dart';
import 'package:aptiche/utils/string.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

class GraphQLService {
final RemoteConfigService _remoteConfigService = Get.find();

/// Stores the [GraphQLClient]
late GraphQLClient _client;

/// Intialises the [GraphQLClient]
Future<void> initGraphQL(String? token) async {
final HttpLink _httpLink = HttpLink(Strings.GRAPHQL_URL);
/// Initialise Remote Config.
await _remoteConfigService.setupRemoteConfig();

/// Get the apiUrl and apiKey from remote config.
final HttpLink _httpLink = HttpLink(
'${_remoteConfigService.apiUrl}?apikey=${_remoteConfigService.apiKey}',
);

final AuthLink _authLink = AuthLink(getToken: () async => 'Bearer $token');

final Link _link = _authLink.concat(_httpLink);
Expand Down
24 changes: 24 additions & 0 deletions aptiche/lib/services/net/remote_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:firebase_remote_config/firebase_remote_config.dart';

class RemoteConfigService {
late RemoteConfig remoteConfig;
Future<RemoteConfig> setupRemoteConfig() async {
try {
remoteConfig = RemoteConfig.instance;
remoteConfig.setDefaults(<String, dynamic>{
'api_url': 'https://aptiche.dscnitrourkela.org/graphql',
'api_key': 'SriramForTheDiro'
});
await remoteConfig.ensureInitialized();
await remoteConfig.fetchAndActivate();

return remoteConfig;
} catch (e) {
rethrow;
}
}

String get apiUrl => remoteConfig.getString('api_url');

String get apiKey => remoteConfig.getString('api_key');
}
2 changes: 2 additions & 0 deletions aptiche/lib/utils/bindings.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:aptiche/services/graphql.dart';
import 'package:aptiche/services/net/authservice.dart';
import 'package:aptiche/services/net/remote_config.dart';
import 'package:aptiche/services/third_party_services.dart';
import 'package:aptiche/views/dataentry/dataentry_controller.dart';
import 'package:aptiche/views/home/home_controller.dart';
Expand All @@ -10,6 +11,7 @@ import 'package:get/instance_manager.dart';
class HomeBinding implements Bindings {
@override
void dependencies() {
Get.put<RemoteConfigService>(RemoteConfigService());
Get.put<GraphQLService>(GraphQLService());
Get.put<AuthService>(AuthService());
Get.put<LoginController>(LoginController());
Expand Down
3 changes: 0 additions & 3 deletions aptiche/lib/utils/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ abstract class Strings {
//PNG Strings
static const String quizPNG = 'assets/images/quiz.png';

static const String GRAPHQL_URL =
'https://aptiche.dscnitrourkela.org/graphql?apikey=SriramForTheDiro';

static const String aboutText =
'Google Developer Student Clubs (GDSC) is a Google Developers powered program for university students to learn mobile and web development skills. The clubs will be open to any student interested to learn, ranging from novice developers who are just starting, to advanced developers who want to further their skills. The clubs are intended as a space for students to try out new ideas and collaborate to solve mobile and web development problems.\n\n'
'GDSC NIT Rourkela is a student chapter of GDSC India with a motive to nurture developers within the community and solve real-life problems in the community through technology.';
Expand Down
14 changes: 14 additions & 0 deletions aptiche/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
firebase_remote_config:
dependency: "direct main"
description:
name: firebase_remote_config
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.0+3"
firebase_remote_config_platform_interface:
dependency: transitive
description:
name: firebase_remote_config_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0+3"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions aptiche/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies:
graphql_flutter: ^5.0.0
intl: ^0.17.0
dartdoc: ^1.0.2
firebase_remote_config: ^0.10.0+3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 155db44

Please sign in to comment.