Code Monkey home page Code Monkey logo

spree_api_examples's Introduction

Spree API Examples

In this repo, you can expect to find some examples of how to interact with Spree's API.

All examples use the Faraday and httpclient gems, as these provide (imo) the best Ruby HTTP API available. Your mileage may vary if you choose to use other gems.

There are not that many examples at the moment. This will change, over time. You can help it change by submitting pull requests to this repo.

Do these examples work?

Sure they do!

There's a catch, though: you have to run them against a sample store setup using Spree's sample data. You can set one up by installing Spree and then running these commands:

bundle exec rake db:reset spree_sample:load AUTO_ACCEPT=1

Which is the equivalant of running:

bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed AUTO_ACCEPT=1
bundle exec rake spree_sample:load --trace

These commands (of course) will kill everything you know and love in your database. If you don't care about the data in your database, run them.

These commands will give you most of what you need. One final thing:

rails console
Spree::User.first.update_column(:spree_api_key, 'fake')

Now you're ready to run the tests and be MEGA SUCCESSFUL.

You can run them in two ways:

ruby test.rb # this will run them all
ruby examples/checkout/walkthrough.rb # this will run just the one

Guest Examples

In order to run guest examples that don't require an API key you must disable API authentication in config/initializers/spree.rb:

Spree::Api::Config[:requires_authentication] = false

License

Do whatever you want with the source code.

Please tell me if you find it useful. I'm reachable through the usual means.

No implied warranty.

Batteries not included. May dissolve in water. Keep out of reach of children.

spree_api_examples's People

Contributors

bdq avatar radar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spree_api_examples's Issues

User creation example

When importing orders, can your shows a first_name, last_name fields (which is used for the shipping) but does not show an example of how the user record should be created

paperclip reports spoofed image file type for some images

While uploading images I found that some of them were failing to upload with the error
Content Type Spoof: Filename local.path (image/jpeg from Headers, [] from Extension), content type discovered from file command: image/jpeg. See documentation to allow this combination.

I found that adding the file name while uploading fixed this issue

file_name = File.basename(image_path)
attachment = Faraday::UploadIO.new(image, file_type, file_name)

Not sure if you want to add this in to the example code, shouldn't ever hurt to send the file name but this should at least help someone with the same issue.

JSON client fails to create blank order

Ruby base runs fine, but then JSON base fails

vagrant@vagrant:/vagrant/spree_api_examples$ ruby examples/checkout/walkthrough.rb
Running Examples::Checkout::Walkthrough with Clients::Base
----------------------------------------------------------
[SUCCESS] Created new checkout.
[SUCCESS] Email set automatically on order successfully.
[SUCCESS] Added a line item.
[SUCCESS] Transitioned order into address state.
[SUCCESS] Retrieved a list of countries.
[SUCCESS] Retrieved a list of states.
[SUCCESS] Address details added.
[SUCCESS] Order automatically transitioned to 'delivery'.
[SUCCESS] Delivery options selected.
[SUCCESS] Order automatically transitioned to 'payment'.
[SUCCESS] Payment details provided for the order.
[SUCCESS] Order automatically transitioned to 'confirm'.
[SUCCESS] Second payment added to order.
[SUCCESS] Order automatically transitioned to 'confirm' again.
[SUCCESS] First payment has been marked as invalid.
[SUCCESS] Second payment is in checkout state.
[SUCCESS] Order complete!
Running Examples::Checkout::Walkthrough with Clients::JSON
----------------------------------------------------------
[FAILURE] Failed to create a new blank checkout. (422)
Error occurred at: examples/checkout/walkthrough.rb:28:in `run'

Error message in the web log: param is missing or the value is empty: order

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.