Project

meta_hari

0.0
No commit activity in last 3 years
No release in over 3 years
Receiving product informations from a given link.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 2.12.5
~> 4.5.0
~> 1.6.6
~> 0.10.1
~> 10.0
~> 3.2.0
~> 0.31.0

Runtime

~> 2.3.8
~> 0.0.3
 Project Readme

MetaHari

Codeship Status for spieker/meta_hari Dependency Status Code Climate

Meta Hari is receiving product informations from a given product link (i.e. from Amazon).

The name Meta Hari comes from Mata Hari, one of the most popular spies.

Installation

Add this line to your application's Gemfile:

gem 'meta_hari'

And then execute:

$ bundle

Or install it yourself as:

$ gem install meta_hari

Usage

In order to receive product informations, just pass the URL containing thous informations to the method MetaHari.spy.

product = MetaHari.spy('www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1')
product.inspect # => #<MetaHari::Product:0x007fa3429de030 @uri=#<Addressable::URI:0x3fd1a18d5c04 URI:http://www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1>, @name="Gastroback 42429 Design Wasserkocher Advanced Pro", @image="http://ecx.images-amazon.com/images/I/814Yl6mxLsL._SL1500_.jpg", @description="">
product.uri.to_s # => http://www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1

Implemented spyglasses

A spyglass is a support class for a specific shop. In order to support custom shops which can not be spyed by the generic spyglass (MetaHari::Spyglass::Base), a new spyglass has to be created.

Creating a spyglass

A spyglass has to be a class within the namespace MetaHari::Spyglass and must extend the class MetaHari::Spyglass::Base. The methods self.suitable? and spy.

module MetaHari
  module Spyglass
    class AmazonDe < Base
      def self.suitable?(uri)
        %w(amazon.de www.amazon.de).include? uri.host.downcase
      end

      protected

      def spy_list
        [:spy_amazon]
      end

      def title
        document.css('#productTitle').text
      end

      def image
        data = document.css('img#landingImage')
        data &&= data.attr 'data-old-hires'
        data && data.value
      end

      def spy_amazon
        { 'name' => title, 'image' => image, 'description' => '' }
      end
    end
  end
end

Contributing

  1. Fork it ( https://github.com/spieker/meta_hari/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request