gomojo

package module
v0.0.0-...-7685d40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2013 License: BSD-3-Clause Imports: 9 Imported by: 0

README

gomojo : Instamojo API Wrapper written in Go

This is an API wrapper package and a command-line tool to interface with Instamojo API, written in Go.

This is currently a work-in-progress, but then, what isn't in this world?

I initially wrote bits of this for Instamojo integration with an app backend. Now it's a Golang package that can be used to interact with the API. The latest is at https://github.com/dotmanish/gomojo

gomojo: is the Go package you can refer to from your Go sources.
gomojo-tool: is the command-line tool for using the API interactively.

Disclaimer: I am not affiliated with Instamojo other than being one of their merchant account customers. This (gomojo) is not officially endorsed by Instamojo team. That said, you should check out Instamojo if you haven't yet.

Install

You would want to do

go get github.com/dotmanish/gomojo/gomojo-tool

to download and install the gomojo package and the gomojo-tool binary. This requires you to have configured GOPATH variable correctly in your environment.

If you only want to grab the gomojo package, just use

go get github.com/dotmanish/gomojo

which will only retrieve the package, but not the command-line API tool.

Command-Line Tool Usage

Currently Available actions:

auth, deauth, listoffers, offerdetails, archiveoffer

Example usage of the command-line API tool:

gomojo-tool -action listoffers -app <your App-ID> -token <auth token>

gomojo-tool -action offerdetails -offerslug <offer slug> -app <your App-ID> -token <auth token>

gomojo-tool -action archiveoffer -offerslug <offer slug> -app <your App-ID> -token <auth token>

If you don't have a pre-generated Auth Token, you can either generate one first like this

gomojo-tool -action auth -app <your App-ID> -user <your username> -passwd <your password>

Or you can simply pass the username and password as command line parameters (note that this will generate an intermediate Auth Token, which will be destructed later) I will later add functionality to read username and password from a file.

gomojo-tool -action listoffers -app <your App-ID> -user <your username> -passwd <your password>

Sample output for 'listoffers':

Total 2 Offers
----------------------------
Offer # 1
Status:  Archived
Title:  Test Product 1
Slug:  test-product-1
ShortURL:
----------------------------
Offer # 2
Status:  Archived
Title:  Test Product 2
Slug:  test-product-2
ShortURL:
----------------------------

API Wrapper Package Usage

The source for gomojo-tool is a comprehensive sample for API wrapper usage. Check gomojo-tool.go for reference.

Typical usage would entail:

  1. import "github.com/dotmanish/gomojo"

  2. call InitGomojoWithAuthToken() or InitGomojoWithUserPass()

  3. call the Main APIs or Helper Functions

Currently available APIs:

Initialization:

InitGomojoWithAuthToken
InitGomojoWithUserPass

Main APIs:

ListOffers
GetOfferDetails
ArchiveOffer
UploadFile
CreateOffer
UpdateOffer
GetNewAuthToken
DeleteAuthToken

Helper Functions:

GetCurrentAuthToken

License

Use of this source code is governed by a BSD (3-Clause) License.

Copyright 2013 Manish Malik (manishmalik.name)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of this program/product nor the names of its contributors may
  be used to endorse or promote products derived from this software without
  specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveOffer

func ArchiveOffer(offer_slug string) (bool, string)

ArchiveOffer: archives an existing Offer Inputs: (Offer Slug string) Returns: (API success bool, Message string)

func DeleteAuthToken

func DeleteAuthToken(auth_token string) (bool, string)

DeleteAuthToken: deletes an existing Auth Token Inputs: (Auth Token string) Returns: (API success bool, Message string)

func GetCurrentAuthToken

func GetCurrentAuthToken() string

GetCurrentAuthToken: returns the current Auth Token Inputs: None Returns (Auth Token string)

func GetNewAuthToken

func GetNewAuthToken(username, password string) (string, bool, string)

GetNewAuthToken: gets a new Auth Token Inputs: (Username string, Password string) Returns: (Auth Token string, API success bool, Message string)

func InitGomojoWithAuthToken

func InitGomojoWithAuthToken(api_ver, app_id, auth_token string)

