Class: Auchandirect::ScrAPI::Cart
- Defined in:
- lib/auchandirect/scrAPI/cart.rb
Overview
Cart API for AuchanDirect store
Class Method Summary collapse
-
.login_parameter ⇒ Object
Client side ‘login’ parameter name.
-
.login_parameters(login, password) ⇒ Object
Parameters for a client side login.
-
.login_url ⇒ Object
Url at which a client browser can login.
-
.logout_url ⇒ Object
Url at which a client browser can logout.
- .new_agent ⇒ Object
-
.password_parameter ⇒ Object
Client side ‘password’ parameter name.
-
.url ⇒ Object
Main url of the store.
Instance Method Summary collapse
-
#add_to_cart(quantity, item_remote_id) ⇒ Object
Adds items to the cart of the current user.
-
#cart_value ⇒ Object
Total value of the remote cart.
-
#empty_the_cart ⇒ Object
Empties the cart of the current user.
-
#initialize(login, password) ⇒ Cart
constructor
Logins to auchan direct store.
-
#logout ⇒ Object
Logs out from the store.
-
#method_missing(method_sym, *arguments, &block) ⇒ Object
Missing methods can be forwarded to the class.
-
#respond_to?(method_sym) ⇒ Boolean
It can respond to messages that the class can handle.
Methods inherited from BaseCart
Constructor Details
#initialize(login, password) ⇒ Cart
Logins to auchan direct store
36 37 38 39 40 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 36 def initialize(login, password) @agent = new_agent do_login(login, password) raise InvalidAccountError unless logged_in? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
Missing methods can be forwarded to the class
100 101 102 103 104 105 106 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 100 def method_missing(method_sym, *arguments, &block) if delegate_to_class?(method_sym) self.class.send(method_sym, *arguments, &block) else super end end |
Class Method Details
.login_parameter ⇒ Object
Client side ‘login’ parameter name
63 64 65 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 63 def self.login_parameter LOGIN_PARAMETER end |
.login_parameters(login, password) ⇒ Object
Parameters for a client side login
53 54 55 56 57 58 59 60 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 53 def self.login_parameters(login, password) default_params = post_parameters.map {|name, value| {'name' => name, 'value' => value, 'type' => 'hidden'}} user_params = [{'name' => FORMDATA_PARAMETER, 'value' => login_form_data(new_agent), 'type' => 'hidden'}, {'name' => LOGIN_PARAMETER, 'value' => login, 'type' => 'text'}, {'name' => PASSWORD_PARAMETER, 'value' => password, 'type' => 'password'}] default_params + user_params end |
.login_url ⇒ Object
Url at which a client browser can login
49 50 51 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 49 def self.login_url URL + login_path end |
.logout_url ⇒ Object
Url at which a client browser can logout
72 73 74 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 72 def self.logout_url URL + logout_path end |
.new_agent ⇒ Object
42 43 44 45 46 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 42 def self.new_agent Mechanize.new do |it| Agent.configure(it) end end |
.password_parameter ⇒ Object
Client side ‘password’ parameter name
67 68 69 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 67 def self.password_parameter PASSWORD_PARAMETER end |
.url ⇒ Object
Main url of the store
31 32 33 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 31 def self.url HOMEPAGE end |
Instance Method Details
#add_to_cart(quantity, item_remote_id) ⇒ Object
Adds items to the cart of the current user
93 94 95 96 97 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 93 def add_to_cart(quantity, item_remote_id) quantity.times do post("/boutiques.mozaique.thumbnailproduct.addproducttobasket/#{item_remote_id}") end end |
#cart_value ⇒ Object
Total value of the remote cart
82 83 84 85 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 82 def cart_value cart_page = get("/monpanier") cart_page.search("span.prix-total").first.content.gsub(/€$/,"").to_f end |
#empty_the_cart ⇒ Object
Empties the cart of the current user
88 89 90 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 88 def empty_the_cart post("/boutiques.blockzones.popuphandler.cleanbasketpopup.cleanbasket") end |
#logout ⇒ Object
Logs out from the store
77 78 79 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 77 def logout get(self.class.logout_path) end |
#respond_to?(method_sym) ⇒ Boolean
It can respond to messages that the class can handle
109 110 111 |
# File 'lib/auchandirect/scrAPI/cart.rb', line 109 def respond_to?(method_sym) super or delegate_to_class?(method_sym) end |