Skip to content

Instantly share code, notes, and snippets.

@chandeeland
Last active August 20, 2018 14:46
Show Gist options
  • Save chandeeland/7c6c52b2876f89a8e4a328c584cee712 to your computer and use it in GitHub Desktop.
Save chandeeland/7c6c52b2876f89a8e4a328c584cee712 to your computer and use it in GitHub Desktop.
require 'uri'
require 'net/http'
require 'json'
require 'pry'
class Brandibble
def initialize(env)
@env = env
end
def run
binding.pry
# order(:bite)
# order(:bite)
# order(:brandibble)
# order(:bite)
end
# menu item maker
# id = '5ad975204a83e70007d8f955'
def item(id)
mi = Platform::MenuItem.find(id)
v = mi.variations.sample
{
menu_item_id: mi.id,
note: "#{mi.name} #{v.name}",
quantity: 1,
variation_id: v.id,
modifiers: mi.modifier_groups.map(&:modifiers).flatten.map(&:id)
}
end
private
attr_reader :env
def tokens
bodies = {
numpang: {
bite: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\ngBAfWaku3H8P37fE\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\n8c114d5b42167e8256f3dfbe31fc7d83e83da4a4944a33d29879d062e3a127d2\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n0a3dd7907581f79cbd0d7311a5b5ce099e581eaeaec869f8ac0e35fa26a8e623\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nstas@bitekiosk.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
brandibble: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nenhcMqmntKmJ78M3\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\njc@brandibble.co\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\n8618a193b69deff2880e7f4bec960ab485ec4e64f3c859be2e3e12e1f3212290\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n0092b8ac0bf45202d223124ca7ba4d2d5e084f2fe8eb9ff2b54ed4bf0453ed84\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
},
sbx: {
bite: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nlovebite\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\nf33d9b18a1bf97ed0359e4aa97190ee5be57097e0040642fc04cf911658939df\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n6fd4161ec6a4740a8031253bfb2411491ad3c9895b0ea5332eb6c824a001262a\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nstas@bitekiosk.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
brandibble: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nsalidosbx\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\njc@brandibble.co\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\na9bdc06ff00c341500f383dfc052c1dac95af6ce9d5817b116f37106bf09dee5\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n10e22850907fd29c4ea10830ca8e95d7aa0b538aea87a128a5f61155fdaf6f22\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
},
prod: {
bite: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\n8c114d5b42167e8256f3dfbe31fc7d83e83da4a4944a33d29879d062e3a127d2\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n0a3dd7907581f79cbd0d7311a5b5ce099e581eaeaec869f8ac0e35fa26a8e623\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\nstas@salido.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nsalido123\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
brandibble: "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\npassword\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"username\"\r\n\r\njc@salido.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_id\"\r\n\r\n8618a193b69deff2880e7f4bec960ab485ec4e64f3c859be2e3e12e1f3212290\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"client_secret\"\r\n\r\n0092b8ac0bf45202d223124ca7ba4d2d5e084f2fe8eb9ff2b54ed4bf0453ed84\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\nsalido123\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
}
}
@tokens ||= {
brandibble: get_token(bodies[env][:brandibble]),
bite: get_token(bodies[env][:bite])
}
end
def token_url
return URI("https://ss-gandalf-sbx.herokuapp.com/oauth/token") if env == :sbx
URI("https://ss-gandalf-pro.herokuapp.com/oauth/token")
end
def get_token(body)
http = Net::HTTP.new(token_url.host, token_url.port)
request = Net::HTTP::Post.new(token_url)
request["content-type"] = 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
request["Cache-Control"] = 'no-cache'
request.body = body
result = Net::HTTP.start(token_url.host, token_url.port,
:use_ssl => token_url.scheme == 'https') {|http| http.request(request)}
JSON.parse(result.read_body).dig('access_token')
end
def order_url
return URI("https://ss-geoffrey-sbx.herokuapp.com/orders") if env == :sbx
URI("https://ss-geoffrey-pro.herokuapp.com/orders")
end
def order(who)
http = Net::HTTP.new(order_url.host, order_url.port)
request = Net::HTTP::Post.new(order_url)
request["Authorization"] = "Bearer #{tokens[who]}"
request["Accept"] = 'application/vnd.api+json'
request["Content-Type"] = 'application/vnd.api+json'
request["Cache-Control"] = 'no-cache'
request["Postman-Token"] = '8682dad9-122c-461c-85af-dc8747c739af'
request.body = data(who)
res = Net::HTTP.start(order_url.host, order_url.port,
:use_ssl => order_url.scheme == 'https') {|http| http.request(request)}
puts JSON.parse(res.read_body)
res.read_body
end
def order_items
sbx_common = [
{
:menu_item_id => '5ad63d4730c4b90007fff0fa',
:note => "Coconut Shrimp Bowl Grain",
:quantity => 1,
:variation_id => '5ad63d4730c4b90007fff104',
:modifiers => [
{ command: '', modifier_id: '5ad6345d30c4b90007fff08c' },
{ modifier_id: '5ad6347551354f0007183749' },
{ command: 'add', modifier_id: '5ad634a951354f000718374a' },
{ command: 'add', modifier_id: '5ad634b351354f000718374b' },
{ command: 'add', modifier_id: '5ad6340151354f0007183746' },
{ command: 'add', modifier_id: '5ad6354430c4b90007fff090' },
{ command: 'add', modifier_id: '5ad6355051354f000718374f' }
].sample(2)
},
{:menu_item_id=>"5ad619e230c4b90007ffef90", :note=>"Cambodian Iced Coffee", :quantity=>1, :variation_id=>"5ad619e230c4b90007ffef94", modifiers: []},
{:menu_item_id=>"5ad975204a83e70007d8f955", :note=>"Cherry Soda", :quantity=>1, :variation_id=>"5ad975204a83e70007d8f95a"},
{:menu_item_id=>"5ad61b3130c4b90007ffefa2", :note=>"Roasted Chicken \"Chimi\" Bowl", :quantity=>1, :variation_id=>"5ad61b3130c4b90007ffefac"}
]
prod_common = [
{:menu_item_id=>"5b69ad0bd325040034726f1c", :note=>"Cherry Soda Regular", :quantity=>1, :variation_id=>"5b69ad0bd325040034726f1e",
:modifiers=>[
{command: 'add', modifier_id: "55f049bfdcaf9d0018000014"},
{command: 'add', modifier_id: "577ec3370b8dd60009000a94"},
{command: 'add', modifier_id: "577ec32056868400090000d3"},
{command: 'add', modifier_id: "577ec32056868400090000d3"},
{command: 'add', modifier_id: "55f049bfdcaf9d0018000014"},
{command: 'add', modifier_id: "577ec3370b8dd60009000a94"},
{command: 'add', modifier_id: "579f81eb71eed80009000604"},
].sample(3)},
{:menu_item_id=>"5b69adb558eae60060e3779e", :note=>"Roasted Chicken \"Chimi\" Bowl Grain", :quantity=>1, :variation_id=>"5b69adb558eae60060e377a7", :modifiers=>[]}
]
numpang_common = [
{:menu_item_id=>"56286ca33b72a5000a000120",
:note=>"Cherry Soda Regular",
:quantity=>1,
:variation_id=>"56286ca43b72a5000a000122",
:modifiers=>[]
},
# {:menu_item_id=>"56286ca03b72a5000a000114",
# :note=>"Cambodian Iced Coffee Regular",
# :quantity=>1,
# :variation_id=>"56286ca13b72a5000a000116",
# :modifiers=>[]
# },
{:menu_item_id=>"56286c8e3b72a5000a00004d",
:note=>"Coconut Tiger Shrimp Regular",
:quantity=>1,
:variation_id=>"56286c8e3b72a5000a00004f",
:modifiers=>[
{command: 'add', modifier_id: "5adf7c7821aa7a00320bee05"},
{command: 'add', modifier_id: "5adf7c7e8b94d0003ac5bd03"},
{command: 'add', modifier_id: "5adf7c878b94d0003ec5bcff"},
{command: 'add', modifier_id: "5adf7c8e21aa7a00360bee51"},
{command: 'add', modifier_id: "5adf7d808b94d0003ac5bd19"},
{command: 'add', modifier_id: "5adf7d218b94d00036c5bc42"},
{command: 'add', modifier_id: "5adf7d2bb934f3003eb7268b"},
{command: 'add', modifier_id: "5adf7d338b94d0003ac5bd10"},
].sample(2)
},
# {:menu_item_id=>"581a2e047f44730009000b67",
# :note=>"Coconut Tiger Shrimp Bowl Grain LG",
# :quantity=>1,
# :variation_id=>"58e5627093eb2b000600048e",
# :modifiers=>[
# {command: 'add', modifier_id: "5adf7cba8b94d00036c5bc3b"},
# {command: 'add', modifier_id: "5adf7d6f21aa7a00360bee5b"},
# {command: 'add', modifier_id: "5adf7d758b94d00032c5bc08"},
# {command: 'add', modifier_id: "5adf7d7a8b94d0003ec5bd0e"},
# {command: 'add', modifier_id: "5adf7d808b94d0003ac5bd19"},
# {command: 'add', modifier_id: "5adf7d2bb934f3003eb7268b"},
# {command: 'add', modifier_id: "5adf7d2621aa7a00320bee0a"},
# {command: 'add', modifier_id: "5adf7d0eb934f30042b7261d"},
# {command: 'add', modifier_id: "5adf7d9221aa7a00420beef3"},
# {command: 'add', modifier_id: "5adf7d088b94d00032c5bc02"},
# {command: 'add', modifier_id: "5adf7cc721aa7a003a0bef71"},
# {command: 'add', modifier_id: "5adf7d3821aa7a00360bee56"},
# {command: 'add', modifier_id: "5adf7d3d21aa7a003a0bef7a"}
# ].sample(2)
# },
{:menu_item_id=>"5a6913c2139c2b000e13e1f2",
:note=>"Duroc Pulled Pork Bowl White",
:quantity=>1,
:variation_id=>"5a6913c2139c2b000e13e1f4",
:modifiers=>[
{command: 'add', modifier_id: "5adf7d0eb934f30042b7261d"},
{command: 'add', modifier_id: "5adf7d9221aa7a00420beef3"},
{command: 'add', modifier_id: "5adf7cc721aa7a003a0bef71"},
{command: 'add', modifier_id: "5adf7d088b94d00032c5bc02"},
{command: 'add', modifier_id: "5adf7cba8b94d00036c5bc3b"},
{command: 'add', modifier_id: "5adf7d6f21aa7a00360bee5b"},
{command: 'add', modifier_id: "5adf7d758b94d00032c5bc08"},
{command: 'add', modifier_id: "5adf7d7a8b94d0003ec5bd0e"},
{command: 'add', modifier_id: "5adf7d2621aa7a00320bee0a"},
{command: 'add', modifier_id: "5adf7d2bb934f3003eb7268b"},
{command: 'add', modifier_id: "5adf7d3821aa7a00360bee56"},
{command: 'add', modifier_id: "5adf7d648b94d0005ec5bdbb"}
].sample(2)
}
]
{
numpang: {
brandibble: numpang_common,
bite: numpang_common
},
prod: {
brandibble: prod_common,
bite: prod_common
},
sbx: {
brandibble: sbx_common,
bite: sbx_common + [
{:menu_item_id=>"5ad60fcf30c4b90007ffed72", :note=>"Hot & Sour Chicken + Rice Soup", :quantity=>1, :variation_id=>"5ad60fd030c4b90007ffed7a"}
]
}
}
end
def revenue_centers
{
numpang: {
bite: '5aeb8c8b4861050054b07783',
brandibble: '5aeb8cb5486105005fb0775c'
},
prod: {
bite: '5b69c4a5946f1b0038b4932f',
brandibble: '5b69c521d325040040727046'
},
sbx: {
bite: '5ad624c751354f00071836ed',
brandibble: '5ad91bda4c79970007f6b43b'
}
}
end
def order_types
{
numpang: {
bite: '5aebac84541574003a87cf0f',
brandibble: '59ba8e213dc288000ad9ac35'
},
prod: {
bite: '5b69aa5058eae60060e3778d',
brandibble: '5b69aa5cd32504003c726ed0'
},
sbx: {
bite: '5ad60cca30c4b90007ffecf3',
brandibble: '5aa3040d4d7a0a00071a2672'
}
}
end
def discount_rule
{
numpang: '5b02ece0e70869003a16e243',
prod: '5b69acbe946f1b0034b49351',
sbx: '5aa30e1101e9de000718f849'
}
end
def data(who)
JSON.unparse({
"data": {
"attributes": {
"guests": [
{
"email": "david.chan+test@salido.com",
"external_id": "100:#{Time.now.to_i}",
"first_name": "david",
"gender": "M",
"last_name": "chan",
"phone": "8005551212"
}
],
"order_items": order_items[env][who].sample(2),
"order_type_id": order_types[env][who],
"revenue_center_id": revenue_centers[env][who],
"tip_amount": 10.0,
"external_id": "1234:#{Time.now.to_i}",
"discounts": [
{
"discount_rule_id": discount_rule[env],
"value": 100,
"note": "$1 open discount"
}
]
},
"type": "orders"
}
})
end
end
Brandibble.new(:prod).run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment