Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Open Sourcing the Store
What we open sourced and how you can too!
Mike Nakhimovich - New York Times
Agenda For Today
Walkthrough of New York Times’ first Android
Open Source Library
How you can make open source a library
y...
Problem Set
Modern Android Apps need their data representations to be fluid and always
available.
Users expect their UI ex...
Android === Open Source
Libraries fill gaps left by framework
Network Client? OKHTTP/Retrofit
Threading/Functional Program...
Android === Open Source
Libraries fill gaps left by framework
Network Client? OKHTTP/Retrofit
Threading/Functional Program...
Introducing Store
https://github.com/NYTimes/Store
A Store abstracts fetching, parsing,
caching, and retrieval of data in
your application.
Stores are configurable and enforce
uni-direcitonal data flow while
exposing data as RxJava
Observables
Sounds Great, but how do I
use them?
Add to build.gradle
compile 'com.nytimes.android:store:1.0.1'
Open A Store
Store<Article> articleStore = StoreBuilder.<Article>builder()
.open();
Add a fetcher
public interface Fetcher<T> {
Observable<T> fetch(BarCode barCode);
}
Store<Article> articleStore = StoreBui...
Or NonObservable Fetcher
Use nonObservbleFetcher when connecting to a synchronous & non observable
API
Store<Article> arti...
Call your Store with a Barcode
...
BarCode barcode = new BarCode("Article", "42");
articleStore.fetch(barcode)
.subscribeO...
Fetch Dataflow (Unidirectional)
Same request <1min will
get throttled response
Getting Cached Data
articleStore.get(barcode)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer...
Note: if nothing
cached get() will act
exactly like fetch()
Get Dataflow
What happens if we
need to transform
response?
Adding a Parser
Adding a Parser
Store<Article> articleStore = ParsingStoreBuilder.<BufferedSource,
Article>builder()
.fetcher(barCode -> a...
Dataflow with Parser
Introducing Middleware
Use our Middleware
Before:
.parser(source -> {
try (InputStreamReader reader = new
InputStreamReader(source.inputStream())...
Use our Middleware
Before:
.parser(source -> {
try (InputStreamReader reader = new
InputStreamReader(source.inputStream())...
Disk Caching
ParsingStoreBuilder.<BufferedSource, Article>builder()
.fetcher(barCode -> api.getSource(barCode.getKey()))
....
Dataflow with Cache
No Need to implement
yourself
articleStore = ParsingStoreBuilder.<BufferedSource, Article>builder()
.fetcher(barCode -> ap...
Hope you’ll use Stores
And contribute back to the project
Part 2
How to go from 0 to Open
Source Project
Android Studio
Create a Project
Add a library module
Add some code to library
Use Android Studio to
create Github Project
Add a
Descriptive
Readme.md
● Who is project for?
● What was motivation for creation?
● What does it do?
● How does it do ...
Add a License
Part 2B: How to upload
project to Maven Central
Create a Sonatype Jira
Account (yes really)
Open A ticket to claim an organization
Wait for Response
Whats a GPG Key?
Use GPG to create a key
http://central.sonatype.org/pages/working-with-pgp-signatures.html
Add to top level gradle.properties
(don’t check into github!)
Add to library module gradle.properties
Add to top level build.gradle
Add Gradle Maven Plugin & Script
https://github.com/NYTimes/Store/blob/develop/gradle/maven-push.gradle
Run UploadArchives task
Go To Nexus Staging Repo to Verify
https://oss.sonatype.org/index.html#stagingRepositories
Close staging Repo and Deploy to Maven Central
Update jira with successful
first upload
Enable Travis
Add Travis.yml
Add Contributing.md
Submit a talk to GDG
Thanks for listening
Upcoming SlideShare
Loading in …5
×
Upcoming SlideShare
Advanced Dagger talk from 360andev
Next
Download to read offline and view in fullscreen.

2

Share

Open sourcing the store

Download to read offline

GDGNYC January 2017 talk about open sourcing https://github.com/NYTimes/Store

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Open sourcing the store

  1. 1. Open Sourcing the Store What we open sourced and how you can too! Mike Nakhimovich - New York Times
  2. 2. Agenda For Today Walkthrough of New York Times’ first Android Open Source Library How you can make open source a library yourself
  3. 3. Problem Set Modern Android Apps need their data representations to be fluid and always available. Users expect their UI experience to never be compromised (blocked) by new data loads International users expect minimal data downloads
  4. 4. Android === Open Source Libraries fill gaps left by framework Network Client? OKHTTP/Retrofit Threading/Functional Programming? RxJava Dependency Injection? Dagger View Bindings? Butterknife
  5. 5. Android === Open Source Libraries fill gaps left by framework Network Client? OKHTTP/Retrofit Threading/Functional Programming? RxJava Dependency Injection? Dagger View Bindings? Butterknife Store? Data Flow & Caching
  6. 6. Introducing Store https://github.com/NYTimes/Store
  7. 7. A Store abstracts fetching, parsing, caching, and retrieval of data in your application.
  8. 8. Stores are configurable and enforce uni-direcitonal data flow while exposing data as RxJava Observables
  9. 9. Sounds Great, but how do I use them?
  10. 10. Add to build.gradle compile 'com.nytimes.android:store:1.0.1'
  11. 11. Open A Store Store<Article> articleStore = StoreBuilder.<Article>builder() .open();
  12. 12. Add a fetcher public interface Fetcher<T> { Observable<T> fetch(BarCode barCode); } Store<Article> articleStore = StoreBuilder.<Article>builder() .fetcher(barCode -> api.getArticle(barCode.getKey())) .open();
  13. 13. Or NonObservable Fetcher Use nonObservbleFetcher when connecting to a synchronous & non observable API Store<Article> articleStore = StoreBuilder.<Article>builder() .nonObservableFetcher(barCode -> api.getArticle(barCode.getKey())) .open();
  14. 14. Call your Store with a Barcode ... BarCode barcode = new BarCode("Article", "42"); articleStore.fetch(barcode) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Article>() { public void onCompleted() {} public void onError(Throwable throwable) {//handle error} public void onNext(Article article) {//bind Article to UI}});
  15. 15. Fetch Dataflow (Unidirectional) Same request <1min will get throttled response
  16. 16. Getting Cached Data
  17. 17. articleStore.get(barcode) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Article>() { public void onCompleted() {} public void onError(Throwable throwable) {//handle error} public void onNext(Article article) {//bind Article to UI}}); Note: if nothing cached get() will act exactly like fetch() Getting Cached Data
  18. 18. Note: if nothing cached get() will act exactly like fetch() Get Dataflow
  19. 19. What happens if we need to transform response? Adding a Parser
  20. 20. Adding a Parser Store<Article> articleStore = ParsingStoreBuilder.<BufferedSource, Article>builder() .fetcher(barCode -> api.getSource(barCode.getKey())) .parser(source -> { try (InputStreamReader reader = new InputStreamReader(source.inputStream())) { return gson.fromJson(reader, Article.class); } catch (IOException e) { throw new RuntimeException(e);} }) .open();
  21. 21. Dataflow with Parser
  22. 22. Introducing Middleware
  23. 23. Use our Middleware Before: .parser(source -> { try (InputStreamReader reader = new InputStreamReader(source.inputStream())) { return gson.fromJson(reader, Article.class); } catch (IOException e) { throw new RuntimeException(e);} })
  24. 24. Use our Middleware Before: .parser(source -> { try (InputStreamReader reader = new InputStreamReader(source.inputStream())) { return gson.fromJson(reader, Article.class); } catch (IOException e) { throw new RuntimeException(e);} }) After: .parser(new GsonSourceParser<>(gson, Article.class))
  25. 25. Disk Caching ParsingStoreBuilder.<BufferedSource, Article>builder() .fetcher(barCode -> api.getSource(barCode.getKey())) .parser(new GsonSourceParser<>(gson, Article.class)) .persister(new Persister<BufferedSource>() { public Observable<BufferedSource> read(BarCode barCode) { return Observable.fromCallable(() -> diskCache.get(barCode)); } public Observable<Boolean> write(BarCode barCode, BufferedSource source) { diskCache.save(barCode, source); return Observable.just(true); }}) .open();
  26. 26. Dataflow with Cache
  27. 27. No Need to implement yourself articleStore = ParsingStoreBuilder.<BufferedSource, Article>builder() .fetcher(barCode -> api.getSource(barCode.getKey())) .parser(new GsonSourceParser<>(gson, Article.class)) .persister(new SourcePersister(FileSystemFactory.create(getFilesDir()))) .open();
  28. 28. Hope you’ll use Stores And contribute back to the project
  29. 29. Part 2 How to go from 0 to Open Source Project
  30. 30. Android Studio Create a Project
  31. 31. Add a library module
  32. 32. Add some code to library
  33. 33. Use Android Studio to create Github Project
  34. 34. Add a Descriptive Readme.md ● Who is project for? ● What was motivation for creation? ● What does it do? ● How does it do it?
  35. 35. Add a License
  36. 36. Part 2B: How to upload project to Maven Central
  37. 37. Create a Sonatype Jira Account (yes really)
  38. 38. Open A ticket to claim an organization
  39. 39. Wait for Response
  40. 40. Whats a GPG Key?
  41. 41. Use GPG to create a key http://central.sonatype.org/pages/working-with-pgp-signatures.html
  42. 42. Add to top level gradle.properties (don’t check into github!)
  43. 43. Add to library module gradle.properties
  44. 44. Add to top level build.gradle
  45. 45. Add Gradle Maven Plugin & Script https://github.com/NYTimes/Store/blob/develop/gradle/maven-push.gradle
  46. 46. Run UploadArchives task
  47. 47. Go To Nexus Staging Repo to Verify https://oss.sonatype.org/index.html#stagingRepositories
  48. 48. Close staging Repo and Deploy to Maven Central
  49. 49. Update jira with successful first upload
  50. 50. Enable Travis
  51. 51. Add Travis.yml
  52. 52. Add Contributing.md
  53. 53. Submit a talk to GDG
  54. 54. Thanks for listening
  • emanzanomarcos

    Apr. 7, 2017
  • williammdavis

    Jan. 10, 2017

GDGNYC January 2017 talk about open sourcing https://github.com/NYTimes/Store

Views

Total views

656

On Slideshare

0

From embeds

0

Number of embeds

17

Actions

Downloads

7

Shares

0

Comments

0

Likes

2

×