Socket
Socket
Sign inDemoInstall

github.com/greenvine/ebay-classifieds-api

Package Overview
Dependencies
12
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/greenvine/ebay-classifieds-api


Version published

Readme

Source

ebay-classifieds-api

GoDoc

This is an unofficial SDK for eBay Classifieds (ECG) API written in Go. To use the API, you must have partner access.

The module primarily consists of two components, ECG Agent and ECG Parser. The former sends the request to the API endpoint, whereas the latter parses the platform-dependent responses received from the endpoint. Currently, it implements APIs available in Australia but may also suitable for use in other countries.

Official API documentation provided by eBay Germany can be found here.

Installation

To install the module, simply run:

go get github.com/GreenVine/ebay-classifieds-api

Then import it within your project files whenever you need ECG Agent and/or ECG Parser (country-specific):

import (
    "github.com/GreenVine/ebay-classifieds-api"
    "github.com/GreenVine/ebay-classifieds-api/parsers/au"
)

Usage

Initialise the ECG Agent as follows and pass the API endpoint as base URL. Optionally, you can pass either authentication or authorization or both settings to the agent. Read more about security settings implemented in the API here.

ecg := ecg.Agent {
    Endpoint: "https://api.example.com/api", // API Endpoint
    ECGAuthentication: &ecg.Authentication{ // Authentication (optional)
        AuthenticateUser: "user",
        AuthenticateAd: "ad",
        AuthenticateDevice: "device",
    },
    ECGAuthorization: &ecg.Authorization{ // Authorization via HTTP Header (optional)
        Username: "user",
        Password: "password",
    },
}

Then request the API along with the URL and timeout (in milliseconds) settings:

advertisement, err := ecg.RequestEndpoint("/ads/123456", 2000)
category, err := ecg.RequestEndpoint("/ads", 10000)

ECG Agent will either return a XML document on success, or an EndpointErrorResponse type on failure. You will then need to use a country-specific parser to parse the advertisement or category response:

if err != nil { // erroneous HTTP response
   fmt.Println(*err.StatusCode, *err.Message)
} else { // successful response
   advert, errs, isFatal := auparser.ParseAdvert(advertisement) // parse an Advertisement
   cat, errs, isFatal := auparser.ParseCategory(category) // parse Advertisements in a category

   fmt.Println(advert.Title) // get advertisement title
   fmt.Println(cat.Pagination.CurrentPage) // get current page number
   
   jsonstr, _ := json.Marshal(advert)
   fmt.Println(string(jsonstr)) // or optionally print the entire advertisement response as JSON
}

FAQs

Last updated on 04 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc