Giter Club home page Giter Club logo

bricklink-api's Introduction

bricklink-api

Node.js CI

Node package for connecting to Bricklink's API.

npm install --save bricklink-api

Basic Usage

Initialize a client with your OAuth credentials as supplied at the following:

https://www.bricklink.com/v2/api/register_consumer.page

You are required to have a Bricklink account and register your IP address from which your application will be using the API. You can also use 0.0.0.0 to match any IP address (such as a cloud solution); however, you would need to keep the keys and secrets secure.

var api = require('bricklink-api');
var Client = api.Client,
    ItemType = api.ItemType;

var bricklink = new Client({
    "consumer_key": "<ConsumerKey>",
    "consumer_secret": "<ConsumerSecret>",
    "token": "<TokenValue>",
    "token_secret": "<TokenSecret>"
  });

bricklink.getCatalogItem(ItemType.Part, '3001')
  .then(function(part){
    console.log(part);
  });

\\ Alternate Usage:

var CatalogItem = api.CatalogItem;
var req = CatalogItem.get(ItemType.Part, '3001');
bricklink.send(req)
  .then(function(part){
    console.log(part);
  });

ES6 Support

Read basic usage.

import {Client, ItemType, CatalogItem} from 'bricklink-api';

const bricklink = new Client({
    "consumer_key": "<ConsumerKey>",
    "consumer_secret": "<ConsumerSecret>",
    "token": "<TokenValue>",
    "token_secret": "<TokenSecret>"
  });

bricklink.getCatalogItem(ItemType.Part, '3001')
  .then(part => console.log(part));

\\ Alternate Usage:

let req = CatalogItem.get(ItemType.Part, '3001');
bricklink.send(req)
  .then(part => console.log(part));

Documentation

Full API documentation is available at:

https://ryansh100.github.io/bricklink-api

Change Log

  • 2017/04/03: Fix bugs with require of dictionaries. Update to make more intuitive imports. Add support for color and category lookup.
  • 2021/05/01: Updating the compiling engine, updating the way tests are run

bricklink-api's People

Contributors

dependabot[bot] avatar ofir-shapira-como avatar ryansh100 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bricklink-api's Issues

Failed request should reject

Hello

First of all thanks for the lib. It helped me alot, as it implements signing. But I have one issue with failed requests.

Failed requests are console.loged and resolved on line:

resolve(data.data);

Then it is impossible to get error reason.

I am overcoming the issue using own client. But I think it would be usefull to resolve and reject with whole bricklink data

Error requesting prices

Hey ryansh100,
currently request getPriceGuide-request seems to be broken.
It leads to the following error:

node_modules/bricklink-api/src/client.js:68
let data = JSON.parse(body);
^
SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse (<anonymous>)

Did the Bricklink Api, announce some changes?
Do you have time to investigate?

Could not use the example.

Hi,

I try to use your code to retrieve data from Bricklink but it does not work. Therefore I use the code following code and it works.

`'use strict';

const express = require('express');
const app = express();

const Client = require('bricklink-api').Client;
console.log('hi', Client);
const ItemType = require('bricklink-api').ItemType;
const bricklink = new Client({
"consumer_key": "",
"consumer_secret": "",
"token": "",
"token_secret": ""
});

app.get('/part/:id', function(req, res) {
bricklink.getCatalogItem('PART', req.params.id)
.then(function(part){
res.json(part)
});
})`

Client.Send method do not catch errors when called with a callback function

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Description of the issue

I was trying to make a web interface using ExpressJs and Bricklink-API.
The problem is errors handling.
When an error is sent from bricklink api, it is not caught in case there is a callback to the Client Send method.

Here is the diff that solved my problem:

diff --git a/node_modules/brickbase-bricklink-api/dist/client.js b/node_modules/brickbase-bricklink-api/dist/client.js
index 85b4a64..deba093 100644
--- a/node_modules/brickbase-bricklink-api/dist/client.js
+++ b/node_modules/brickbase-bricklink-api/dist/client.js
@@ -111,7 +111,7 @@ var Client = exports.Client = function () {
       });
 
       if (req.callback) {
-        promise.then(req.callback);
+        promise.then(req.callback).catch(req.callback);
       }
       return promise;
     }

This issue body was partially generated by patch-package.

Including error information in thrown exception

Hi @ryansh100, thanks for the library, would you be able to add more data about errors from BrickLink? might want to throw an object instead of a string.

const error = new Error(
'Received an error from the BrickLink servers',
);
logger(
JSON.stringify(
{
reqestURI: resourceURL,
responseMetadata: payload.meta,
},
null,
2,
),
);
throw error;

e.g.

const error = {
          resourceURL: resourceURL,
          responseMetadata: payload.meta,
        }

Would you accept a PR for that?

Client.send does not support PUT or POST, making it impossible to add or update anything using the API

Although no methods exist yet, I want to share that the Client object cannot send PUT or POST requests.

The problem consists of multiple issues:

  • There does not seem to be a way to provide a content body to a request. Whatever you do, the request parameters will always be sent as query string.
  • There is no header Content-Type: application/json configured, even though it's required by BrickLink's API (not stated in docs, but error will be thrown when missing).
  • The OauthHelper does not seem able to correctly sign requests containing a body.

These issues need to be addressed or expansion of the api wrapper cannot progress except for adding more GET requests.

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.