Skip to content

Commit

Permalink
fix: API authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wallen committed Mar 18, 2024
1 parent 8b2d94b commit 4eeb98b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 64 deletions.
1 change: 1 addition & 0 deletions lib/lemlist_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
library;

export 'src/lemlist_sdk.dart';
export 'src/models/models.dart';
4 changes: 2 additions & 2 deletions lib/src/lemlist_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class LemlistSDK {
}) : _dio = Dio(
BaseOptions(
baseUrl: 'https://api.lemlist.com',
headers: {
'Authorization': base64Encode(utf8.encode(':$apiKey')),
queryParameters: {
'access_token': apiKey,
},
),
);
Expand Down
51 changes: 48 additions & 3 deletions lib/src/models/lead_request.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'lead_request.freezed.dart';
part 'lead_request.g.dart';

/// A [LeadRequest] class.
@freezed
Expand All @@ -15,9 +14,55 @@ class LeadRequest with _$LeadRequest {
String? phone,
String? picture,
String? linkedinUrl,
String? website,
@Default({}) Map<String, dynamic> customFields,
}) = _LeadRequest;

const LeadRequest._();

/// Initializes a [LeadRequest] from JSON.
factory LeadRequest.fromJson(Map<String, dynamic> json) =>
_$LeadRequestFromJson(json);
factory LeadRequest.fromJson(Map<String, dynamic> json) {
const knownFields = {
'firstName',
'lastName',
'companyName',
'icebreaker',
'phone',
'picture',
'linkedinUrl',
'website',
};

// Extract customFields by filtering out known fields
final customFields = Map.fromEntries(
json.entries.where((entry) => !knownFields.contains(entry.key)),
);

return LeadRequest(
firstName: json['firstName'] as String?,
lastName: json['lastName'] as String?,
companyName: json['companyName'] as String?,
icebreaker: json['icebreaker'] as String?,
phone: json['phone'] as String?,
picture: json['picture'] as String?,
linkedinUrl: json['linkedinUrl'] as String?,
website: json['website'] as String?,
customFields: customFields,
);
}

/// Converts a [LeadRequest] to JSON.
Map<String, dynamic> toJson() {
return {
if (firstName != null) 'firstName': firstName,
if (lastName != null) 'lastName': lastName,
if (companyName != null) 'companyName': companyName,
if (icebreaker != null) 'icebreaker': icebreaker,
if (phone != null) 'phone': phone,
if (picture != null) 'picture': picture,
if (linkedinUrl != null) 'linkedinUrl': linkedinUrl,
if (website != null) 'website': website,
...customFields,
};
}
}
100 changes: 70 additions & 30 deletions lib/src/models/lead_request.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');

LeadRequest _$LeadRequestFromJson(Map<String, dynamic> json) {
return _LeadRequest.fromJson(json);
}

/// @nodoc
mixin _$LeadRequest {
String? get firstName => throw _privateConstructorUsedError;
Expand All @@ -27,8 +23,9 @@ mixin _$LeadRequest {
String? get phone => throw _privateConstructorUsedError;
String? get picture => throw _privateConstructorUsedError;
String? get linkedinUrl => throw _privateConstructorUsedError;
String? get website => throw _privateConstructorUsedError;
Map<String, dynamic> get customFields => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$LeadRequestCopyWith<LeadRequest> get copyWith =>
throw _privateConstructorUsedError;
Expand All @@ -47,7 +44,9 @@ abstract class $LeadRequestCopyWith<$Res> {
String? icebreaker,
String? phone,
String? picture,
String? linkedinUrl});
String? linkedinUrl,
String? website,
Map<String, dynamic> customFields});
}

/// @nodoc
Expand All @@ -70,6 +69,8 @@ class _$LeadRequestCopyWithImpl<$Res, $Val extends LeadRequest>
Object? phone = freezed,
Object? picture = freezed,
Object? linkedinUrl = freezed,
Object? website = freezed,
Object? customFields = null,
}) {
return _then(_value.copyWith(
firstName: freezed == firstName
Expand Down Expand Up @@ -100,6 +101,14 @@ class _$LeadRequestCopyWithImpl<$Res, $Val extends LeadRequest>
? _value.linkedinUrl
: linkedinUrl // ignore: cast_nullable_to_non_nullable
as String?,
website: freezed == website
? _value.website
: website // ignore: cast_nullable_to_non_nullable
as String?,
customFields: null == customFields
? _value.customFields
: customFields // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
) as $Val);
}
}
Expand All @@ -119,7 +128,9 @@ abstract class _$$LeadRequestImplCopyWith<$Res>
String? icebreaker,
String? phone,
String? picture,
String? linkedinUrl});
String? linkedinUrl,
String? website,
Map<String, dynamic> customFields});
}

