简体   繁体   English

利用API创建外部应用程序

[英]Leveraging an API to create an external application

I currently have a site built on and hosted by bigcommerce. 我目前有一个在bigcommerce上建立并托管的网站。 We have products in our store. 我们的商店有产品。

Additionally, I'm working on developing a mini-site with some of our store's content, by making use of the bigcommerce API (ruby version). 此外,我正在利用bigcommerce API (红宝石版)来开发一个包含我们商店某些内容的迷你网站。

I have however run into a problem and a question. 但是,我遇到了一个问题。

1) Problem : populating images from the bigcommerce DB via the API doesn't seem to be possible. 1) 问题 :似乎无法通过API从bigcommerce数据库填充图像。 how do I do it!? 我该怎么做!? When I query the images hash I receive a url to the API's route, where there are no images stored... If you know of any examples, please link me if you would. 当我查询图像哈希时,我收到一个指向API路由的URL,其中没有存储图像...如果您知道任何示例,请联系我。 I've scoured github and got nothing. 我已经搜索了github,却一无所获。

I realize this is a fairly vague question, can update shortly with more detail if it's useful. 我意识到这是一个相当模糊的问题,如果有用的话,可以稍后进行更详细的更新。 But this ultimately provokes the following. 但这最终引发了以下情况。

2) Question : is it poor design to re-persist all the db's objects (products) into the mini-site's database, purely for the purpose of making it easier to create a restful mini-site application? 2) 问题 :将所有数据库的对象(产品)重新持久化到微型站点数据库中的设计是否很糟糕,纯粹是为了使其更容易创建一个宁静的微型站点应用程序? (Ie creating a product page for each product object? Eg product_path(product.id) .) (是否为每个产品对象创建一个产品页面?例如product_path(product.id) 。)

I ask this because I suppose I could create a two-page or three-page app which will dynamically render the respective product information based on whichever product is clicked, and maybe just direct the user from there to the cart, but this seems awkward and forced. 我之所以这样问,是因为我想我可以创建一个两页或三页的应用程序,该应用程序将根据所单击的产品来动态呈现相应的产品信息,并且可能只是将用户从那里引导到购物车,但这似乎很尴尬,而且被迫。 (for lack of a better expression.) (由于缺乏更好的表达方式。)

Speaking to your first question - it is possible to get the product images via API. 说到第一个问题-可以通过API获取产品图片。 It is very hard for me to understand what you are trying to do from your question (a code snippet of what you have tried would be helpful). 对于我来说,很难从问题中理解您要尝试做的事情(您尝试过的代码片段会很有帮助)。

From the Bigcommerce Ruby lib - you should look up this method. 在Bigcommerce Ruby库中-您应该查找此方法。 It will do what you want. 它会做您想要的。 T Ť

  def get_products_images(options={})
      @connection.get("/products/images", options)
    end

You will receive a response like the following - 您将收到类似以下的回复-

{
        "id": 5,
        "product_id": 28,
        "image_file": "sample_images/picture_1__48492.png",
        "is_thumbnail": true,
        "sort_order": 0,
        "description": "",
        "date_created": "Mon, 26 Oct 2009 05:08:32 +0000"
    }

The store image can be found from http(s)://storeurl/product_images/{{image_file}} 可以从http(s):// storeurl / product_images / {{image_file}}中找到商店图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM