OpenBazaar API Ruby Client

in #openbazaar9 years ago (edited)

OpenBazaar API Ruby Client

Build Status Code Climate Test Coverage

A simple OpenBazaar API client for Ruby.

Installation

Add the gem to your Gemfile:

gem 'obarc', github: 'inertia186/obarc'

Then:

$ bundle install

Usage

require 'obarc'

session = OBarc::Session.new(username: 'username', password: 'password')

profile = session.profile
{"profile":
  {"website": "website",
   "public_key": "b7d8f6ee04453e1babde87d12198ecd14be00aa998e85636767d8b00d2603e6d",
   .
   .
   .
   "primary_color": 16777215,
   "background_color": 12832757,
   "email": "[email protected]"}}
session.update_profile(email: '[email protected]')
{"success": true}
session.connected_peers
{"peers": [["5.37.3.8", 28467]], "num_peers": 1}

If you want to manually upload an image, this will return the image hash.

session.upload_image(image: 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAC91JREFUWAktl3mQHOV5xn99zH3u7K1d7Uq7CEkIpNVZRhagQDjKCcaxSIJNIJTjI5XCuakKceXyHy5XnJSr')
{"image_hashes": ["a89810619833ef29d373c124ce05f362a313929e"], "success": true}

You can also add a new listing with image URLs in the hash. The client will upload them and save the image hashes to the contract.

{"success": true}

Tests

  • Clone the client repository into a directory of your choice:
    • git clone https://github.com/inertia186/obarc.git
  • Navigate into the new folder
    • cd obarc
  • Basic tests can be invoked as follows:
    • rake
  • To run tests with parallelization and local code coverage:
    • HELL_ENABLED=true rake
  • To run tests against a testnet server:
    • TEST_NET=true OB_SERVER_HOST=localhost OB_USERNAME=username OB_PASSWORD=password rake

Docmentation

  • Session - Most of what you need in your app is explained here.

Requirements

  • ruby 2.1.5
  • bundler 1.11
  • OpenBazaar-Server 1.1.15

Get in touch!

If you're using OBarc, I'd love to hear from you. Drop me a line and tell me what you think!

Licence

I don't believe in intellectual "property". If you do, consider OBarc as licensed under a Creative Commons CC0 License.