magento 0.2.0 → 0.3.7
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 +4 -4
- data/.github/workflows/gem-push.yml +42 -0
- data/.gitignore +1 -1
- data/README.md +186 -111
- data/lib/magento.rb +35 -31
- data/lib/magento/category.rb +4 -0
- data/lib/magento/country.rb +5 -10
- data/lib/magento/customer.rb +13 -18
- data/lib/magento/model.rb +79 -47
- data/lib/magento/model_mapper.rb +71 -0
- data/lib/magento/order.rb +5 -0
- data/lib/magento/product.rb +9 -10
- data/lib/magento/query.rb +150 -0
- data/lib/magento/request.rb +108 -103
- data/lib/magento/shared/address.rb +4 -4
- data/lib/magento/shared/available_regions.rb +4 -4
- data/lib/magento/shared/category_link.rb +6 -6
- data/lib/magento/shared/custom_attribute.rb +4 -4
- data/lib/magento/shared/extension_attribute.rb +3 -3
- data/lib/magento/shared/item.rb +3 -0
- data/lib/magento/shared/media_gallery_entry.rb +4 -4
- data/lib/magento/shared/option.rb +4 -4
- data/lib/magento/shared/payment.rb +3 -0
- data/lib/magento/shared/payment_additional_info.rb +3 -0
- data/lib/magento/shared/product_link.rb +4 -4
- data/lib/magento/shared/region.rb +4 -4
- data/lib/magento/shared/shipping.rb +3 -0
- data/lib/magento/shared/shipping_assignment.rb +3 -0
- data/lib/magento/shared/stock_item.rb +3 -3
- data/lib/magento/shared/tier_price.rb +4 -4
- data/lib/magento/shared/total.rb +3 -0
- data/lib/magento/shared/value.rb +3 -0
- data/lib/magento/version.rb +3 -0
- data/magento-ruby.gemspec +22 -0
- data/magento.gemspec +6 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4683ba34529189e0ae2a417065da3514b380463a51ea7b80a95d720e0db5a1e4
|
4
|
+
data.tar.gz: 5ac940a291de0ad07891cf34958d014c0b82e2a4249bf0b205d1622b066c6fff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57a3425ec1c2cc3a110b650569f8a11ff8957092a52095c47b17c3b4aa6efaea586ebf13543ed10968e7e87047058a894a6d64d136764359cd749b37c286237f
|
7
|
+
data.tar.gz: 966333d6449626d8a929ac6cb6dab27b1e14d18e9d342d599888372d3bd1a2812d2bb4e364f40f38cfdad1e579b38d8f46bfe848c53002fcdeb2c5d63594575e
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6.x
|
20
|
+
|
21
|
+
- name: Publish to GPR
|
22
|
+
run: |
|
23
|
+
mkdir -p $HOME/.gem
|
24
|
+
touch $HOME/.gem/credentials
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
26
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
27
|
+
gem build magento-ruby.gemspec
|
28
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
29
|
+
env:
|
30
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
31
|
+
OWNER: ${{ github.repository_owner }}
|
32
|
+
|
33
|
+
- name: Publish to RubyGems
|
34
|
+
run: |
|
35
|
+
mkdir -p $HOME/.gem
|
36
|
+
touch $HOME/.gem/credentials
|
37
|
+
chmod 0600 $HOME/.gem/credentials
|
38
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
39
|
+
gem build magento.gemspec
|
40
|
+
gem push magento-[0-9]*.gem
|
41
|
+
env:
|
42
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,111 +1,186 @@
|
|
1
|
-
# Magento Ruby library
|
2
|
-
|
3
|
-
## Install
|
4
|
-
|
5
|
-
Add in your Gemfile
|
6
|
-
|
7
|
-
```rb
|
8
|
-
gem 'magento', '~> 0.
|
9
|
-
```
|
10
|
-
|
11
|
-
or run
|
12
|
-
|
13
|
-
```sh
|
14
|
-
gem install magento
|
15
|
-
```
|
16
|
-
|
17
|
-
### Setup
|
18
|
-
|
19
|
-
```rb
|
20
|
-
Magento.url = 'https://yourstore.com'
|
21
|
-
Magento.token = 'MAGENTO_API_KEY'
|
22
|
-
Magento.store = :default # optional, Default is :all
|
23
|
-
```
|
24
|
-
|
25
|
-
##
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Magento::
|
31
|
-
```
|
32
|
-
|
33
|
-
##
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Magento::
|
38
|
-
Magento::
|
39
|
-
```
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
```
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
Magento::Product.
|
62
|
-
```
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
Magento::Product.
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
1
|
+
# Magento Ruby library
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
Add in your Gemfile
|
6
|
+
|
7
|
+
```rb
|
8
|
+
gem 'magento', '~> 0.3.7'
|
9
|
+
```
|
10
|
+
|
11
|
+
or run
|
12
|
+
|
13
|
+
```sh
|
14
|
+
gem install magento
|
15
|
+
```
|
16
|
+
|
17
|
+
### Setup
|
18
|
+
|
19
|
+
```rb
|
20
|
+
Magento.url = 'https://yourstore.com'
|
21
|
+
Magento.token = 'MAGENTO_API_KEY'
|
22
|
+
Magento.store = :default # optional, Default is :all
|
23
|
+
```
|
24
|
+
|
25
|
+
## Models
|
26
|
+
```rb
|
27
|
+
Magento::Product
|
28
|
+
Magento::Order
|
29
|
+
Magento::Country
|
30
|
+
Magento::Category
|
31
|
+
```
|
32
|
+
|
33
|
+
## Get details
|
34
|
+
|
35
|
+
```rb
|
36
|
+
Magento::Product.find('sku-test')
|
37
|
+
Magento::Order.find(25)
|
38
|
+
Magento::Country.find('BR')
|
39
|
+
```
|
40
|
+
\* _same pattern to all models_
|
41
|
+
|
42
|
+
**Outside pattern**
|
43
|
+
|
44
|
+
Get customer by token
|
45
|
+
|
46
|
+
```rb
|
47
|
+
Magento::Customer.find_by_token('user_token')
|
48
|
+
```
|
49
|
+
|
50
|
+
## Get List
|
51
|
+
|
52
|
+
```rb
|
53
|
+
Magento::Product.all
|
54
|
+
```
|
55
|
+
|
56
|
+
#### Select fields:
|
57
|
+
```rb
|
58
|
+
Magento::Product.select(:id, :sku, :name).all
|
59
|
+
Magento::Product.select(:id, :sku, :name, extension_attributes: :category_links).all
|
60
|
+
Magento::Product.select(:id, :sku, :name, extension_attributes: [:category_links, :website_ids]).all
|
61
|
+
Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, { category_links: :category_id }]).all
|
62
|
+
```
|
63
|
+
|
64
|
+
#### Filters:
|
65
|
+
|
66
|
+
```rb
|
67
|
+
Magento::Product.where(name_like: 'IPhone%').all
|
68
|
+
Magento::Product.where(price_gt: 100).all
|
69
|
+
|
70
|
+
# price > 10 AND price < 20
|
71
|
+
Magento::Product.where(price_gt: 10)
|
72
|
+
.where(price_lt: 20).all
|
73
|
+
|
74
|
+
# price < 1 OR price > 100
|
75
|
+
Magento::Product.where(price_lt: 1, price_gt: 100).all
|
76
|
+
|
77
|
+
Magento::Order.where(status_in: [:canceled, :complete]).all
|
78
|
+
```
|
79
|
+
|
80
|
+
| Condition | Notes |
|
81
|
+
| --------- | ----- |
|
82
|
+
|eq | Equals. |
|
83
|
+
|finset | A value within a set of values |
|
84
|
+
|from | The beginning of a range. Must be used with to |
|
85
|
+
|gt | Greater than |
|
86
|
+
|gteq | Greater than or equal |
|
87
|
+
|in | In. The value is an array |
|
88
|
+
|like | Like. The value can contain the SQL wildcard characters when like is specified. |
|
89
|
+
|lt | Less than |
|
90
|
+
|lteq | Less than or equal |
|
91
|
+
|moreq | More or equal |
|
92
|
+
|neq | Not equal |
|
93
|
+
|nfinset | A value that is not within a set of values |
|
94
|
+
|nin | Not in. The value is an array |
|
95
|
+
|notnull | Not null |
|
96
|
+
|null | Null |
|
97
|
+
|to | The end of a range. Must be used with from |
|
98
|
+
|
99
|
+
|
100
|
+
#### SortOrder:
|
101
|
+
|
102
|
+
```rb
|
103
|
+
Magento::Product.order(:sku).all
|
104
|
+
Magento::Product.order(sku: :desc).all
|
105
|
+
Magento::Product.order(status: :desc, name: :asc).all
|
106
|
+
```
|
107
|
+
|
108
|
+
#### Pagination:
|
109
|
+
|
110
|
+
```rb
|
111
|
+
# Set page and quantity per page
|
112
|
+
Magento::Product.page(1).per(25) # Default per is 50
|
113
|
+
```
|
114
|
+
|
115
|
+
#### Example of several options together:
|
116
|
+
```rb
|
117
|
+
Magento::Product.select(:sku, :name, :price)
|
118
|
+
.where(name_like: 'Tshort%')
|
119
|
+
.order(price: :desc)
|
120
|
+
.per(10)
|
121
|
+
.all
|
122
|
+
```
|
123
|
+
|
124
|
+
\* _same pattern to all models_
|
125
|
+
|
126
|
+
## Create
|
127
|
+
|
128
|
+
```rb
|
129
|
+
Magento::Order.create(
|
130
|
+
customer_firstname: '',
|
131
|
+
customer_lastname: '',
|
132
|
+
customer_email: '',
|
133
|
+
# others attrbutes ...,
|
134
|
+
items: [
|
135
|
+
{
|
136
|
+
sku: '',
|
137
|
+
price: '',
|
138
|
+
qty_ordered: 1,
|
139
|
+
# others attrbutes ...,
|
140
|
+
}
|
141
|
+
],
|
142
|
+
billing_address: {
|
143
|
+
# attrbutes...
|
144
|
+
},
|
145
|
+
payment: {
|
146
|
+
# attrbutes...
|
147
|
+
},
|
148
|
+
extension_attributes: {
|
149
|
+
# attrbutes...
|
150
|
+
}
|
151
|
+
)
|
152
|
+
```
|
153
|
+
|
154
|
+
### Update
|
155
|
+
|
156
|
+
```rb
|
157
|
+
product = Magento::Product.find('sku-teste')
|
158
|
+
|
159
|
+
product.name = 'Updated name'
|
160
|
+
product.save
|
161
|
+
|
162
|
+
# or
|
163
|
+
|
164
|
+
product.update(name: 'Updated name')
|
165
|
+
```
|
166
|
+
|
167
|
+
### Delete
|
168
|
+
|
169
|
+
```rb
|
170
|
+
product = Magento::Product.find('sku-teste')
|
171
|
+
|
172
|
+
product.delete
|
173
|
+
|
174
|
+
# or
|
175
|
+
|
176
|
+
Magento::Product.delete('sku-teste')
|
177
|
+
```
|
178
|
+
|
179
|
+
___
|
180
|
+
|
181
|
+
##TODO:
|
182
|
+
|
183
|
+
### Search products
|
184
|
+
```rb
|
185
|
+
Magento::Product.search('tshort')
|
186
|
+
```
|
data/lib/magento.rb
CHANGED
@@ -1,31 +1,35 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
|
6
|
-
require_relative 'magento/
|
7
|
-
require_relative 'magento/
|
8
|
-
require_relative 'magento/
|
9
|
-
require_relative 'magento/
|
10
|
-
require_relative 'magento/
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
self
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
self.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'dry/inflector'
|
5
|
+
|
6
|
+
require_relative 'magento/errors'
|
7
|
+
require_relative 'magento/request'
|
8
|
+
require_relative 'magento/model'
|
9
|
+
require_relative 'magento/model_mapper'
|
10
|
+
require_relative 'magento/query'
|
11
|
+
require_relative 'magento/product'
|
12
|
+
require_relative 'magento/country'
|
13
|
+
require_relative 'magento/customer'
|
14
|
+
require_relative 'magento/order'
|
15
|
+
|
16
|
+
Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
|
17
|
+
|
18
|
+
module Magento
|
19
|
+
class << self
|
20
|
+
attr_accessor :url, :open_timeout, :timeout, :token, :store
|
21
|
+
end
|
22
|
+
|
23
|
+
self.url = ENV['MAGENTO_URL']
|
24
|
+
self.open_timeout = 30
|
25
|
+
self.timeout = 90
|
26
|
+
self.token = ENV['MAGENTO_TOKEN']
|
27
|
+
self.store = ENV['MAGENTO_STORE'] || :all
|
28
|
+
|
29
|
+
def self.production?
|
30
|
+
ENV['RACK_ENV'] == 'production' ||
|
31
|
+
ENV['RAILS_ENV'] == 'production' ||
|
32
|
+
ENV['PRODUCTION'] ||
|
33
|
+
ENV['production']
|
34
|
+
end
|
35
|
+
end
|
data/lib/magento/country.rb
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
module Magento
|
2
|
-
class Country < Model
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
map_hash Country, country_hash
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module Magento
|
2
|
+
class Country < Model
|
3
|
+
self.endpoint = 'directory/countries'
|
4
|
+
end
|
5
|
+
end
|