Class: Auchandirect::ScrAPI::Cart

Inherits:
BaseCart
  • Object
show all
Defined in:
lib/auchandirect/scrAPI/cart.rb

Overview

Cart API for AuchanDirect store

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCart

#url

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(, password)
  @agent = new_agent
  (, 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_parameterObject

Client side ‘login’ parameter name



63
64
65
# File 'lib/auchandirect/scrAPI/cart.rb', line 63

def self.
  
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.(, password)
  default_params = post_parameters.map {|name, value| {'name' => name, 'value' => value, 'type' => 'hidden'}}
  user_params = [{'name' => FORMDATA_PARAMETER, 'value' => (new_agent), 'type' => 'hidden'},
                 {'name' => , 'value' => , 'type' => 'text'},
                 {'name' => PASSWORD_PARAMETER, 'value' => password, 'type' => 'password'}]

  default_params + user_params
end

.login_urlObject

Url at which a client browser can login



49
50
51
# File 'lib/auchandirect/scrAPI/cart.rb', line 49

def self.
  URL + 
end

.logout_urlObject

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_agentObject



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_parameterObject

Client side ‘password’ parameter name



67
68
69
# File 'lib/auchandirect/scrAPI/cart.rb', line 67

def self.password_parameter
  PASSWORD_PARAMETER
end

.urlObject

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_valueObject

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_cartObject

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

#logoutObject

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

Returns:

  • (Boolean)


109
110
111
# File 'lib/auchandirect/scrAPI/cart.rb', line 109

def respond_to?(method_sym)
  super or delegate_to_class?(method_sym)
end