Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Jan 16, 2020
0 parents commit e84cfb5
Show file tree
Hide file tree
Showing 25 changed files with 1,457 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Files and directories created by pub
.dart_tool/
.packages
# Remove the following pattern if you wish to check in your lock file
pubspec.lock

# Conventional directory for build outputs
build/

# Directory created by dartdoc
doc/api/

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

## Test config
test-unsplash-credentials.json
2 changes: 2 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/unsplash_client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- TODO
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
An unofficial client to for the [unsplash](https://unsplash.com) api.

This is a work in progress. At the moment only **Photos.list** and **Photos.random** are
implemented.

## Usage

A simple usage example:

```dart
import 'package:unsplash_client/client.dart';
void main() async {
// Create a client.
final client = UnsplashClient(
settings: Settings(
// Use the credentials from the developer portal.
credentials: AppCredentials(
accessKey: '...',
secretKey: '...',
)
),
);
// Fetch 5 random photos.
final response = await client.photos.random(count: 5).go();
// Check that the request was successful.
if (!response.isOk) {
throw 'Something is wrong: $response';
}
// Do something with the photos.
final photos = response.data;
// Create a dynamically resized url.
final resizedUrl = photos.first.urls.raw.resize(
width: 400,
height: 400,
fit: ResizeFitMode.cover,
format: ImageFormat.webp,
);
}
```
10 changes: 10 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include: package:effective_dart/analysis_options.1.2.0.yaml

linter:
rules:
- prefer_relative_imports

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
5 changes: 5 additions & 0 deletions lib/client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'src/app_credentials.dart';
export 'src/client.dart';
export 'src/model/model.dart';
export 'src/photos.dart';
export 'src/dynamic_resize.dart';
63 changes: 63 additions & 0 deletions lib/src/app_credentials.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:meta/meta.dart';

/// Credentials for accessing the unsplash api, as a registered app.
///
/// You need to [register](https://unsplash.com/developers) as a developer
/// and create an usnplash app to get credentials.
@immutable
class AppCredentials {
/// Creates [AppCredentials] from the given arguments.
const AppCredentials({
@required this.accessKey,
this.secretKey,
}) : assert(accessKey != null);

/// The access key of the app these [AppCredentials] belong to.
final String accessKey;

/// The secret key of the app these [AppCredentials] belong to.
final String secretKey;

/// Creates a copy of this instance, replacing non `null` fields.
AppCredentials copyWith({
String accessKey,
String secretKey,
}) {
return AppCredentials(
accessKey: accessKey ?? this.accessKey,
secretKey: secretKey ?? this.secretKey,
);
}

/// Serializes this instance to json.
Map<String, dynamic> toJson() {
return <String, dynamic>{
'accessKey': accessKey,
'secretKey': secretKey,
};
}

/// Deserializes [AppCredentials] from [json].
factory AppCredentials.fromJson(Map<String, dynamic> json) {
return AppCredentials(
accessKey: json['accessKey'] as String,
secretKey: json['secretKey'] as String,
);
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is AppCredentials &&
runtimeType == other.runtimeType &&
accessKey == other.accessKey &&
secretKey == other.secretKey;

@override
int get hashCode => accessKey.hashCode ^ secretKey.hashCode;

@override
String toString() {
return 'Credentials{accessKey: $accessKey, secretKey: $secretKey}';
}
}
Loading

0 comments on commit e84cfb5

Please # to comment.