InitGomojoWithAuthToken: Initialize gomojo with Auth Token Inputs: (API version string, App ID string, Auth Token string)

func InitGomojoWithUserPass

func InitGomojoWithUserPass(api_ver, app_id, username, password string)

initGomojoWithUserPass: Initialize gomojo with username/password Inputs: (API version string, App ID string, Username string, Password string) Note: The username/password are internally stored in gomojo variables until the first attempt to call an API. Afterwards, these internal variables are blanked out.

func SetCurrentAuthToken

func SetCurrentAuthToken(auth_token string)

SetCurrentAuthToken: sets the current Auth Token Inputs: (Auth Token string)

func UploadFile

func UploadFile(file_path string) (bool, string, string, string)

UploadFile: uploads a File (content) or Cover Image Inputs: (File Path string) Returns: (API success bool, APUI Message string, UploadURL string, Upload-File JSON string)

Types

type ArchiveResponse

type ArchiveResponse struct {
	Message string `json:"message"`
	Success bool   `json:"success"`
}

ArchiveResponse: represents response of 'archiveoffer' DELETE API

type AuthResponse

type AuthResponse struct {
	Token   string `json:"token"`
	Message string `json:"message"`
	Success bool   `json:"success"`
}

AuthResponse: represents response of 'auth' POST API

type DeAuthResponse

type DeAuthResponse struct {
	Message string `json:"message"`
	Success bool   `json:"success"`
}

DeAuthResponse: represents response of 'auth' DELETE API

type FileUploadResonse

type FileUploadResonse struct {
	UploadURL  string `json:"upload_url"`
	Message    string `json:"message"`
	Success    bool   `json:"success"`
	UploadJSON string // Additional field populated later with upload response JSON
}

FileUploadResonse: represents response of 'getfileuploadurl' POST API

type ListOffersResponse

type ListOffersResponse struct {
	Offers  []Offer `json:"offers"`
	Success bool    `json:"success"`
	Message string  `json:"message"`
}

ListOffersResponse: represents response of 'offer' API

type Offer

type Offer struct {
	ShortURL       string `json:"shorturl"`
	Title          string `json:"title"`
	Slug           string `json:"slug"`
	Status         string `json:"status"`
	Description    string `json:"description"`
	Currency       string `json:"currency"`
	BasePrice      string `json:"base_price"`
	Quantity       string `json:"quantity"`
	StartDate      string `json:"start_date"`
	EndDate        string `json:"end_date"`
	Timezone       string `json:"timezone"`
	Venue          string `json:"venue"`
	RedirectURL    string `json:"redirect_url"`
	Note           string `json:"note"`
	FileUploadJSON string `json:"file_upload_json"`
	CoverImageJSON string `json:"cover_image_json"`
}

Offer: represents one Offer object (in list of offers) This is an amalgamation of the fields received as a result of various APIs (Offers List / Offer Details) Note that Offers List API doesn't populate everything.

func CreateOffer

func CreateOffer(offer Offer) (Offer, bool, string)

CreateOffer: create a new offer Inputs: (Offer object) Returns: (Offer object, API success bool, Message string)

func GetOfferDetails

func GetOfferDetails(offer_slug string) (Offer, bool, string)

GetOfferDetails: retrieves the details of a particular offer Inputs: (Offer-Slug string) Returns: (Offer object, API success bool, Message string)

func ListOffers

func ListOffers() ([]Offer, bool, string)

ListOffers: retrieves the list of all offers created under the given App(ID) Inputs: None Returns: (Offer object array, API success bool, Message string)

func UpdateOffer

func UpdateOffer(offer_slug string, offer Offer) (Offer, bool, string)

UpdateOffer: update an existing offer Inputs: (Offer-slug string, Offer object) Returns: (Offer object, API success bool, Message string)

type OfferDetailsResponse

type OfferDetailsResponse struct {
	Offer   Offer  `json:"offer"`
	Success bool   `json:"success"`
	Message string `json:"message"`
}

OfferDetailsResponse: represents response of 'offer' details,'createoffer','updateoffer' API

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL