Skip to content

Codebase Explanation

Jason Kim edited this page Aug 1, 2016 · 7 revisions

Codebase Explanation

Directory Structure

Some files may be added and removed over time, but the directory structure should largely remain the same.

.
├── Gemfile
├── LICENSE.txt
├── README.md
├── Rakefile
├── bin
│   ├── console
│   └── setup
├── lib
│   ├── napster
│   │   ├── client.rb
│   │   ├── me.rb
│   │   ├── models
│   │   │   ├── album.rb
│   │   │   ├── artist.rb
│   │   │   ├── chart.rb
│   │   │   ├── content.rb
│   │   │   ├── favorite.rb
│   │   │   ├── favorite_status.rb
│   │   │   ├── follower.rb
│   │   │   ├── following.rb
│   │   │   ├── library.rb
│   │   │   ├── library_date_time.rb
│   │   │   ├── member.rb
│   │   │   ├── playlist.rb
│   │   │   ├── profile.rb
│   │   │   ├── tag.rb
│   │   │   ├── track.rb
│   │   │   └── uploaded_image.rb
│   │   ├── moniker.rb
│   │   ├── request.rb
│   │   ├── response_error.rb
│   │   └── version.rb
│   ├── napster.rb
│   └── string_helper.rb
├── napster-0.1.0.gem
├── napster.gemspec
└── spec
    ├── client_spec_helper.rb
    ├── config_loader.rb
    ├── fixture_loader.rb
    ├── fixtures
    │   ├── albums_top.json
    │   ├── artists_top.json
    │   ├── genres.json
    │   ├── main.json
    │   ├── member.json
    │   ├── playlists.json
    │   └── tracks_top.json
    ├── lib
    │   └── napster
    │       ├── client_spec.rb
    │       ├── me_spec.rb
    │       ├── models
    │       │   ├── album_spec.rb
    │       │   ├── artist_spec.rb
    │       │   ├── chart_spec.rb
    │       │   ├── content_spec.rb
    │       │   ├── favorite_spec.rb
    │       │   ├── favorite_status_spec.rb
    │       │   ├── library_date_time.rb
    │       │   ├── library_spec.rb
    │       │   ├── member_spec.rb
    │       │   ├── playlist_spec.rb
    │       │   ├── profile_spec.rb
    │       │   ├── tag_spec.rb
    │       │   ├── track_spec.rb
    │       │   └── uploaded_image_spec.rb
    │       ├── request_spec.rb
    │       └── response_error_spec.rb
    ├── napster_spec.rb
    └── spec_helper.rb

Annotations

napster.gemspec

This file is what rubygems.org looks at in order to determine metadata about the Napster gem. You can add gem dependencies and development dependencies here. Do not use Gemfile to add new dependencies.

Gemfile

Use napster.gemspec for all gem dependency management.

lib/napster.rb

All the new files introduced should be required here. Also if a gem (like faraday and oj) is used globally in the Napster gem, you can require the gem here.

lib/string_helper.rb

This is a one-off module that's used to monkey patch a method for String.

lib/napster/client.rb

The Client class is responsible for calling Naster API. To use, Napster gem, we begin by instantiating a client from the Client class. Authentications are made through a client. Also metadata and authenticated calls are all made through a client. The Client class has get, put, post, delete methods that are used to make requests to Napster API.

lib/napster/me.rb

The Me class is responsible for calling all authenticated calls to Napster API that starts with /me namespace.

lib/napster/moniker.rb

The Moniker module includes a method that can be used to validate IDs for Napster API.

lib/napster/request.rb

The Request class creates a Faraday client used to make requests.

lib/napster/response_error.rb

The ResponseError class is used when the client receives an error from Napster API. The ResponseError class inherits from Faraday::Error.

lib/napster/version.rb

Bump the version here whenever a new version is released.

lib/napster/models/*.rb

The model classes are used to wrap the response body from Napster API. Example classes are Artist, Album, and Tracks. Some example like Library do not contain any data from responses, but it provides a namespace to other calls for /me/library.

spec/..

This directory contains all files related to rspec.