/// @nodoc
Expand All @@ -140,6 +151,8 @@ class __$$LeadRequestImplCopyWithImpl<$Res>
Object? phone = freezed,
Object? picture = freezed,
Object? linkedinUrl = freezed,
Object? website = freezed,
Object? customFields = null,
}) {
return _then(_$LeadRequestImpl(
firstName: freezed == firstName
Expand Down Expand Up @@ -170,24 +183,33 @@ class __$$LeadRequestImplCopyWithImpl<$Res>
? _value.linkedinUrl
: linkedinUrl // ignore: cast_nullable_to_non_nullable
as String?,
website: freezed == website
? _value.website
: website // ignore: cast_nullable_to_non_nullable
as String?,
customFields: null == customFields
? _value._customFields
: customFields // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,
));
}
}

/// @nodoc
@JsonSerializable()
class _$LeadRequestImpl implements _LeadRequest {
class _$LeadRequestImpl extends _LeadRequest {
const _$LeadRequestImpl(
{this.firstName,
this.lastName,
this.companyName,
this.icebreaker,
this.phone,
this.picture,
this.linkedinUrl});

factory _$LeadRequestImpl.fromJson(Map<String, dynamic> json) =>
_$$LeadRequestImplFromJson(json);
this.linkedinUrl,
this.website,
final Map<String, dynamic> customFields = const {}})
: _customFields = customFields,
super._();

@override
final String? firstName;
Expand All @@ -203,10 +225,20 @@ class _$LeadRequestImpl implements _LeadRequest {
final String? picture;
@override
final String? linkedinUrl;
@override
final String? website;
final Map<String, dynamic> _customFields;
@override
@JsonKey()
Map<String, dynamic> get customFields {
if (_customFields is EqualUnmodifiableMapView) return _customFields;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_customFields);
}

@override
String toString() {
return 'LeadRequest(firstName: $firstName, lastName: $lastName, companyName: $companyName, icebreaker: $icebreaker, phone: $phone, picture: $picture, linkedinUrl: $linkedinUrl)';
return 'LeadRequest(firstName: $firstName, lastName: $lastName, companyName: $companyName, icebreaker: $icebreaker, phone: $phone, picture: $picture, linkedinUrl: $linkedinUrl, website: $website, customFields: $customFields)';
}

@override
Expand All @@ -225,40 +257,44 @@ class _$LeadRequestImpl implements _LeadRequest {
(identical(other.phone, phone) || other.phone == phone) &&
(identical(other.picture, picture) || other.picture == picture) &&
(identical(other.linkedinUrl, linkedinUrl) ||
other.linkedinUrl == linkedinUrl));
other.linkedinUrl == linkedinUrl) &&
(identical(other.website, website) || other.website == website) &&
const DeepCollectionEquality()
.equals(other._customFields, _customFields));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, firstName, lastName, companyName,
icebreaker, phone, picture, linkedinUrl);
int get hashCode => Object.hash(
runtimeType,
firstName,
lastName,
companyName,
icebreaker,
phone,
picture,
linkedinUrl,
website,
const DeepCollectionEquality().hash(_customFields));

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$LeadRequestImplCopyWith<_$LeadRequestImpl> get copyWith =>
__$$LeadRequestImplCopyWithImpl<_$LeadRequestImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$LeadRequestImplToJson(
this,
);
}
}

abstract class _LeadRequest implements LeadRequest {
abstract class _LeadRequest extends LeadRequest {
const factory _LeadRequest(
{final String? firstName,
final String? lastName,
final String? companyName,
final String? icebreaker,
final String? phone,
final String? picture,
final String? linkedinUrl}) = _$LeadRequestImpl;

factory _LeadRequest.fromJson(Map<String, dynamic> json) =
_$LeadRequestImpl.fromJson;
final String? linkedinUrl,
final String? website,
final Map<String, dynamic> customFields}) = _$LeadRequestImpl;
const _LeadRequest._() : super._();

@override
String? get firstName;
Expand All @@ -275,6 +311,10 @@ abstract class _LeadRequest implements LeadRequest {
@override
String? get linkedinUrl;
@override
String? get website;
@override
Map<String, dynamic> get customFields;
@override
@JsonKey(ignore: true)
_$$LeadRequestImplCopyWith<_$LeadRequestImpl> get copyWith =>
throw _privateConstructorUsedError;
Expand Down
29 changes: 0 additions & 29 deletions lib/src/models/lead_request.g.dart

This file was deleted.

0 comments on commit 4eeb98b

Please sign in to comment.