prestashopper 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +24 -0
- data/lib/prestashopper.rb +2 -0
- data/lib/prestashopper/api.rb +47 -0
- data/lib/prestashopper/product.rb +21 -0
- data/lib/prestashopper/version.rb +1 -1
- data/prestashopper.gemspec +2 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7defedaa887ce629c6fbd24c8d898ed9a53bff7
|
4
|
+
data.tar.gz: bc8db2121a7c38e8fe0099c474cab3810c4463c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 191b15c18a9d4d1cf3da933f5ecd9a0d6442487a70dfb7cb064717267c59a671235c7dd5d4674c24fda1449cf3e2c52dd2e2fa16704be6dd8c10cb72897c7078
|
7
|
+
data.tar.gz: 8850f7fb3acef3b9ee0d7b936c7833b1d878f89b35eb067ea25062043e4d25d049d23aed4c8f1a133645f399fea77620180fa2a1e3253906705a5b4cb318bad7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.2.0 (August 19, 2016)
|
4
|
+
|
5
|
+
Features:
|
6
|
+
|
7
|
+
- Added badges to README (gem version, build status, rubydoc.info docs)
|
8
|
+
- Get list of resources an API key can access
|
9
|
+
- Get all products as an array of hashes
|
10
|
+
|
3
11
|
## 0.1.0 (August 12, 2016)
|
4
12
|
|
5
13
|
Features:
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/prestashopper.svg)](https://badge.fury.io/rb/prestashopper)
|
2
|
+
[![Build Status](https://semaphoreci.com/api/v1/amatriain/prestashopper/branches/master/badge.svg)](https://semaphoreci.com/amatriain/prestashopper)
|
3
|
+
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/amatriain/prestashopper/master)
|
4
|
+
|
1
5
|
# Prestashopper
|
2
6
|
|
3
7
|
Prestashopper is a ruby gem to interact with a Prestashop API. It has been tested with Prestashop v1.6.1.2
|
@@ -42,6 +46,26 @@ Prestashopper.valid_key? 'my.prestashop.com', 'VALID_KEY'
|
|
42
46
|
=> true
|
43
47
|
```
|
44
48
|
|
49
|
+
### Getting an API instance
|
50
|
+
```
|
51
|
+
api = Prestashopper::API.new 'my.prestashop.com', 'VALID_KEY'
|
52
|
+
```
|
53
|
+
|
54
|
+
### Listing resources that can be accessed from an API instance
|
55
|
+
```
|
56
|
+
api.resources
|
57
|
+
=> [:customers, :orders, :products]
|
58
|
+
```
|
59
|
+
|
60
|
+
### Gettting products
|
61
|
+
```
|
62
|
+
products = api.get_products
|
63
|
+
products[0].description
|
64
|
+
=> "product 1"
|
65
|
+
products[0].price
|
66
|
+
=> "24.71"
|
67
|
+
```
|
68
|
+
|
45
69
|
## Development
|
46
70
|
|
47
71
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. The documentation can be generated from the yard comments running `yard doc`.
|
data/lib/prestashopper.rb
CHANGED
data/lib/prestashopper/api.rb
CHANGED
@@ -3,5 +3,52 @@ module Prestashopper
|
|
3
3
|
# Each instance represents a Prestashop API instance.
|
4
4
|
class API
|
5
5
|
|
6
|
+
# @return [String] URI of the Prestashop API
|
7
|
+
attr_reader :api_uri
|
8
|
+
|
9
|
+
# @return [String] API key
|
10
|
+
attr_reader :key
|
11
|
+
|
12
|
+
# Create a new instance
|
13
|
+
# @param url [String] base URL of the Prestashop installation. Do not append "/api" to it, the gem does it internally.
|
14
|
+
# E.g. use "http://my.prestashop.com", not "http://my.prestashop.com/api"
|
15
|
+
# @param key [String] a valid API key
|
16
|
+
def initialize(url, key)
|
17
|
+
@api_uri = UriHandler.api_uri url
|
18
|
+
@key = key
|
19
|
+
@resources_res = RestClient::Resource.new @api_uri, user: @key, password: ''
|
20
|
+
end
|
21
|
+
|
22
|
+
# List resources that the API key can access
|
23
|
+
# @return [Array<Symbol>] list of resources the API can access
|
24
|
+
def resources
|
25
|
+
xml = @resources_res.get.body
|
26
|
+
xml_doc = Nokogiri::XML xml
|
27
|
+
nodes = xml_doc.xpath '/prestashop/api/*'
|
28
|
+
resources_list = []
|
29
|
+
nodes.each{|n| resources_list << n.name.to_sym}
|
30
|
+
return resources_list
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get all products data
|
34
|
+
# @return [Array<Hash>] list of products. Each product is represented by a hash with all its attributes.
|
35
|
+
def get_products
|
36
|
+
# /api/products returns XML with the IDs of each individual product
|
37
|
+
xml_products = @resources_res['products'].get.body
|
38
|
+
xml_products_doc = Nokogiri::XML xml_products
|
39
|
+
products_nodes = xml_products_doc.xpath '/prestashop/products/*/@id'
|
40
|
+
ids_list = []
|
41
|
+
products_nodes.each{|n| ids_list << n.value}
|
42
|
+
|
43
|
+
# GET each individual product to get the whole data
|
44
|
+
products = []
|
45
|
+
ids_list.each do |id|
|
46
|
+
xml_product = @resources_res["products/#{id}"].get.body
|
47
|
+
product = Product.xml2hash xml_product
|
48
|
+
products << product
|
49
|
+
end
|
50
|
+
|
51
|
+
return products
|
52
|
+
end
|
6
53
|
end
|
7
54
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
|
3
|
+
module Prestashopper
|
4
|
+
|
5
|
+
# Has methods to convert the XML returned from the API to a ruby hash
|
6
|
+
class Product
|
7
|
+
|
8
|
+
# Convert a product XML returned by the Prestashop API to a ruby hash, more manageable
|
9
|
+
# @param xml [String] XML returned by the Prestashop API
|
10
|
+
# @return [Hash] the product converted to a hash representation
|
11
|
+
def self.xml2hash(xml)
|
12
|
+
xml_doc = Nokogiri::XML( xml).remove_namespaces!
|
13
|
+
# Strip surrounding tag
|
14
|
+
nodes = xml_doc.xpath '/prestashop/*'
|
15
|
+
product_xml = nodes.to_s
|
16
|
+
product_hash = Hash.from_xml product_xml
|
17
|
+
|
18
|
+
return product_hash['product']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/prestashopper.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_runtime_dependency 'rest-client', '~> 2.0'
|
22
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
23
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.0'
|
22
24
|
|
23
25
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
24
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prestashopper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alfredo Amatriain
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: bundler
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,6 +139,7 @@ files:
|
|
111
139
|
- bin/setup
|
112
140
|
- lib/prestashopper.rb
|
113
141
|
- lib/prestashopper/api.rb
|
142
|
+
- lib/prestashopper/product.rb
|
114
143
|
- lib/prestashopper/uri_handler.rb
|
115
144
|
- lib/prestashopper/version.rb
|
116
145
|
- prestashopper.gemspec
|