magentwo 0.1.86 → 0.1.90

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: 5e51e4d4b67554b49a976fee18670db67323bdcf507a8558ea2cd95d1bc4cc49
4
- data.tar.gz: bba71d4d4bba4e985c266b1271ccc56514abc5001a8a5fbca99d1b9be76410bf
3
+ metadata.gz: 44f33adbf5ffc5496b64a1f441adc196278dbbad3a8aadc318ca19b676aa6858
4
+ data.tar.gz: 20b45d22c24da87f886cb8b09033b6148adc8fe3ea6004ce48423480cf64c965
5
5
  SHA512:
6
- metadata.gz: 69c50939de4b66c4fa9795fda777e22a5952388d89187e8009e6dedda81346a07f81084d751c9cfd9f0185ef30800a107bd29e90596f24c79dc174afcf25b676
7
- data.tar.gz: beed6c14fb9b09a9ca8e68dff160bbec457a6c18c85dd0021c236930b456b8e809ac40738f9f06bfe01400fc4c34d926d87e253e36ae3341c7bb7707544b1aff
6
+ metadata.gz: 2fcce9091f7e9ef49383278c230d8c61b7eb0248ba97c4fc002c8385494fe5fc803bcda137e8b1bc6732f320299a6309d8d9c1789ffa01b29d6944b451791411
7
+ data.tar.gz: 32f13b1fdcf0c182bd6151566bba566a0d6ebfec22220805e03deb6205b0cd7815dc7d274606c7213fa37e41b75573a2d0881f17605ab789aab0e41241518297
data/README.md CHANGED
@@ -1,37 +1,50 @@
1
-
2
1
  This gem is under developement and nowhere near finished but feel free to play around with it.
3
2
  I am grateful for any ideas and suggestions
4
3
 
5
4
  # Magentwo
6
- Ruby-Wrapper for the Magento 2 REST API
7
5
 
6
+ Ruby-Wrapper for the Magento 2 REST API
8
7
 
9
8
  # How to install
9
+
10
10
  To install the Gem directly use
11
+
11
12
  ```
12
13
  gem install magentwo
13
14
  ```
14
15
 
15
16
  or add the following line to your Gemfile
17
+
16
18
  ```
17
19
  gem 'magentwo'
18
20
  ```
21
+
19
22
  and call bundler
23
+
20
24
  ```
21
25
  bundle
22
26
  ```
23
27
 
24
-
25
28
  # How to connect to your magento 2 shop
29
+
26
30
  When only using one connection simply type
31
+
27
32
  ```
28
- Magentwo.connect "http://example.com", "user_name", "password"
33
+ Magentwo.connect "http://example.com", "user_name", "password"
29
34
  ```
35
+
36
+ or
37
+
38
+ ```
39
+ Magentwo.connect_with_token "http://example.com", "my_secret_token"
40
+ ```
41
+
30
42
  When using multiple connections at once you can save the result of `Magentwo.connect` and use the `Magentwo.with` method
43
+
31
44
  ```
32
45
  connection1 = Magentwo.connect "http://example1.com", "user_name", "password"
33
- connection2 = Magentwo.connect "http://example2.com", "user_name", "password"
34
-
46
+ connection2 = Magentwo.connect_with_token "http://example2.com", "my_secret_token"
47
+
35
48
  Magentwo.with (connection1) do
36
49
  #do things in the context of connection1
37
50
  end
@@ -41,6 +54,7 @@ When using multiple connections at once you can save the result of `Magentwo.con
41
54
  ```
42
55
 
43
56
  # How to use
57
+
44
58
  In Magentwo you interact with the API using Models. These are named according the the REST-API specifications of Magento 2
45
59
  The basic functionality is the same for all Models. For products some simple requests would look like this
46
60
 
@@ -52,40 +66,49 @@ Magentwo::Product.fields #returns an array of productfields
52
66
  ```
53
67
 
54
68
  # Filtering
69
+
55
70
  You can filter requests to search for specific elements
56
71
  Here are some examples
57
72
 
58
73
  Look for all customers whose firstname is Foobar
74
+
59
75
  ```
60
76
  Magentwo::Customer.filter(:firstname => "Foobar").all
61
77
  ```
62
78
 
63
79
  Look for all customers whose id is not 42
80
+
64
81
  ```
65
82
  Magentwo::Customer.exclude(:id => 42).all
66
83
  ```
67
84
 
68
85
  You can also combine these
86
+
69
87
  ```
70
88
  Magentwo::Customer.filter(:firstname => "Foobar").exclude(:id => 42).all
71
89
  ```
90
+
72
91
  The `filter` and `exclude` methods can also be used to filter for a set. To Request all Customers whose firstname is either Foo or Bar you could write
92
+
73
93
  ```
74
94
  Magentwo::Customer.filter(:firstname => ["Foo", "bar"]).all
75
95
  ```
76
96
 
77
97
  Look for all Products whose name includes the word "Computer"
98
+
78
99
  ```
79
100
  Magentwo::Product.like(:name => "%Computer%").all
80
101
  ```
81
102
 
82
103
  Compare using `gt`, `gteq`, `lt` or `lteq`. These methods do not seem to work with dates, please use `from` and `to` when e.g. trying to fetch all Products that changed within a certain period.
104
+
83
105
  ```
84
106
  Magentwo::Product.lt(:price => 42).all
85
107
  Magentwo::Product.gt(:id => 1337).first
86
108
  ```
87
109
 
88
110
  Compare using `from` and `to`, you may also use both to specify a range.
