Unofficial Rubygems for Thailand eCommerce Marketplace
A gems used to kick off API of eCommerce in Thailand. This gems inspired from Official Lazada Open Platform Gems
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
- Create
stock_shaker_config.rb
inconfig/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
* You should be define the StockShaker.configure
before typing this command.
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"
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"
-
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
-
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
-
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
We supported
- Ruby MRI 2.2+
- Rails 5.0+
- Contributed this gems!
- Write Test!
- Configurable
- Validation
- Generator
- Write Rspec
- Logger
- Sentry.io Integration
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
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)
- Integrate with API reference
git clone https://github.com/nijicha/stock_shaker.git
bundle install
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.
The gem is available as open source under the terms of the MIT License.