magento 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +42 -0
- data/README.md +221 -176
- data/lib/magento.rb +43 -35
- data/lib/magento/country.rb +5 -5
- data/lib/magento/customer.rb +13 -13
- data/lib/magento/model.rb +79 -79
- data/lib/magento/model_mapper.rb +2 -6
- data/lib/magento/product.rb +9 -7
- data/lib/magento/query.rb +24 -7
- data/lib/magento/record_collection.rb +66 -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/bundle_product_option.rb +4 -0
- data/lib/magento/shared/category_link.rb +6 -6
- data/lib/magento/shared/configurable_product_option.rb +4 -0
- data/lib/magento/shared/custom_attribute.rb +4 -4
- data/lib/magento/shared/extension_attribute.rb +3 -3
- data/lib/magento/shared/filter.rb +4 -0
- data/lib/magento/shared/filter_group.rb +4 -0
- data/lib/magento/shared/media_gallery_entry.rb +4 -4
- data/lib/magento/shared/option.rb +4 -4
- data/lib/magento/shared/product_link.rb +4 -4
- data/lib/magento/shared/region.rb +4 -4
- data/lib/magento/shared/search_criterium.rb +5 -0
- data/lib/magento/shared/stock_item.rb +3 -3
- data/lib/magento/shared/tier_price.rb +4 -4
- data/lib/magento/version.rb +3 -0
- data/magento-ruby.gemspec +22 -0
- data/magento.gemspec +6 -1
- metadata +14 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10797b41b2292eb765414cf4757cca8e92d6eeaa604ae3c59da76763e11dce9e
|
4
|
+
data.tar.gz: 683f76e2c1b7215e279459bd5eca921caba0e58fe18d299a29c256a0a5e11b94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8c44416f426c6c57bd402cd2d794027ce811bdd1d2e001502d19ffc785e3cb16b26d01fa983c1a3e1582a2d2a6b18f33a3a6f472230069abb33d75263676060
|
7
|
+
data.tar.gz: 5175d8d609601f3b207e29f92cfa38fff076c7ec51a225c274cbdfbd5d6a81edc99e3f8069ebeed100b838899add3c875c70054afa2de70601d69148270ad521
|
@@ -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/README.md
CHANGED
@@ -1,176 +1,221 @@
|
|
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
|
-
## 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
|
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
|
-
|
71
|
-
|
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
|
-
```rb
|
103
|
-
|
104
|
-
Magento::Product.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
.
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
)
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
```
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
```rb
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
#
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
1
|
+
# Magento Ruby library
|
2
|
+
|
3
|
+
## Install
|
4
|
+
|
5
|
+
Add in your Gemfile
|
6
|
+
|
7
|
+
```rb
|
8
|
+
gem 'magento', '~> 0.4.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
|
+
## 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) # Current page, Default is 1
|
113
|
+
.page_size(25) # Default is 50
|
114
|
+
.all
|
115
|
+
|
116
|
+
# per is an alias to page_size
|
117
|
+
Magento::Product.per(25).all
|
118
|
+
```
|
119
|
+
|
120
|
+
#### Example of several options together:
|
121
|
+
```rb
|
122
|
+
products = Magento::Product.select(:sku, :name)
|
123
|
+
.where(name_like: 'biscoito%')
|
124
|
+
.page(1)
|
125
|
+
.page_size(5)
|
126
|
+
.all
|
127
|
+
```
|
128
|
+
|
129
|
+
\* _same pattern to all models_
|
130
|
+
|
131
|
+
### Response
|
132
|
+
|
133
|
+
The `all` method retorns a `Magento::RecordCollection` instance
|
134
|
+
|
135
|
+
```rb
|
136
|
+
products.first
|
137
|
+
# #<Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
|
138
|
+
|
139
|
+
products[0]
|
140
|
+
# #<Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
|
141
|
+
|
142
|
+
products.last
|
143
|
+
# #<Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
|
144
|
+
|
145
|
+
products.map(&:sku)
|
146
|
+
# ["2100", "792", "836", "913", "964"]
|
147
|
+
|
148
|
+
products.size
|
149
|
+
# 5
|
150
|
+
|
151
|
+
products.current_page
|
152
|
+
# 1
|
153
|
+
|
154
|
+
products.page_size
|
155
|
+
# 5
|
156
|
+
|
157
|
+
products.total_count
|
158
|
+
# 307
|
159
|
+
```
|
160
|
+
|
161
|
+
## Create
|
162
|
+
|
163
|
+
```rb
|
164
|
+
Magento::Order.create(
|
165
|
+
customer_firstname: '',
|
166
|
+
customer_lastname: '',
|
167
|
+
customer_email: '',
|
168
|
+
# others attrbutes ...,
|
169
|
+
items: [
|
170
|
+
{
|
171
|
+
sku: '',
|
172
|
+
price: '',
|
173
|
+
qty_ordered: 1,
|
174
|
+
# others attrbutes ...,
|
175
|
+
}
|
176
|
+
],
|
177
|
+
billing_address: {
|
178
|
+
# attrbutes...
|
179
|
+
},
|
180
|
+
payment: {
|
181
|
+
# attrbutes...
|
182
|
+
},
|
183
|
+
extension_attributes: {
|
184
|
+
# attrbutes...
|
185
|
+
}
|
186
|
+
)
|
187
|
+
```
|
188
|
+
|
189
|
+
### Update
|
190
|
+
|
191
|
+
```rb
|
192
|
+
product = Magento::Product.find('sku-teste')
|
193
|
+
|
194
|
+
product.name = 'Updated name'
|
195
|
+
product.save
|
196
|
+
|
197
|
+
# or
|
198
|
+
|
199
|
+
product.update(name: 'Updated name')
|
200
|
+
```
|
201
|
+
|
202
|
+
### Delete
|
203
|
+
|
204
|
+
```rb
|
205
|
+
product = Magento::Product.find('sku-teste')
|
206
|
+
|
207
|
+
product.delete
|
208
|
+
|
209
|
+
# or
|
210
|
+
|
211
|
+
Magento::Product.delete('sku-teste')
|
212
|
+
```
|
213
|
+
|
214
|
+
___
|
215
|
+
|
216
|
+
##TODO:
|
217
|
+
|
218
|
+
### Search products
|
219
|
+
```rb
|
220
|
+
Magento::Product.search('tshort')
|
221
|
+
```
|