magento_remote 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/magento_remote/magento_mech.rb +19 -8
- data/lib/magento_remote/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5236fc7f2136ea5ec063adc2ba9eb2cd7e444560
|
4
|
+
data.tar.gz: b4cf90268f8054076f04e1133ed5dca4fd2dd61f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb0e436342195eb663d819eed4951e55a8473c3553805d17b8561b9e1b644fc68f4e7994f6897fb1e789c72b247e9c284a4e6ec1cf4d0a791eebbeb5ab1739e
|
7
|
+
data.tar.gz: 6938ad84956935e0b54325bdd9133dc0dbf98ac2c008cdcd713fd98066f3f450cf3062051433f4f22c3b0b4b0cba5c1be9bedece394d7c323f29c0cd74ef036c
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
require 'logger'
|
3
3
|
require 'json'
|
4
|
+
require 'uri'
|
4
5
|
|
5
6
|
# The Mech Driver, interacting with a Magento shop page.
|
6
7
|
# Note that the Mech does not keep too much state, you have to
|
@@ -53,8 +54,9 @@ class MagentoMech
|
|
53
54
|
fail "Empty obligatory parameter"
|
54
55
|
end
|
55
56
|
|
56
|
-
url =
|
57
|
-
|
57
|
+
url = URI.join @base_uri, "checkout/cart/add/uenc/#{form_token}/"\
|
58
|
+
"product/#{product_id}/?isajaxcart=true&groupmessage=1&minicart=1&ajaxlinks=1"
|
59
|
+
result_page = @mech.post url,
|
58
60
|
{product: product_id,
|
59
61
|
qty: qty}
|
60
62
|
|
@@ -73,7 +75,7 @@ class MagentoMech
|
|
73
75
|
if !form_token.nil?
|
74
76
|
return ajax_add_to_cart(product_id, qty, form_token)
|
75
77
|
end
|
76
|
-
url =
|
78
|
+
url = URI.join @base_uri, "checkout/cart/add?product=#{product_id}&qty=#{qty}"
|
77
79
|
|
78
80
|
# Check the returned page name
|
79
81
|
result_page = @mech.get url
|
@@ -81,6 +83,8 @@ class MagentoMech
|
|
81
83
|
# There are multiple reasons of failure:
|
82
84
|
# * product_id unknown
|
83
85
|
# * product out of stock
|
86
|
+
# * product does not exist (unhandled response (Mechanize::ResponseCodeError)
|
87
|
+
# )
|
84
88
|
|
85
89
|
# There are multiple ways to detect failure:
|
86
90
|
# * contains a form with post action ending on product/#{product_id}/
|
@@ -115,16 +119,22 @@ class MagentoMech
|
|
115
119
|
qty = qty.to_i - 1
|
116
120
|
end
|
117
121
|
end
|
118
|
-
while qty.to_i > 0 && !add_to_cart(product_id, qty)
|
122
|
+
while qty.to_i > 0 && !add_to_cart(product_id, qty, form_token)
|
119
123
|
qty = qty.to_i - 1
|
120
124
|
end
|
121
125
|
qty.to_i + num_ordered
|
122
126
|
end
|
123
127
|
|
128
|
+
# Login and get the current carts contents
|
129
|
+
def get_cart_content!
|
130
|
+
login
|
131
|
+
get_cart_content
|
132
|
+
end
|
133
|
+
|
124
134
|
# Get the current carts contents
|
125
135
|
# Returns [[name, qty], [name2, qty2] ... ]
|
126
136
|
def get_cart_content
|
127
|
-
cart_page = @mech.get(
|
137
|
+
cart_page = @mech.get(URI.join @base_uri, "checkout/cart/")
|
128
138
|
name_links = cart_page.search('td h2 a')
|
129
139
|
names = name_links.map &:text
|
130
140
|
quantities_inputs = cart_page.search('.qty')
|
@@ -134,11 +144,11 @@ class MagentoMech
|
|
134
144
|
|
135
145
|
# Login with given credentials
|
136
146
|
def login_with username, password
|
137
|
-
login_page = @mech.get(
|
147
|
+
login_page = @mech.get(URI.join @base_uri, "customer/account/login/")
|
138
148
|
|
139
149
|
# Probably we could just send the POST directly.
|
140
|
-
form = login_page.form_with(:action => "#
|
141
|
-
form.action =
|
150
|
+
form = login_page.form_with(:action => "#", :method => 'POST')
|
151
|
+
form.action = URI.join @base_uri, "customer/account/loginPost/"
|
142
152
|
form.fields.find{|f| f.name == 'login[username]'}.value = username
|
143
153
|
form.fields.find{|f| f.name == 'login[password]'}.value = password
|
144
154
|
@mech.submit(form)
|
@@ -270,6 +280,7 @@ class MagentoMech
|
|
270
280
|
# Example:
|
271
281
|
# base uri is http://zentimental.net
|
272
282
|
# relative_url 'index.html' # => http://zentimental.net/index.html
|
283
|
+
# # TODO use more, and use URI.join
|
273
284
|
def relative_url path
|
274
285
|
if @base_uri.end_with?('/') && !path.start_with?('/')
|
275
286
|
@base_uri + '/' + path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magento_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felix Wolfsteller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.5.1
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: Login to a magento shop and do stuff.
|