auchandirect-scrAPI 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: da85baea18c9892825b603e963724cf03a268115
4
- data.tar.gz: 8eae477d988b9d184449cc4bc966a1c89fac60fa
3
+ metadata.gz: e6cfee413c33f6e047d2c013993cb22da0cee83b
4
+ data.tar.gz: 1755e97b5e057b3c5a50b5831d04961720ac2986
5
5
  SHA512:
6
- metadata.gz: 01513b5c508dab584d38d257199c0f9a69e75e1d5a2f01bfaab680e2ab755104e9efab18b93ab001b9df5eb9da390af104231c58257f0ee21303c10426f694b7
7
- data.tar.gz: bc8f3dd14c9b3f3205ba656d62f56b10a3d3c2be1e09064cc5888ceaf3f2a651fd8f38e5db7bcd5707389c6862359153ad14b561adba49f2254961f428ebba03
6
+ metadata.gz: 86e67a5fcf7563ca70d2ed50098a4a5817334a70556f6bcfa6d6036b8c6981373686af41d099e58e63c4a8471447a001b4f874dae663068605cbc50046df41ce
7
+ data.tar.gz: 697dc5f3bc4227669580c56376ba62f4dfa3c8164dbed4c288c3b03e300da7a42f8dc1aace79acc501f344293002a24dcfea84edb05b58b7e6ec9d039c788f7a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files`.split($/).reject {|f| f.match(/^offline_sites/)}
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.add_dependency 'storexplore', '~> 0.3'
19
+ spec.add_dependency 'storexplore', '~> 0.4'
20
20
 
21
21
  spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake"
@@ -22,6 +22,7 @@
22
22
  require 'storexplore'
23
23
  require 'auchandirect/scrAPI/version'
24
24
  require 'auchandirect/scrAPI/constants'
25
+ require 'auchandirect/scrAPI/agent'
25
26
  require 'auchandirect/scrAPI/items'
26
27
  require 'auchandirect/scrAPI/base_cart'
27
28
  require 'auchandirect/scrAPI/dummy_cart'
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # auchandirect/scrAPI/items.rb
4
+ #
5
+ # Copyright (c) 2010-2014 by Philippe Bourgau. All rights reserved.
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 3.0 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
+ # MA 02110-1301 USA
21
+
22
+ module Auchandirect
23
+ module ScrAPI
24
+
25
+ # Helper class for common code around mechanize agents
26
+ class Agent
27
+
28
+ # Initializes agent with the auchandirect cookie for both items
29
+ # and cart apis.
30
+ def self.configure(agent)
31
+ agent.cookie_jar << Mechanize::Cookie.new(domain: '.auchandirect.fr',
32
+ name: 'prehomemobile',
33
+ value: 'prehomemobile',
34
+ path: '/')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -34,11 +34,17 @@ module Auchandirect
34
34
 
35
35
  # Logins to auchan direct store
36
36
  def initialize(login, password)
37
- @agent = Mechanize.new
37
+ @agent = new_agent
38
38
  do_login(login, password)
39
39
  raise InvalidAccountError unless logged_in?
40
40
  end
41
41
 
42
+ def self.new_agent
43
+ Mechanize.new do |it|
44
+ Agent.configure(it)
45
+ end
46
+ end
47
+
42
48
  # Url at which a client browser can login
43
49
  def self.login_url
44
50
  URL + login_path
@@ -46,7 +52,7 @@ module Auchandirect
46
52
  # Parameters for a client side login
47
53
  def self.login_parameters(login, password)
48
54
  default_params = post_parameters.map {|name, value| {'name' => name, 'value' => value, 'type' => 'hidden'}}
49
- user_params = [{'name' => FORMDATA_PARAMETER, 'value' => login_form_data(Mechanize.new), 'type' => 'hidden'},
55
+ user_params = [{'name' => FORMDATA_PARAMETER, 'value' => login_form_data(new_agent), 'type' => 'hidden'},
50
56
  {'name' => LOGIN_PARAMETER, 'value' => login, 'type' => 'text'},
51
57
  {'name' => PASSWORD_PARAMETER, 'value' => password, 'type' => 'password'}]
52
58
 
@@ -123,7 +129,7 @@ module Auchandirect
123
129
  home_page = agent.get(Cart.url)
124
130
 
125
131
  with_retry(5) do
126
- login_form_json = post(agent, "/boutiques.paniervolant.customerinfos:showsigninpopup", {}, {'Referer' => home_page.uri})
132
+ login_form_json = post(agent, "/boutiques.paniervolant.customerinfos:showsigninpopup", {}, {'Referer' => home_page.uri.to_s})
127
133
 
128
134
  html_body = JSON.parse(login_form_json.body)["zones"]["popupZone"]
129
135
  doc = Nokogiri::HTML("<html><body>#{html_body}</body></html>")
@@ -51,6 +51,9 @@ module Auchandirect
51
51
  end
52
52
 
53
53
  Storexplore::Api.define DOMAIN do
54
+ agent do |it|
55
+ Agent.configure(it)
56
+ end
54
57
 
55
58
  categories '#footer-menu h2 a' do
56
59
  attributes do
@@ -21,7 +21,7 @@
21
21
 
22
22
  module Auchandirect
23
23
  module ScrAPI
24
- VERSION = "0.2.1"
24
+ VERSION = "0.2.2"
25
25
  end
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ shared_examples_for "Any Client Cart" do |store_cart_class, please_login_text|
29
29
  end
30
30
 
31
31
  it "logs in and out through HTTP" do
32
- @client = Mechanize.new
32
+ @client = @store_cart_class.new_agent
33
33
  expect(logged_in?).to (be false), "should not be logged in at the begining"
34
34
 
35
35
  login
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auchandirect-scrAPI
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philou
@@ -29,7 +29,7 @@ cert_chain:
29
29
  LKjGZUoe+A3/FKYHWLPZAArCXrXLhpjAfopLBNmOAju0e30ObcjPQDWcj7z5jfJl
30
30
  ILiFgo6hdHrp/tFaDv14PiMRm6sZaQ==
31
31
  -----END CERTIFICATE-----
32
- date: 2014-11-04 00:00:00.000000000 Z
32
+ date: 2014-11-05 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: storexplore
@@ -37,14 +37,14 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.3'
40
+ version: '0.4'
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.3'
47
+ version: '0.4'
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -160,6 +160,7 @@ files:
160
160
  - Rakefile
161
161
  - auchandirect-scrAPI.gemspec
162
162
  - lib/auchandirect/scrAPI.rb
163
+ - lib/auchandirect/scrAPI/agent.rb
163
164
  - lib/auchandirect/scrAPI/base_cart.rb
164
165
  - lib/auchandirect/scrAPI/cart.rb
165
166
  - lib/auchandirect/scrAPI/constants.rb
metadata.gz.sig CHANGED
Binary file