magento 0.2.0 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8bc5f8a39bdb839264e76b211f08b5ce3621340c64e866295456ec136180155
4
- data.tar.gz: 4711ecfd3c80b9f52dce500b8d832ebe9dd2f3ef981e9245eb4730bcfc1bc529
3
+ metadata.gz: 4683ba34529189e0ae2a417065da3514b380463a51ea7b80a95d720e0db5a1e4
4
+ data.tar.gz: 5ac940a291de0ad07891cf34958d014c0b82e2a4249bf0b205d1622b066c6fff
5
5
  SHA512:
6
- metadata.gz: c4eeca2012769013e626ffa61689d487ebcf92430cd9a0740254f16bffb2ec11f62b0b8c519446fe314a571a8def6c20e46ce80def22f1ea599ff4350d81c9c3
7
- data.tar.gz: df313171a3767e8bf326fbf6bb45aa53010f1a8b3f7469b4cb27cb44b82ea2e30fa19eeb7165fe3380e8c50c89760c38721cdeeb5d24b3236325da94411a1fb9
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
@@ -25,4 +25,4 @@ test/vcr_cassettes
25
25
 
26
26
  .vscode
27
27
  .byebug_history
28
- test.rb
28
+ /*test.rb
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.2.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
- ## Product
26
-
27
- ### Get product details by sku
28
-
29
- ```rb
30
- Magento::Product.find_by_sku('sku-test')
31
- ```
32
-
33
- ## Customer
34
-
35
- ### Get customer by id
36
- ```rb
37
- Magento::Customer.find(id) # or
38
- Magento::Customer.find_by_id(id)
39
- ```
40
-
41
- ### Get customer by token
42
- ```rb
43
- Magento::Customer.find_by_token('user_token')
44
- ```
45
-
46
- ## Countries
47
-
48
- ### Get available regions for a country
49
-
50
- ```rb
51
- country = Magento::Country.find('BR')
52
-
53
- country.available_regions
54
- ```
55
-
56
- # TODO
57
- ### Get product list
58
-
59
- Get all
60
- ```rb
61
- Magento::Product.all()
62
- ```
63
-
64
- Set page and quantity per page
65
- ```rb
66
- Magento::Product.all(page: 1, page_size: 25) # Default page size is 50
67
- ```
68
-
69
- Filter list by attribute
70
- ```rb
71
- Magento::Product.all(name_like: 'IPhone%')
72
-
73
- Magento::Product.all(price_gt: 100, page: 2)
74
- ```
75
-
76
- ### Search products
77
- ```rb
78
- Magento::Product.search('tshort')
79
- ```
80
-
81
- ## Order
82
-
83
- ### Create Order as admin user
84
-
85
- See the [documentation](https://magento.redoc.ly/2.4-admin/#operation/salesOrderRepositoryV1SavePost) to all attributes
86
-
87
- ```rb
88
- Magento::Order.create(
89
- customer_firstname: '',
90
- customer_lastname: '',
91
- customer_email: '',
92
- # others attrbutes ...,
93
- items: [
94
- {
95
- sku: '',
96
- price: '',
97
- qty_ordered: 1,
98
- # others attrbutes ...,
99
- }
100
- ],
101
- billing_address: {
102
- # attrbutes...
103
- },
104
- payment: {
105
- # attrbutes...
106
- },
107
- extension_attributes: {
108
- # attrbutes...
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
+ ```
@@ -1,31 +1,35 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- require_relative 'magento/errors'
6
- require_relative 'magento/request'
7
- require_relative 'magento/model'
8
- require_relative 'magento/product'
9
- require_relative 'magento/country'
10
- require_relative 'magento/customer'
11
-
12
- Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
13
-
14
- module Magento
15
- class << self
16
- attr_accessor :url, :open_timeout, :timeout, :token, :store
17
- end
18
-
19
- self.url = ENV['MAGENTO_URL']
20
- self.open_timeout = 30
21
- self.timeout = 90
22
- self.token = ENV['MAGENTO_TOKEN']
23
- self.store = ENV['MAGENTO_STORE'] || :all
24
-
25
- def self.production?
26
- ENV['RACK_ENV'] == 'production' ||
27
- ENV['RAILS_ENV'] == 'production' ||
28
- ENV['PRODUCTION'] ||
29
- ENV['production']
30
- end
31
- end
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
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class Category < Model
3
+ end
4
+ end
@@ -1,10 +1,5 @@
1
- module Magento
2
- class Country < Model
3
- class << self
4
- def find(code)
5
- country_hash = request.get("directory/countries/#{code}").parse
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