prestashopper 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/prestashopper.rb +63 -0
- data/lib/prestashopper/api.rb +7 -0
- data/lib/prestashopper/uri_handler.rb +26 -0
- data/lib/prestashopper/version.rb +3 -0
- data/prestashopper.gemspec +28 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb45387162f612a1a13f6fddc9aa76fe44439c7d
|
4
|
+
data.tar.gz: f9cbe7668eeae82ca4aab0d8a8b53f86f99693ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe784e19c467bbb8d600fe7a53634584a45bfa538207d485468f20d35d89116f099f3b438d62828343458215fb35d7e6b944257714f7d308a8a3587054c4190a
|
7
|
+
data.tar.gz: 6902fa4d21968891c88db3450b4868741a2d690d8f4d75a795936529020931285a711721908f99f170de1f4fbdb7cbed016ffca1668d0607157ab0b418163101
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alfredo Amatriain
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Prestashopper
|
2
|
+
|
3
|
+
Prestashopper is a ruby gem to interact with a Prestashop API. It has been tested with Prestashop v1.6.1.2
|
4
|
+
|
5
|
+
Prestashop is an open source e-commerce application written in PHP: [visit the homepage](https://www.prestashop.com/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'prestashopper'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install prestashopper
|
22
|
+
|
23
|
+
## Enabling the Prestashop API and creating an API key
|
24
|
+
|
25
|
+
For security reasons the Prestashop API is disabled by default. To be able to use this gem you will have to enable it.
|
26
|
+
|
27
|
+
Once enabled you'll have to create an API key and give it the necessary permissions for the operations you intend to perform. Most methods in this gem need a valid API key.
|
28
|
+
|
29
|
+
For more information about enabling the Prestashop API and managing API keys and their permissions, see the [official documentation](http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service).
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Checking if the Prestashop API is enabled
|
34
|
+
```
|
35
|
+
Prestashopper.api_enabled? 'my.prestashop.com'
|
36
|
+
=> true
|
37
|
+
```
|
38
|
+
|
39
|
+
### Checking if an API key is valid
|
40
|
+
```
|
41
|
+
Prestashopper.valid_key? 'my.prestashop.com', 'VALID_KEY'
|
42
|
+
=> true
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
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`.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/amatriain/prestashopper](https://github.com/amatriain/prestashopper).
|
54
|
+
|
55
|
+
|
56
|
+
## License
|
57
|
+
|
58
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
59
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'prestashopper'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'prestashopper/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'prestashopper/api'
|
4
|
+
require 'prestashopper/uri_handler'
|
5
|
+
|
6
|
+
# @author Alfredo Amatriain <geralt@gmail.com>
|
7
|
+
#
|
8
|
+
# Ruby gem for interacting with the Prestashop API.
|
9
|
+
module Prestashopper
|
10
|
+
|
11
|
+
# Check if there is an enabled API in a Prestashop instance.
|
12
|
+
# @param url [String] base URL of the Prestashop installation. Do not append "/api" to it, the gem does it internally.
|
13
|
+
# E.g. use "http://my.prestashop.com", not "http://my.prestashop.com/api"
|
14
|
+
# @return [boolean] true if the API is enabled, false if it is disabled
|
15
|
+
# @raise [RestClient::Exception] if there is an error during HTTP GET
|
16
|
+
# @raise [StandardError] if a response different from 401 or 503 is received (not counting redirect responses,
|
17
|
+
# which will be followed)
|
18
|
+
def self.api_enabled?(url)
|
19
|
+
api_uri = UriHandler.api_uri url
|
20
|
+
res = RestClient::Resource.new api_uri, user: '', password: ''
|
21
|
+
begin
|
22
|
+
response = res.get
|
23
|
+
# We don't send an API key, so an HTTP error code should be returned. Execution shouldn't reach here normally.
|
24
|
+
raise StandardError.new "Expected 401 or 503 response from Prestashop API #{api_uri} without key, instead received <#{response.code}> #{response.body}"
|
25
|
+
rescue RestClient::Exception => e
|
26
|
+
if e.response.code == 401
|
27
|
+
return true # "Unauthorized" response means API is enabled
|
28
|
+
elsif e.response.code == 503
|
29
|
+
return false # "Service Unavailable" response means API is disabled
|
30
|
+
else
|
31
|
+
raise e # Any other HTTP error code means something is wrong
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Check if an API key is valid.
|
37
|
+
# @param url [String] base URL of the Prestashop installation. Do not append "/api" to it, the gem does it internally.
|
38
|
+
# E.g. use "http://my.prestashop.com", not "http://my.prestashop.com/api"
|
39
|
+
# @param key [String] the key to check
|
40
|
+
# @return [boolean] true if key is valid, false otherwise
|
41
|
+
# @raise [RestClient::Exception] if there is an error during HTTP GET
|
42
|
+
# @raise [StandardError] if a response different from 200 or 401 is received (not counting redirect responses,
|
43
|
+
# which will be followed)
|
44
|
+
def self.valid_key?(url, key)
|
45
|
+
api_uri = UriHandler.api_uri url
|
46
|
+
res = RestClient::Resource.new api_uri, user: key, password: ''
|
47
|
+
begin
|
48
|
+
response = res.get
|
49
|
+
if response.code == 200 # OK response means API key is valid
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
raise StandardError.new "Expected 200 or 401 response from Prestashop API #{api_uri} with key #{key}, instead received <#{response.code}> #{response.body}"
|
53
|
+
end
|
54
|
+
rescue RestClient::Exception => e
|
55
|
+
if e.response.code == 401
|
56
|
+
return false # "Unauthorized" response means API key is invalid
|
57
|
+
else
|
58
|
+
raise e # Any other HTTP error code means something is wrong
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Prestashopper
|
4
|
+
|
5
|
+
# Handle URIs, converting from base Prestashop URL to API URIs
|
6
|
+
class UriHandler
|
7
|
+
API_PATH = 'api/'
|
8
|
+
|
9
|
+
# Convert a base Prestashop URL to its API URI
|
10
|
+
# @param base_url [String] a Prestashop base URL. Do not append "/api", it is appended internally. E.g. use
|
11
|
+
# "http://my.prestashop.com/", not "http://my.prestashop.com/api". URIs without scheme (e.g. "my.prestashop.com")
|
12
|
+
# are assumed to be http:// by default.
|
13
|
+
# @return [String] the URI of the API for this Prestashop instance
|
14
|
+
def self.api_uri(base_url)
|
15
|
+
# Base URL must end in '/' so that we can properly append other path fragments for the API paths
|
16
|
+
base_url.strip!
|
17
|
+
base_url += '/' unless base_url[-1] == '/'
|
18
|
+
|
19
|
+
# Add http:// scheme if the scheme is missing from the base url
|
20
|
+
base_url = 'http://' + base_url if URI.parse(base_url).scheme.nil?
|
21
|
+
|
22
|
+
uri = URI.join base_url, API_PATH
|
23
|
+
return uri.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'prestashopper/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'prestashopper'
|
8
|
+
spec.version = Prestashopper::VERSION
|
9
|
+
spec.authors = ['Alfredo Amatriain']
|
10
|
+
spec.email = ['geralt@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby gem to interact with the Prestashop API.}
|
13
|
+
spec.homepage = 'https://github.com/amatriain/prestashopper'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'rest-client', '~> 2.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
26
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
27
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prestashopper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alfredo Amatriain
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- geralt@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- CHANGELOG.md
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/prestashopper.rb
|
113
|
+
- lib/prestashopper/api.rb
|
114
|
+
- lib/prestashopper/uri_handler.rb
|
115
|
+
- lib/prestashopper/version.rb
|
116
|
+
- prestashopper.gemspec
|
117
|
+
homepage: https://github.com/amatriain/prestashopper
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.5.1
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Ruby gem to interact with the Prestashop API.
|
141
|
+
test_files: []
|