Class: Trustvox::Store

Inherits:
Base
  • Object
show all
Defined in:
lib/trustvox/store.rb

Overview

Responsible to api calls about store

Instance Method Summary collapse

Methods inherited from Base

#auth_by_platform_token!, #auth_by_store_token!, #initialize

Constructor Details

This class inherits a constructor from Trustvox::Base

Instance Method Details

#create(store_data) ⇒ Object

Call create store api

Parameters:

  • store_data


7
8
9
10
11
12
13
14
15
16
# File 'lib/trustvox/store.rb', line 7

def create(store_data)
  auth_by_platform_token!
  response = self.class.post('/stores', { body: store_data.to_json })
  data = JSON.parse(response.body) rescue nil

  {
    status: response.code,
    data: data,
  }
end

#load_store(url) ⇒ Object

Call store lookup api

Parameters:

  • url


31
32
33
34
35
36
37
38
39
40
# File 'lib/trustvox/store.rb', line 31

def load_store(url)
  auth_by_platform_token!
  response = self.class.get("/stores", { query: { url: url} })
  data = JSON.parse(response.body) rescue nil

  {
    status: response.code,
    data: data,
  }
end

#push_order(order_data) ⇒ Object

Call order api

Parameters:

  • order_data


20
21
22
23
24
25
26
27
# File 'lib/trustvox/store.rb', line 20

def push_order(order_data)
  body = Utils.build_push_order_data(order_data)
  auth_by_store_token!
  response = self.class.post("/stores/#{Config.store_id}/orders", { body: body.to_json })
  data = JSON.parse(response.body) rescue nil

  { status: response.code, data: data }
end