shoper 0.0.1
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/LICENSE +21 -0
- data/README.md +14 -0
- data/build.sh +4 -0
- data/lib/shoper.rb +77 -0
- data/shoper.gemspec +22 -0
- data/test.rb +44 -0
- data/test.sh +13 -0
- metadata +70 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fe4460d446911cf55ab65d16c109cade30644fde74aaf8656b4b95d86ac10198
|
|
4
|
+
data.tar.gz: d5187be2533696cb1da623a48e7c2ff213dc13da81e71436ab060861fb84692f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5792ceba534e613d169d4ddbb0f7c93b71040b2a41f170ac6fee21bb5694d5e311a98a0f811e73858b66af84afe5abcf886eba489f9d72a4065d42c9bb673459
|
|
7
|
+
data.tar.gz: 9568ce8416b4054139b560bd727ba9426e3865c90b38bcd31ca2b918cc84143c7d97b5d73f3b7230e3420d2f855232b6e14133b841781c19a3a34fba8bde2b8d
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Zielona Fabryka
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/build.sh
ADDED
data/lib/shoper.rb
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require "rest-client"
|
|
2
|
+
require "base64"
|
|
3
|
+
require "json"
|
|
4
|
+
|
|
5
|
+
# Shoper REST API main class
|
|
6
|
+
class Shoper
|
|
7
|
+
def initialize(shoper_url, shoper_username, shoper_password)
|
|
8
|
+
@configuration = {
|
|
9
|
+
:shoper => {},
|
|
10
|
+
}
|
|
11
|
+
@configuration[:shoper][:url] = shoper_url
|
|
12
|
+
@configuration[:shoper][:api] = @configuration[:shoper][:url] + "/webapi/rest/"
|
|
13
|
+
@configuration[:shoper][:username] = shoper_username
|
|
14
|
+
@configuration[:shoper][:password] = shoper_password
|
|
15
|
+
self.get_token
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_token
|
|
19
|
+
r = RestClient::Request.execute(
|
|
20
|
+
method: :post,
|
|
21
|
+
url: @configuration[:shoper][:url] + "/webapi/rest/auth",
|
|
22
|
+
headers: {
|
|
23
|
+
"Authorization" => "Basic " + Base64::encode64(
|
|
24
|
+
@configuration[:shoper][:username] + ":" + @configuration[:shoper][:password]
|
|
25
|
+
),
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
j = JSON.parse(r)
|
|
29
|
+
@configuration[:shoper][:token] = j["access_token"]
|
|
30
|
+
@configuration[:shoper][:token_expires] = Time.now + j["expires_in"]
|
|
31
|
+
@configuration[:shoper][:token_type] = j["token_type"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Shoper.resource(resource, action, params, id, data)
|
|
35
|
+
# * get -> /aboutpages/<id>
|
|
36
|
+
# * update -> /aboutpages/<id>
|
|
37
|
+
# * delete -> /aboutpages/<id>
|
|
38
|
+
# * insert -> /aboutpages
|
|
39
|
+
# * list -> /aboutpages
|
|
40
|
+
def resource(resource, action, data = { :id => nil, :params => nil, :data => nil })
|
|
41
|
+
case action
|
|
42
|
+
when "get", "update", "delete"
|
|
43
|
+
endpoint = resource + "/" + data[:id]
|
|
44
|
+
when "insert", "list"
|
|
45
|
+
endpoint = resource
|
|
46
|
+
else
|
|
47
|
+
return { :error => true }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
pp endpoint
|
|
51
|
+
# Check if Shoper Token is still valid
|
|
52
|
+
self.get_token if Time.now > @configuration[:shoper][:token_expires]
|
|
53
|
+
|
|
54
|
+
r = RestClient::Resource.new(@configuration[:shoper][:api] + endpoint,
|
|
55
|
+
:headers => {
|
|
56
|
+
:authorization => "Bearer " +
|
|
57
|
+
@configuration[:shoper][:token],
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
case action
|
|
61
|
+
when "get"
|
|
62
|
+
res = r.get :params => data[:params]
|
|
63
|
+
when "update"
|
|
64
|
+
res = r.put data[:data].to_json, :content_type => :json
|
|
65
|
+
when "delete"
|
|
66
|
+
res = r.delete
|
|
67
|
+
when "insert"
|
|
68
|
+
pp data[:data].to_json
|
|
69
|
+
res = r.post data[:data].to_json, :content_type => :json
|
|
70
|
+
when "list"
|
|
71
|
+
res = r.get
|
|
72
|
+
else
|
|
73
|
+
return { :error => true }
|
|
74
|
+
end
|
|
75
|
+
pp JSON.parse(res)
|
|
76
|
+
end
|
|
77
|
+
end
|
data/shoper.gemspec
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
# Required BEGIN
|
|
3
|
+
s.name = "shoper"
|
|
4
|
+
s.version = "0.0.1"
|
|
5
|
+
s.authors = ["Pawel 'felixd' Wojciechowski"]
|
|
6
|
+
s.summary = %q{Shoper REST API}
|
|
7
|
+
s.files = Dir["lib/*.rb"] + Dir["bin/*"]
|
|
8
|
+
s.files += Dir["[A-Z]*"] + Dir["test/**/*"]
|
|
9
|
+
# Required END
|
|
10
|
+
# Recommended BEGIN
|
|
11
|
+
s.licenses = ["MIT"]
|
|
12
|
+
# Recommended BEGIN
|
|
13
|
+
s.homepage = "https://github.com/zielonafabryka/ruby-gem-shoper"
|
|
14
|
+
s.email = %q{felixd@wp.pl}
|
|
15
|
+
s.date = %q{2020-04-14}
|
|
16
|
+
s.description = %q{Shoper e-commerce Gem. This project aims to integrate Shoper REST API support in Ruby. More information can be found here: https://developers.shoper.pl/developers/api/getting-started}
|
|
17
|
+
s.require_paths = ["lib"]
|
|
18
|
+
|
|
19
|
+
s.add_runtime_dependency "rest-client", "~> 2.1", ">= 2.1.0"
|
|
20
|
+
|
|
21
|
+
s.required_ruby_version = ">= 2.0.0"
|
|
22
|
+
end
|
data/test.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require "shoper"
|
|
2
|
+
|
|
3
|
+
shoper = Shoper.new(
|
|
4
|
+
ENV["SHOPER_URL"], ENV["SHOPER_USER"], ENV["SHOPER_PASS"]
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
i = 4170
|
|
8
|
+
while i < 4171
|
|
9
|
+
done = false
|
|
10
|
+
while done != true
|
|
11
|
+
begin
|
|
12
|
+
response = shoper.resource "products", "delete", { :id => i.to_s }
|
|
13
|
+
pp response
|
|
14
|
+
done = true
|
|
15
|
+
rescue RestClient::TooManyRequests
|
|
16
|
+
sleep 4
|
|
17
|
+
rescue RestClient::NotFound => e
|
|
18
|
+
pp e.http_headers
|
|
19
|
+
puts "Not found"
|
|
20
|
+
done = true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
i += 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
p = {
|
|
28
|
+
:code => "1234567",
|
|
29
|
+
:category_id => 1,
|
|
30
|
+
:translations => {
|
|
31
|
+
:pl_PL => {
|
|
32
|
+
:name => "Nazwa produktu",
|
|
33
|
+
:description => "Opis produktu",
|
|
34
|
+
:active => true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
:stock => {
|
|
38
|
+
:price => 666,
|
|
39
|
+
:active => 1,
|
|
40
|
+
:stock => 1,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pp shoper.resource "products", "insert", { :data => p }
|
data/test.sh
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# export SHOPER_URL="https://sklep.zielonafabryka.pl"
|
|
4
|
+
# export SHOPER_USER="webapi"
|
|
5
|
+
# export SHOPER_PASS="CHqc8AC5rhexPeYZ"
|
|
6
|
+
|
|
7
|
+
export SHOPER_URL="https://devshop-609684.shoparena.pl"
|
|
8
|
+
export SHOPER_USER="webapi"
|
|
9
|
+
export SHOPER_PASS="Testy12345"
|
|
10
|
+
|
|
11
|
+
echo $SHOPER_URL
|
|
12
|
+
ruby test.rb
|
|
13
|
+
|
metadata
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: shoper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pawel 'felixd' Wojciechowski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-04-14 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.1'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 2.1.0
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '2.1'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 2.1.0
|
|
33
|
+
description: 'Shoper e-commerce Gem. This project aims to integrate Shoper REST API
|
|
34
|
+
support in Ruby. More information can be found here: https://developers.shoper.pl/developers/api/getting-started'
|
|
35
|
+
email: felixd@wp.pl
|
|
36
|
+
executables: []
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- LICENSE
|
|
41
|
+
- README.md
|
|
42
|
+
- build.sh
|
|
43
|
+
- lib/shoper.rb
|
|
44
|
+
- shoper.gemspec
|
|
45
|
+
- test.rb
|
|
46
|
+
- test.sh
|
|
47
|
+
homepage: https://github.com/zielonafabryka/ruby-gem-shoper
|
|
48
|
+
licenses:
|
|
49
|
+
- MIT
|
|
50
|
+
metadata: {}
|
|
51
|
+
post_install_message:
|
|
52
|
+
rdoc_options: []
|
|
53
|
+
require_paths:
|
|
54
|
+
- lib
|
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 2.0.0
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
|
+
requirements:
|
|
62
|
+
- - ">="
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '0'
|
|
65
|
+
requirements: []
|
|
66
|
+
rubygems_version: 3.1.2
|
|
67
|
+
signing_key:
|
|
68
|
+
specification_version: 4
|
|
69
|
+
summary: Shoper REST API
|
|
70
|
+
test_files: []
|