Code Monkey home page Code Monkey logo

stock_shaker's Introduction

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

Do Authorization Link

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

  • Shopee OrderAPI
    server_url = StockShaker::Client::SHOPEE_API_GATEWAY_URL_TH
    shop_id = ENV['YOUR_SHOP_ID']
    
    update_time_from = StockShaker::DateUtil.datetime_to_timestamp(DateTime.now.beginning_of_day - 2.days)
    update_time_to = StockShaker::DateUtil.datetime_to_timestamp(DateTime.now)
    
    client = StockShaker::Client::ShopeeOP.new(server_url, shop_id)
    request = StockShaker::Request::ShopeeOP.new('/orders/basics', :post)
    
    request.add_shopee_api_params({
      update_time_from: update_time_from,
      update_time_to: update_time_to,
      pagination_entries_per_page: 100,
      pagination_offset: 0
    })
    
    response = client.execute(request)
    puts response.body

Compatibility

We supported

  • Ruby MRI 2.2+
  • Rails 5.0+

Need helps!

  • Contributed this gems!
  • Write Test!

TODO

Core

  • Configurable
    • Validation
  • Generator
  • Write Rspec
  • Logger
  • Sentry.io Integration

Lazada

See more: Lazada Open Platform Documentation

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

Shopee

See more: Shopee Open Platform Documentation

  • Integrate with API reference
  • ItemAPI
    • GetItemsList (/items/get)
    • GetItemDetails (/item/get)
    • UpdateStock (/items/update_stock)
    • UpdateStockBatch (/items/update/items_stock)
    • UpdateVariationStock (/items/update_variation_stock)
    • UpdateVariationStockBatch (/items/update/vars_stock)
    • InsertItemImg (/item/img/insert)
    • DeleteItemImg (/item/img/delete)
  • OrderAPI
    • GetOrdersList (/orders/basics)
    • GetOrdersDetail (/orders/detail)
    • GetEscrowDetails (/orders/my_income)
  • ShopAPI
    • 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.

stock_shaker's People

Contributors

nijicha avatar wachirapornmpt avatar

Stargazers

 avatar

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.