https://github.com/iaintshine/presta_shop
A library for Ruby to interact with the PrestaShop's Web Service API
https://github.com/iaintshine/presta_shop
Last synced: about 2 months ago
JSON representation
A library for Ruby to interact with the PrestaShop's Web Service API
- Host: GitHub
- URL: https://github.com/iaintshine/presta_shop
- Owner: iaintshine
- License: mit
- Created: 2013-07-10T15:18:57.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-04-22T12:53:12.000Z (about 10 years ago)
- Last Synced: 2025-03-30T08:32:14.508Z (3 months ago)
- Language: Ruby
- Size: 367 KB
- Stars: 8
- Watchers: 3
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PrestaShop
The Presta Shop API gem allows Ruby developers to programmatically interact with Presta Shop's Web Service API.
The API is implemented as XML over HTTP using five verbs: HEAD/GET/POST/PUT/DELETE
## Installation
Add this line to your application's Gemfile:
gem 'presta_shop', :git => 'https://github.com/iaintshine/presta_shop.git'
And then execute:
$ bundle
Or install it yourself as:
$ gem install presta_shop
## Usage
1. Using your admin panel generate an authentication key.
2. Assign rights for each resource that you want to make available for this key.
3. Initialize the library
```ruby
PrestaShop.configure do |c|
c.api_url = "http://your/presta/shop"
c.api_key = "YOURAPIKEY"
endPrestaShop.bootstrap!
```4. Make a request and use a reponse
```ruby
shop = PrestaShop.get(:resource => :shops, :id => 1)
puts shop[:name]
```You can use a new high-level ActiveRecord-like ORM style as well
```ruby
shop = PrestaShop::Shop.find(1)
puts shop.name
```
### ActiveRecord-like methodsThese are the basic ActiveRecord-like methods you can use with your models:
```ruby
# Check if resource exists using an id
PrestaShop::Shop.exists? id# Fetch a resource using an id
PrestaShop::Shop.find id
# Fetch a collection of resources
PrestaShop::Shop.all
# Create a new resource
PrestaShop::Shop.create name: "new shop", id_category: 2 ...# Save a new resource
shop = PrestaShop::Shop.new name: "new shop", ...
shop.save!shop.persisted?
# Update an existing resource
shop = PrestaShop::Shop.find id
shop.name = "changed name"
shop.save!# Destroy a resource without fetching it using an id
PrestaShop::Shop.destroy id# Destroy a fetched resource
shop = PrestaShop::Shop.find id
shop.destroy!shop.destroyed?
```
### Low-level api access
```ruby
# Check if resource exists using an id
PrestaShop.head resource: :shops, id: id# Fetch a resource using an id
PrestaShop.get resource: :shops, id: id
# Fetch a collection of resources
PrestaShop::get resource: :shops
# Create a new resource
shop = { name: "new shop", id_category: 2 ... }
PrestaShop.create resource: :shops,
payload: shop# Update an existing resource
PrestaShop.update resource: :shops, id: shop[:id], payload: :shop# Destroy a resource using an id
PrestaShop.delete resource: :shops, id: id
```## Supported resources
For a list of supported resources, see file `presta_shop/resources.rb` or `presta_shop/models/` subdirectory.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request