4

I found an Amazon Gem that I want to use https://github.com/hakanensari/vacuum/.

I've only ever used gems with in depth tutorials or following a RailsCast. I'm looking for tips on using gems I find online. I'll explain the steps I'm doing, and hopefully someone can give me some ideas on what else I should be doing when using a new gem. Also, if you have a good tutorial or explanation on gems, that would be great too.

I started off examining the Gem on Github, I'll point out the things I took notice of. Let me know if there are things I'm missing I should notice.

Examining Gem on Github

  1. Go to the examples and look at "examples/product_advertising/basic_lookup.rb"
  2. Follow the required file, and checkout "examples/product_advertising/shared.rb"
  3. Notice, I need to install "pry"
  4. Notice, the examples expand on the "lib" folder
  5. Check out "credentials.yml"
  6. Notice a "@req" is instantiated as a new Vacuum object.
  7. Then back in basic_lookup.rb, it looks like it's assigning the lookup value, then binding the response to some kind of "pry" view.

Next, I'll try implementing these examples in my own project. Here's where I'm not sure what to do as far, as files are concerned.

Attempt Implementing Example

  1. Install vacuum gem

    gem install vacuum

  2. Install pry gem

    gem install pry

  3. Added "shared.rb" and "credentials.yml" to my "app/controllers" directory
  4. Replaced the information in "credentials.yml" with my information
  5. Attempt to copy the information from "basic_lookup.rb" into an existing controller

    def amazon
      require File.expand_path('../shared.rb', __FILE__)
    
      res   = @req.look_up '0816614024'
      items = res.find 'Item'
    
      binding.pry
    end
    
  6. Create a route

    match '/test' => 'products#amazon'

  7. Go to test page and receive the following error

    undefined method 'look_up' for nil:NilClass

I would like to point out, at this point I haven't added the lib folder.

Questions

  • I like the credentials.yml is separated out, when I want to add this to my project, where should I save that file?
  • I like the shared.rb file, should I just put that in the controller folder?
  • Why is it referencing the "lib" folder in "shared.rb"? Do I need to copy that directory into my project?

I appreciate you sticking around and reading all of this. I'm still trying to get a handle on using a gems, so any help or tips are great. Really, I'm just trying to figure out, how do I find any gem and start using it appropriately.

Thanks for any help you can give me!

david
  • 582
  • 5
  • 13
  • Do you need all that? Can't you just do something like https://gist.github.com/frankie-loves-jesus/89d24dd88579c7f912f3? – Mark Boulder May 01 '14 at 13:52

1 Answers1

0

I like the shared.rb file, should I just put that in the controller folder? Answer = yes, you just put that file in controller folder.