Ruby API client for Discount Network API
Add this line to your application's Gemfile:
gem "discountnetwork", "~> 0.1.1"
And then execute:
$ bundle
Once you have your API keys from Discount Network, then you can add an initializer to set up your API keys
DiscountNetwork.configure do |config|
config.api_key = "YOUR_API_KEY"
# Default configurations
# config.api_host = "https://api.discountnetwork.io/v1"
end
Session API allow you to authenticate a subscriber, create a new session or destroying an existing session.
Creating a new session will verify the subscriber and return the subscriber
object with subscription details.
DiscountNetwork::Session.create(
name: "username", password: "secret_password"
)
To retrieve the user account details using the Discount Network account
API
#
# The `auth_token` is optional, if you don't pass any
# parameter then it will try to retrieve the subscriber
# using the `auth_token` configuration.
#
DiscountNetwork::Account.find(auth_token)
To create a new user account you can use the Account.create
interface, but one
important things to remember that account creation is not available for all white
label, so if it's failing then most likely this feature is not supported on your
white label.
DiscountNetwork::Account.create(subscriber_attributes)
Once the user is logged in and auth_token
has been configured properly then
we can update the user details using the DiscountNetwork account
API
DiscountNetwork::Account.update(subscriber_attributes)
The activation
offers an easier way to find the subscriber details based on
the activation_token
. To find a subscriber
use
DiscountNetwork::Activation.find(activation_token)
Once subscriber has provided their required information then we can activate
their account using the Activation
API. The API already has validations in
place but it would be easier to implement some validation before sending any
activation API request.
DiscountNetwork::Activation.activate(
activation_token, subscriber_attributes
)
If the subscriber forgot their password then developer can allow them to reset their password using the Discount network API.
DiscountNetwork::Password.forgot(email_address)
Before allowing subscriber to reset their password, developer can validate if the reset token is valid or not as expired or invalid reset token won't allow subscriber to reset their password.
DiscountNetwork::Password.validate(reset_token)
Once subscriber has submitted a valid reset request and followed the instruction then we can allow them to set their password as follow
DiscountNetwork::Password.create(reset_token, password_attributes)
Each Discount Network subscription comes with varies number of supplementary subscribers, that means primary member can add one or more of this friends or family member to his subscription. The supplementary API provides an easier way to manage the supplementary subscribers. Please note, This interface expects that the subscriber has already been authenticated before making any API call.
To list all the supplementary subscribers for the authenticated subscriber
developer can use the list
interface for supplementary.
DiscountNetwork::Supplementary.list
To add a new supplementary subscriber with authenticated subscriber's
subscription developer can use the create
interface for supplementary.
DiscountNetwork::Supplementary.create(
subscriber_attributes
)
# subscriber attributes
subscriber_attributes = {
first_name: "John",
last_name: "Green",
phone: "+1 123 345 5678",
email: "[email protected]"
}
Retrieve the list of destinations based on a search term. This is useful when you are planning to show the list of destinations while user start to type destination name
DiscountNetwork::Destination.list(term: "bangkok")
You can create a new search using the API. Please note: It's advisable to wait 10-15 seconds before trying to retrieve the search results.
DiscountNetwork::Search.create(
adults: 2,
children: 0,
room_numbers: 1
location_id: 835,
check_in: "25/10/2016",
check_out: "28/10/2016",
location_name: "Bangkok, Thailand",
)
Once, you have created a new search and you have the search id then you can retrieve the search details as
DiscountNetwork::Search.find(search_id)
Retrieve the hotel search results from the Discount Network API.
DiscountNetwork::Result.where(
search_id: search_id
)
Retrieve the hotel details for a specific search
DiscountNetwork::Result.find_by(
search_id: search_id, hotel_id: hotel_id
)
Submit a new booking request for a specific hotel using the API.
# Creating a new booking request for a specific hotel, Pay close
# attention to the construction of the booking object
#
# If you want to add multiple travellers in one booking then
# pass an Array for travellers as
# `travellers: [traveller_one_attributes, traveller_two_attributes]`
#
# If you need to add multiple properties in one request, like one
# hotel and a condo in one booking request, then pass an Array as
#`properties: [property_one_attributes, property_two_attributes]`
DiscountNetwork::Booking.create(
hotel_id: "hotel_id",
search_id: "search_id",
travellers: traveller_attributes,
properties: property_attributes
)
# Traveller attributes
traveller_attributes = {
first_name: "John",
last_name: "Doe",
phone: "012 345 6789",
email: "[email protected]",
address: "123 Main Street",
city: "New York",
state: "New York",
zip: "NY10310"
}
# Property attributes
property_attributes = {
property_id: "property_101",
provider_name: "Booking.com",
name: "Nasa Vagas, Thailand",
price: "100.99",
description: "Description",
review_score: "90",
total_reviews: "10000",
currency_code: "USD"
}
To find the details for a specific booking request, including the confirmation number, use
DiscountNetwork::Booking.find(booking_id)
Discount Network partnered with multiple vendors to provide the best possible price in all sort of travel. This will allow developer to add those public provider in their site and let their subscriber search and contact the support to receive their subscriber discount.
This will allow developer to retrieve all of the specified public travel partner
so they can show them to their site. Note: They type
is mandatory and
the supported value for type
are hotel
, cruise
, resort
, tour
, package
and car
.
DiscountNetwork::Provider.where(type: "hotel")
On the provider listing API, one of the most important attribute
the API
returns is slug
, we can use that slug
to retrieve the details about any
specific provider.
DiscountNetwork::Provider.find_by_slug(slug)
We are following Sandi Metz's Rules for this gem, you can read the [description of the rules here] (http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers). All new code should follow these rules. If you make changes in a pre-existing file that violates these rules you should fix the violations as part of your contribution.
- Clone the repository.
git clone https://github.com/discountnetwork/discountnetwork-ruby.git
- Setup your environment.
bin/setup
- Run the test suite
bin/rake
- Setup API keys.
cp .sample.pryrc .pryrc
vim .pryrc
- Start your console.
bin/console
- Start playing with it.
DiscountNetwork::Session.create(name: "username", password: "password")
This gem provides an easier way to test Discount Network API Responses. Simply
include the following line in your spec_helper
and you should have access to
all of the test helpers.
require "discountnetwork/rspec"
First, thank you for contributing! We love pull requests from everyone. By participating in this project, you hereby grant the right to grant or transfer an unlimited number of non exclusive licenses or sub-licenses to third parties, under the copyright covering the contribution to use the contribution by all means.
Here are a few technical guidelines to follow:
- Open an issue to discuss a new feature.
- Write tests to support your new feature.
- Make sure the entire test suite passes locally and on CI.
- Open a Pull Request.
- Squash your commits after receiving feedback.
- Party!
The gem is available as open source under the terms of the MIT License.