111
+
89
112
  ```
90
113
  Magentwo::Product.from(:updated_at => Time.new(2019, 1, 1).all
91
114
  Magentwo::Product.to(:created_at => Time.new(2019, 2, 1).all
@@ -94,30 +117,38 @@ Magentwo::Product.to(:created_at => Time.new(2019, 2, 1).all
94
117
  All of these filter-functions can be chained as needed
95
118
 
96
119
  # Select
120
+
97
121
  If you know which fields you are interested in you can speed up the fetching process by only requesting these fields
122
+
98
123
  ```
99
124
  Magentwo::Product.filter(...).select(:id, :sku).all
100
125
  ```
101
126
 
102
127
  # Pagination
128
+
103
129
  On default the pagesize is set to 20, you can change this with
130
+
104
131
  ```
105
132
  Magentwo.default_page_size=42
106
133
  ```
107
134
 
108
135
  The pagesize can also be set on the fly
109
136
  To request page 2 with a pagesize of 100 simply write the following. The second paramter is optional
137
+
110
138
  ```
111
139
  Magentwo::Product.exclude(:name => "foobar").page(2, 100).all
112
140
  ```
113
141
 
114
142
  To iterate threw all the pages use `each_page`. Again the pagesize parameter is optional
143
+
115
144
  ```
116
145
  Magentwo::Product.each_page(512) do |page|
117
146
  p page
118
147
  end
119
148
  ```
149
+
120
150
  You may also want to fetch all pages of products that match a certain criteria
151
+
121
152
  ```
122
153
  Magentwo::Product.from(:updated_at => my_last_sync_value).each_page(512) do |page|
123
154
  p page
@@ -125,15 +156,19 @@ end
125
156
  ```
126
157
 
127
158
  # Order
159
+
128
160
  By default the results are ordered as Magento2 "thinks" its best. At any place you may add the `order_by` to sepcify this to your liking. If you skip the `ASC/DESC` argument, `ASC` will be set.
161
+
129
162
  ```
130
163
  Magentwo::Product.order_by(:id, "ASC").all
131
164
  Magentwo::Product.order_by(:id, "DESC").all
132
165
  ```
133
166
 
134
167
  # Updates
168
+
135
169
  To update Models back to Magento 2 use the `save` method
136
170
  This switches the first and last name of the Customer Foo Bar
171
+
137
172
  ```
138
173
  customer = Magentwo::Customer.filter(:first_name => "Foo", :last_name => "Bar").first
139
174
  customer.firstname = "Bar"
@@ -142,7 +177,9 @@ customer.save
142
177
  ```
143
178
 
144
179
  # Delete
180
+
145
181
  To delete a Model use the `delete` method
182
+
146
183
  ```
147
184
  product = Magentwo::Product.first
148
185
  product.delete
data/lib/connection.rb CHANGED
@@ -2,15 +2,23 @@ module Magentwo
2
2
  class Connection
3
3
  attr_accessor :host, :port, :user, :password, :token, :base_path, :scheme
4
4
 
5
- def initialize uri, user, password, base_path:nil
5
+ def initialize uri:, user:nil, password:nil, base_path:nil, token:nil
6
6
  uri = URI(uri)
7
7
  @host = uri.host
8
8
  @port = uri.port
9
- @user = user
10
9
  @scheme = uri.scheme
11
- @password = password
12
10
  @base_path = base_path || "/rest/V1"
13
- request_token
11
+
12
+ if (user && password)
13
+ @user = user
14
+ @password = password
15
+ request_token
16
+ elsif (token)
17
+ @token = token
18
+ else
19
+ raise ArgumentError, "expected user/password or token"
20
+ end
21
+
14
22
  end
15
23
 
16
24
  def request_token
data/lib/magentwo.rb CHANGED
@@ -11,7 +11,13 @@ module Magentwo
11
11
  raise ArgumentError, "no host specified" unless host
12
12
  raise ArgumentError, "no user_name specified" unless user_name
13
13
  raise ArgumentError, "no password specified" unless password
14
- Base.adapter = Adapter.new host, user_name, password
14
+ Base.adapter = Adapter.new ({uri: host, user: user_name, password: password})
15
+ end
16
+
17
+ def self.connect_with_token host=nil, token=nil
18
+ raise ArgumentError, "no host specified" unless host
19
+ raise ArgumentError, "no token specified" unless token
20
+ Base.adapter = Adapter.new ({token: token, uri: host})
15
21
  end
16
22
 
17
23
  def self.with connection
data/magentwo.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'magentwo'
3
- s.version = '0.1.86'
3
+ s.version = '0.1.90'
4
4
  s.date = '2019-01-17'
5
5
  s.summary = "Magento 2 API Wrapper"
6
6
  s.description = "Provides a simple Ruby Interface to interact with the Magento 2 API"
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magentwo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.86
4
+ version: 0.1.90
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Mueß
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2019-01-17 00:00:00.000000000 Z
@@ -46,7 +46,7 @@ licenses:
46
46
  - MIT
47
47
  metadata:
48
48
  source_code_uri: https://github.com/Arkad82x/magentwo
49
- post_install_message:
49
+ post_install_message:
50
50
  rdoc_options: []
51
51
  require_paths:
52
52
  - lib
@@ -61,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.0.3
65
- signing_key:
64
+ rubygems_version: 3.2.15
65
+ signing_key:
66
66
  specification_version: 4
67
67
  summary: Magento 2 API Wrapper
68
68
  test_files: []