rockauto_api 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d861f195fe9c02dc5737f5756f0c3e7248ddad192a380913dd9e95a65d327b8
4
- data.tar.gz: 93ef1dddb194b74a1d091039460b3586466f1e225bba2289b0da43cfe5253e02
3
+ metadata.gz: 6a8f768a66a9b2d791cc6f0b27ccfadb6ef8aea842767648c669f7dd14ac396d
4
+ data.tar.gz: 29f26f81a94b6af11ab3e94ced337e51115134c09fe7deb3bcfc8b7d55e2a845
5
5
  SHA512:
6
- metadata.gz: d4606e5e6fe6ea4b7301722ddaba983dfab6de91c47ea8510054898b1d95f292b44c4adf2e98ce5bd44bca10d8dc2f7c86b539df7f888863b0b86e821f809d91
7
- data.tar.gz: 0d6ec3fdb8ba7f234e91dbfcbd31b504d44dc53b10ab3c1d3610e28a63dd3c4f983a79b077f3312c3922f1e3c824fb6c1688aeebf7e1c404c8716482e38ba7d0
6
+ metadata.gz: 5a3348b251faaca4fa20bb2051e33d2dbd3b3177431cb95aac4e9042bd407b15937c8acee0c92814da730df4e7de758fea6a90e41fceb4154ca73ca3006851a1
7
+ data.tar.gz: 6af1ab1af31c41419a5e823d1560c9100a5ff630eccb456999fbf1611f49d4b69b160986c580698885bddaa3e3d3c5a55c61fea240b4808ef78304d437d17981
@@ -26,20 +26,14 @@ module RockautoApi
26
26
  "Sec-Fetch-Dest" => "document"
27
27
  }.freeze
28
28
 
29
- INITIAL_COOKIES = {
30
- "idlist" => "0",
31
- "mkt_US" => "true",
32
- "mkt_CA" => "false",
33
- "mkt_MX" => "false",
34
- "year_2005" => "true",
35
- "ck" => "1"
36
- }.freeze
29
+ MARKET_COOKIES = %w[US CA MX].freeze
37
30
 
38
- attr_reader :cache, :authenticated
31
+ attr_reader :cache, :authenticated, :market
39
32
 
40
- def initialize(mobile: nil, cache: nil)
33
+ def initialize(mobile: nil, cache: nil, market: nil)
41
34
  mobile = RockautoApi.configuration&.default_mobile if mobile.nil?
42
35
  headers = mobile ? MOBILE_HEADERS : DESKTOP_HEADERS
36
+ @market = (market || RockautoApi.configuration&.market || :US).to_s.upcase.to_sym
43
37
 
44
38
  @conn = Faraday.new(url: BASE_URL) do |f|
45
39
  f.request :url_encoded
@@ -57,12 +51,22 @@ module RockautoApi
57
51
  @authenticated = false
58
52
  end
59
53
 
54
+ private
55
+
56
+ def initial_cookies
57
+ cookies = { "idlist" => "0", "year_2005" => "true", "ck" => "1" }
58
+ MARKET_COOKIES.each { |code| cookies["mkt_#{code}"] = (@market.to_s.upcase == code).to_s }
59
+ cookies
60
+ end
61
+
60
62
  def set_initial_cookies
61
- INITIAL_COOKIES.each do |name, value|
63
+ initial_cookies.each do |name, value|
62
64
  @conn.headers["Cookie"] = "#{@conn.headers['Cookie']}; #{name}=#{value}" unless @conn.headers["Cookie"].to_s.include?("#{name}=")
63
65
  end
64
66
  end
65
67
 
68
+ public
69
+
66
70
  def init_session!
67
71
  return if @session_initialized
68
72
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RockautoApi
4
4
  class Configuration
5
- attr_accessor :default_mobile, :cache, :request_timeout, :user_agent, :credentials
5
+ attr_accessor :default_mobile, :cache, :request_timeout, :user_agent, :credentials, :market
6
6
 
7
7
  def initialize
8
8
  @default_mobile = true
@@ -10,6 +10,7 @@ module RockautoApi
10
10
  @request_timeout = 30
11
11
  @user_agent = nil
12
12
  @credentials = nil
13
+ @market = :US
13
14
  end
14
15
 
15
16
  def email
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RockautoApi
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rockauto_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben D'Angelo