Stock Shaker Logo

Stock Shaker

Unofficial Rubygems for Thailand eCommerce Marketplace

Github Stars Gem Version Branch master Travis-ci Build Status License

For The Badge Built with Love For The Badge Made with Ruby Shield.io Made with shield.io

Love Lazada Love Shopee

A gems used to kick off API of eCommerce in Thailand. This gems inspired from Official Lazada Open Platform Gems

Installation

StockShaker's installation is Easy! Add this line to your application's Gemfile

gem 'stock_shaker', '~> 0.3.5'

If you'd rather install StockShaker with ruby-versions below than 2.4.

You need to add openssl as dependencies in Gemfile

# Gemfile

gem 'stock_shaker', '~> 0.3.5'
gem 'openssl'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install stock_shaker

Usage

Configurable

  • Create stock_shaker_config.rb in config/initializer
  • Please ensure you already configured it.
# config/initializer/stock_shaker_config.rb
StockShaker.configure do |config|
  # Lazada Configuration
  config.lazada_config.app_key = ENV['YOUR_LAZADA_APP_KEY']
  config.lazada_config.app_secret_key = ENV['YOUR_LAZADA_APP_SECRET_KEY']
  config.lazada_config.redirect_url = ENV['YOUR_LAZADA_REDIRECT_URL']

  # Shopee Configuration
  config.shopee_config.partner_id = ENV['YOUR_SHOPEE_PARTNER_ID']
  config.shopee_config.secret_key = ENV['YOUR_SHOPEE_SECRET_KEY']
  config.shopee_config.redirect_url = ENV['YOUR_SHOPEE_REDIRECT_URL']
end

NEW API

* You should be define the StockShaker.configure before typing this command.

Lazada

StockShaker::Client::LazadaOP.do_authorization_link

=> "https://auth.lazada.com/oauth/authorize?client_id=YOUR_LAZADA_APP_KEY&force_auth=true&redirect_uri=YOUR_LAZADA_REDIRECT_URL&response_type=code"

Shopee

StockShaker::Client::ShopeeOP.do_authorization_link

=> "https://partner.shopeemobile.com/api/v1/shop/auth_partner?id=YOUR_SHOPEE_PARTNER_ID&redirect=YOUR_SHOPEE_REDIRECT_URL&token=AUTHORIZATION_TOKEN"

Lazada Open Platform

  • SystemAPI

    server_url = StockShaker::Client::LAZADA_API_GATEWAY_URL_TH
    lazada_client = StockShaker::Client::LazadaOP.new(server_url)
    lazada_request = StockShaker::Request::LazadaOP.new('/auth/token/create', :post)
    lazada_request_params = { code: 'YOUR_AUTHORIZATION_CODE' }
    lazada_request_params.each { |key, value| request.add_lazada_api_params(key.to_s, value.to_s) }
    response = lazada_client.execute(lazada_request)
    response.success?
    response.body
    
    server_url = StockShaker::Client::LAZADA_API_GATEWAY_URL_TH
    lazada_client = StockShaker::Client::LazadaOP.new(server_url)
    lazada_request = StockShaker::Request::LazadaOP.new('/auth/token/refresh', :post)
    lazada_request_params = { refresh_token: 'YOUR_REFRESH_TOKEN' }
    lazada_request_params.each { |key, value| request.add_lazada_api_params(key.to_s, value.to_s) }
    response = lazada_client.execute(lazada_request)
    response.success?
    response.body
    
  • Lazada OrderAPI

    server_url = StockShaker::Client::LAZADA_API_GATEWAY_URL_TH
    access_token = ENV['YOUR_ACCESS_TOKEN']
    lazada_client = StockShaker::Client::LazadaOP.new(server_url)
    lazada_request = StockShaker::Request::LazadaOP.new('/orders/get', :get)
    
    # Get orders since last two days by update_after
    days_backwards = 2 # Get backwards 2 days
    update_after = StockShaker::DateUtil.datetime_to_iso8601(DateTime.now.beginning_of_day - days_backwards.days)
    
    lazada_request_params = { 
      created_before: '2018-02-10T16:00:00+07:00',
      created_after: '2017-02-10T09:00:00+07:00',
      status: 'shipped',
      update_before: '2018-02-10T16:00:00+07:00',
      sort_direction: 'DESC',
      offset: 0,
      limit: 100,
      update_after: update_after,
      sort_by: 'updated_at'
    }
    
    lazada_request_params.each { |key, value| request.add_lazada_api_params(key.to_s, value.to_s) }
    response = lazada_client.execute(lazada_request, access_token)
    puts response.success?
    puts response.body
    

Shopee Open Platform

Compatibility

We supported

  • Ruby MRI 2.2+
  • Rails 5.0+

Need helps!

  • Contributed this gems!
  • Write Test!

TODO

Core

  • [x] Configurable
    • [ ] Validation
  • [ ] Generator
  • [ ] Write Rspec
  • [ ] Logger
  • [ ] Sentry.io Integration

Lazada

See more: Lazada Open Platform Documentation

  • [ ] Integrate with API reference
  • [ ] Order API
    • [x] GetOrders
    • [x] GetMultipleOrderItems
  • [ ] Product API
    • [x] GetProducts
    • [x] UpdatePriceQuantity
  • [ ] Finance API
  • [ ] Logistics API
  • [ ] Seller API
  • [x] System API
    • [x] Generate Access Token
    • [x] Refresh Access Token
  • [ ] DataMoat API

Shopee

See more: Shopee Open Platform Documentation

  • [ ] Integrate with API reference
  • ItemAPI
    • [x] GetItemsList (/items/get)
    • [x] GetItemDetails (/item/get)
    • [x] UpdateStock (/items/update_stock)
    • [x] UpdateStockBatch (/items/update/items_stock)
    • [x] UpdateVariationStock (/items/update_variation_stock)
    • [x] UpdateVariationStockBatch (/items/update/vars_stock)
    • [x] InsertItemImg (/item/img/insert)
    • [x] DeleteItemImg (/item/img/delete)
  • OrderAPI
    • [x] GetOrdersList (/orders/basics)
    • [x] GetOrdersDetail (/orders/detail)
    • [x] GetEscrowDetails (/orders/my_income)
  • ShopAPI
    • [x] GetPerformance (/shop/performance)

JD Central

  • [ ] Integrate with API reference

Development

  1. git clone https://github.com/nijicha/stock_shaker.git
  2. bundle install

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nijicha/stock_shaker.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.