|I'm looking for a benevolent maintainer for this library. I don't have the time anymore to evolve it. Until someone picks it up, it's stuck on previous version of auchandirect.com.|
A ruby gem providing, through scrapping, an API to the french www.auchandirect.fr online grocery
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install auchandirect-scrAPI
This library should be production ready.
- It is automaticaly tested through Travis
It should be daily tested through daily-travis to quickly detect modification at www.auchandirect.fr
This API has 2 main features :
- walking the store to collect all the different items in the different subsections
- Connecting with a user account in order to fill his cart
It is not currently possible to pay and validate an order through this API. In order to do so, a user must :
- first disconnect from the API
- only then reconnect with his account through a browser, and order his pre-filled cart
Suppose you'd want to fill your cart with all the pizzas available on the store, this is how you would do it :
cart = Auchandirect::ScrAPI::Cart.login('email@example.com', 'password') begin Auchandirect::ScrAPI::Items.browse.categories.each do |cat| cat.categories.each do |s_cat| s_cat.categories.each do |ss_cat| ss_cat.items.each do |item| if item.attributes[:name] =~ /pizza/i cart.add_to_cart(item.attributes[:remote_id]) end end end end end ensure ensure cart.logout end
Client side usage
In order to make it possible for a web browser to automaticaly connect to auchandirect.fr (for example in an iframe, to pay for a cart that was previously filled with this gem on the server), the Auchandirect::ScrAPI::Cart class exposes enough information to generate the html that makes this possible. You can have a look at spec/lib/auchandirect/scrAPI/client_cart_shared_examples.rb for more details. This whole thing remains tricky and subject to failures though.
In order to run quicker and offline tests for the rest of your app, you can use Auchandirect::ScrAPI::DummyCart in place of a real cart. This cart is compatible with Storexplore's dummy store generators (see https://github.com/philou/storexplore).
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
Running the tests
- If you want to run the tests, you'll need valid auchandirect credentials. So first, head up to www.auchandirect.fr and create yourself an account if you don't yet have one.
- To run guard or rspec, you'll have to specify these credentials through environment variables :
AUCHANDIRECT_TEST_EMAILfirstname.lastname@example.org AUCHANDIRECT_TEST_PASSWORD=secret bundle exec rspec spec
- If you get tired of repeating this, you can create yourself a 'credentials' shell script at the root of the repo :
#!/bin/sh AUCHANDIRECT_TEST_EMAILemail@example.com AUCHANDIRECT_TEST_PASSWORD=secret "$@"
- Make it exectuable
chmod +x credentials
- You can now simply run any command with your credentials
./credentials bundle exec rspec spec