Skip to content

Instantly share code, notes, and snippets.

@frankie-loves-jesus
Last active August 29, 2015 14:04
Show Gist options
  • Save frankie-loves-jesus/1fac418427f894373bbd to your computer and use it in GitHub Desktop.
Save frankie-loves-jesus/1fac418427f894373bbd to your computer and use it in GitHub Desktop.

Display products from the VigLink API using viglink-api

NOT WORKING

Live app: http://runnable.com/U9U3T6cNJG9Mwlu3/viglink-api-2-for-ruby-on-rails

The document "403 Access to this page has been restricted" does not have a valid root

Extracted source (around line #17):
    deals = client.find_deals({
      keyword: category,
      page: 1,
      results_per_page: 50

Rails.root: /root/rails-repo

multi_xml (0.5.5) lib/multi_xml/parsers/rexml.rb:18:in `parse'
multi_xml (0.5.5) lib/multi_xml.rb:138:in `parse'
faraday_middleware (0.9.1) lib/faraday_middleware/response/parse_xml.rb:9:in `block in <class:ParseXml>'
faraday_middleware (0.9.1) lib/faraday_middleware/response_middleware.rb:48:in `call'
faraday_middleware (0.9.1) lib/faraday_middleware/response_middleware.rb:48:in `parse'
faraday_middleware (0.9.1) lib/faraday_middleware/response_middleware.rb:39:in `process_response'
faraday_middleware (0.9.1) lib/faraday_middleware/response_middleware.rb:32:in `block in call'
faraday (0.9.0) lib/faraday/response.rb:57:in `on_complete'
faraday_middleware (0.9.1) lib/faraday_middleware/response_middleware.rb:30:in `call'
faraday (0.9.0) lib/faraday/response.rb:8:in `call'
faraday (0.9.0) lib/faraday/rack_builder.rb:139:in `build_response'
faraday (0.9.0) lib/faraday/connection.rb:377:in `run_request'
faraday (0.9.0) lib/faraday/connection.rb:140:in `get'
viglink-api (0.1.1) lib/viglink_api/request.rb:16:in `request'
viglink-api (0.1.1) lib/viglink_api/request.rb:8:in `get'
viglink-api (0.1.1) lib/viglink_api/deal.rb:16:in `find_deals'
app/models/third_party_products.rb:17:in `fetch'
app/models/third_party_products.rb:3:in `fetch'
app/controllers/main_controller.rb:3:in `index'
actionpack (4.0.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:189:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (4.0.0) lib/active_support/callbacks.rb:403:in `_run__791967061453339900__process_action__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.0) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.0) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (4.0.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.0.0) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.0) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.0) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.0) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.0) lib/action_dispatch/routing/route_set.rb:655:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/cookies.rb:486:in `call'
activerecord (4.0.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4287305910356335478__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
class ThirdPartyProducts
def self.fetch category
VigLink.fetch(category)
end
end
class ThirdPartyProducts::VigLink
def self.fetch category
client = ViglinkApi::Client.new({
api_key: "590c7238a32d91f8123eff7cf7e5ffb7",
api_url: "http://catalog.viglink.com",
api_full_response: true
})
deals = client.find_deals({
keyword: category,
page: 1,
results_per_page: 50
})
deals.each do |deal|
begin
offer = Offer.new
offer.name = deal['name']
offer.destination = deal['url']
offer.image = deal['image_url_large']
offer.price = deal['price_min']
offer.save!
rescue Exception => e
puts e.message
end
end
end
end
class MainController < ApplicationController
def index
@products = ThirdPartyProducts.fetch 'photo'
end
end
<h1>VigLink API</h1>
<p>Should automatically prefer merchants close to Scandinavia</p>
<h2>Popular products for category `photo`</h2>
<% if @products.any? %>
<div class="products">
<% @products.each do |product| %>
<div class="product">
<%= link_to image_tag(product.image_url), product.url %>
<%= link_to product.name, product.url %>
</div>
<% end %>
</div>
<% end %>
<h2>Example of keywords turned into links</h2>
<h3>Should `.article` be processed by a Rails helper similar to say <a href="https://github.com/vmg/rinku">Rinku</a>?</h3>
<p class="article">The new 36.3-megapixel, full-frame Nikon D810 is the much anticipated upgrade from the D800 and D800E. Omitting the OLP filter to increase detail and reduce moiré, the D810 features the EXPEED 4 Image Processor, said to increase speed by 30%, boost battery efficiency and widen ISO range to 64-12,800 (expandable to 32-51,200). The camera can be set to shoot in either the standard 14-bit RAW file format or a slightly smaller-resolution, 12-bit format for a quicker workflow. An Advanced Scene Recognition System uses the 91,000-pixel 3D Color Matrix Meter III to analyze each scene using color, brightness and human faces, providing balanced exposures in difficult lighting. For quick access to your most utilized settings, you can personalize button functions. Video features include full 1080/60p HD resolution, zebra stripe mode, full manual shooting with full AF ability, built-in stereo mic, in-camera time-lapse and interval timer, and uncompressed digital HDMI recording to an external device while also recoding to the SD or CF card.</p>
# encoding: utf-8
# https://github.com/arktisklada/viglink-api/blob/master/lib/viglink_api/deal.rb
module ViglinkApi
module Deal
##
# Retrieve the list of Deals
#
# @param :full [Boolean] If set to true|y|yes then this will return
# the complete response
#
# @return [Hashie::Mash] Deal
def find_deals(options={})
full_response = options.delete(:full) if options[:full]
options[:key] = @api_key
deals_response = get('/vigcatalog/deals.xml', options)
if full_response.to_s.to_bool or @api_full_response
deals_response.response if deals_response.response
else
deals_response.response.results.deals if deals_response.response.results
end
end
##
# Retrieve the list of Deal Types
#
# @param :full [Boolean] If set to true|y|yes then this will return
# the complete response
#
# @return [Hashie::Mash] DealType
def find_deal_types(options = {})
full_response = options.delete(:full) if options[:full]
options[:key] = @api_key
deal_types_response = get('/vigcatalog/deal_types.xml', options)
if full_response.to_s.to_bool or @api_full_response
deal_types_response.response if deal_types_response.response
else
deal_types_response.response.results.deal_types if deal_types_response.response.results
end
end
end
end
=begin
Optional search parameters for find_deals
Param name Type Kind Allowed Values Default Value Description
end_on range filter The end on date a deal is still valid for. Pass in a single date for an exact match, or pass in a range of dates delimited with a dash '-'.
end_on_max range filter The maximum end on date for a deal.
deal_type selection filter The deal type ID a deal belongs to.
keyword query A term or phrase you want to find in the deal name or description.
keyword_description query A term or phrase you want to find in the deal description.
keyword_name query A term or phrase you want to find in the deal name.
merchant selection filter The merchant ID of the merchant a deal belongs to.
merchant_type selection filter The merchant type ID that a deal's merchant belongs to.
page item pagination 1-100 1 The page number of the results you want returned.
results_per_page item pagination 1-100 20 The number of deals to return in every response.
session session Zipped info used to build more relevant filter values in the response in order to get back to previous filtered states. You do NOT to generate session value, it is provided in the parameters block. Pass it forward for any additional calls you make.
site_wide item filter all, yes, no all Indicates whether or not a deal applies site wide on a merchant's site, as opposed to being for a specific product or specific category within the merchant's site.
sort_deal sort relevance, name_asc relevance The sort order the deals are returned in
start_on range filter The start on date a deal is valid for. Pass in a single date for an exact match, or pass in a range of dates delimited with a dash '-'.
start_on_max range filter The maximum start on date for a deal.
start_on_min range filter The minimum start on date for a deal.
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment