class Bing::Content::Api::Connector

Constants

BMC_HOST

Public Class Methods

new(developer_token, token, merchant_id, catalogue_id) click to toggle source
# File lib/bing/content/api/connector.rb, line 9
def initialize(developer_token, token, merchant_id, catalogue_id)
  @developer_token = developer_token
  @token = token
  @merchant_id = merchant_id
  @catalogue_id = catalogue_id
end

Public Instance Methods

get(path) click to toggle source
# File lib/bing/content/api/connector.rb, line 16
def get(path)
  request = HTTPI::Request.new
  request.url = BMC_HOST + base_uri + path
  request.headers['Content-Type'] = 'application/json'
  add_auth_headers(request)
  HTTPI.get(request)
end
post(path, body) click to toggle source
# File lib/bing/content/api/connector.rb, line 24
def post(path, body)
  request = HTTPI::Request.new
  params = { :"bmc-catalog-id" => @catalogue_id } if @catalogue_id
  url = BMC_HOST + base_uri + path_with_params(path, params)
  request.url = url
  request.body = body
  request.headers['Content-Type'] = 'application/json'
  add_auth_headers(request)
  HTTPI.post(request)
end

Private Instance Methods

add_auth_headers(req) click to toggle source
# File lib/bing/content/api/connector.rb, line 43
def add_auth_headers(req)
  req.headers['DeveloperToken'] = @developer_token
  req.headers['AuthenticationToken'] = @token
end
base_uri() click to toggle source
# File lib/bing/content/api/connector.rb, line 48
def base_uri
  "/shopping/v9.1/bmc/#{@merchant_id}"
end
path_with_params(path, params) click to toggle source
# File lib/bing/content/api/connector.rb, line 37
def path_with_params(path, params)
  return path unless params
  encoded_params = URI.encode_www_form(params)
  [path, encoded_params].join("?")
end