Coder Social home page Coder Social logo

rail's Introduction

rail

GoDoc Build Status Coverage Status Report card

rail is a Go client library for accessing the railwayapi.com API.

RailwayAPI.com provides API for Indian Railways data of Trains and Stations, along with features like Train Live status, PNR status, Arrivals on Station, Trains Between Stations etc

Installation

Requires Go version 1.7 or above.

$ go get -u github.com/go-india/rail

Usage

Construct a new rail client, then use the various methods on the client to access different parts of the RailwayAPI.

For demonstration:

package main

import (
  "context"
  "github.com/go-india/rail"
)

var ctx = context.Background()

func main() {
  client := rail.NewClient(API_KEY)

  // Gets PNR status details.
  resp, err := client.PNRStatus(ctx, 2124289856)

  // Gets Live running status of Train.
  resp, err := client.LiveTrainStatus(ctx, 14311, time.Now())

  // Gets fares of train.
  resp, err := client.TrainFare(ctx, 14311, "BE", "ADI", 24, "SL", "GN", time.Now())
}

Notes

  • Using the context package for passing context.
  • Make sure you have a valid API Key. If not, you can get a new one by registering at railwayapi.com registration page.

For complete usage of rail, see the full package docs.

Authentication

If you are using concrete Client, then you need to assign client.Auth field to make the client methods use authenticator for requests.

client := rail.Client{
  Auth: rail.NewAuth(API_KEY),
}

This will add API Key to each request made by client methods.

Integration Tests

You can run integration tests from the directory.

$ go test -v

Note: Use -update flag to update the testdata. When using update flag, you will need to define RAILWAYAPI_TEST_API_KEY in your environment for tests to use the API Key for testing.

Contributing

We welcome pull requests, bug fixes and issue reports. Before proposing a change, please discuss your change by raising an issue.

License

This library is distributed under the MIT license found in the LICENSE file.

Author

Yash Raj Singh

rail's People

Contributors

iamyashrs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rail's Issues

Separate Request/Response Objects

Right now, the library is built as a system build on both concrete request/response objects. Helpers combine the both of them into one.

But since the request/response objects are building blocks of the helpers, we can separate them out into 2 new sub-packages inside the repo. This will give us a clear usage and better docs.

import (
    "github.com/go-india/rail/req"
    "github.com/go-india/rail/resp"
    "github.com/go-india/rail"
)

The client and its helpers are the ultimate API/Usage of this library.
Other types and objects are building blocks of that.

Custom types

Right now, we haven't defined custom types for Quota, Class and StationCode fields of Requests. This decision has been taken as we don't want to limit the user's in future in their use of the library.

A proposal is to define custom types for these fields. And since they would be an alias of Go's inbuild types, they can be easily used.

type Quota string
type Class string
type StationCode string

This decision is pending. Discussions are always welcomed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.