mercadolibre_rails 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/mercadolibre_rails/product.rb +4 -4
- data/app/models/mercadolibre_rails/seller.rb +17 -1
- data/app/models/mercadolibre_rails/site.rb +1 -0
- data/db/migrate/20181004143133_create_mercadolibre_rails_sellers.rb +1 -1
- data/db/migrate/20181022135655_add_site_id_to_mercadolibre_rails_sellers.rb +6 -0
- data/lib/mercadolibre_rails/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df8b324f21f677cc5b8f45c6a37d4511523f076e99f816ac2dc5f2b98e3f6a0c
|
4
|
+
data.tar.gz: e717205170575157ecaee610d9f85cd6a82bab9003ddeb7b19cce045f3415c17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8e100fa61d958425a3caf1e9e327469a412f10020df038f4a413ebc118118e25dd04773236e8310f39b8b8be8f4bd1dec750d6c1c2ca4e5662078af6b17f792
|
7
|
+
data.tar.gz: a8ece76dfaa42f9c6eca0db7ab4991dc77804416e568c01d9ef2e0009a4603345a12edf513dceabe552e3d51ee05c8c1b593fe2acbf501b57217b86c148923e7
|
@@ -22,14 +22,14 @@ module MercadolibreRails
|
|
22
22
|
|
23
23
|
return unless ml_id && site_code
|
24
24
|
|
25
|
-
mercadolibre_site = MercadolibreRails::Site.
|
26
|
-
mercadolibre_site.products.
|
25
|
+
mercadolibre_site = MercadolibreRails::Site.where(code: site_code).first_or_create
|
26
|
+
mercadolibre_site.products.where(mercadolibre_id: ml_id).first_or_create
|
27
27
|
end
|
28
28
|
|
29
29
|
# rubocop:disable Metrics/AbcSize
|
30
30
|
def update_metadata
|
31
31
|
ml_product = MercadolibreApi::Products::Queries::Find.run!(product_id: mercadolibre_id)
|
32
|
-
ml_seller = MercadolibreRails::Seller.
|
32
|
+
ml_seller = MercadolibreRails::Seller.where(mercadolibre_id: ml_product[:seller_id], site: site).first_or_create
|
33
33
|
|
34
34
|
update!(seller: ml_seller, title: ml_product[:title], price: ml_product[:price],
|
35
35
|
currency_code: ml_product[:currency_id], sold_quantity: ml_product[:sold_quantity],
|
@@ -37,7 +37,7 @@ module MercadolibreRails
|
|
37
37
|
latitude: ml_product.dig(:geolocation, :latitude), longitude: ml_product.dig(:geolocation, :longitude))
|
38
38
|
|
39
39
|
ml_product[:pictures].each do |picture|
|
40
|
-
MercadolibreRails::Picture.
|
40
|
+
MercadolibreRails::Picture.where(url: picture[:url], product_id: id).first_or_create
|
41
41
|
end
|
42
42
|
end
|
43
43
|
# rubocop:enable Metrics/AbcSize
|
@@ -3,12 +3,28 @@ require 'mercadolibre_api'
|
|
3
3
|
module MercadolibreRails
|
4
4
|
class Seller < ApplicationRecord
|
5
5
|
has_many :products, dependent: :destroy
|
6
|
+
belongs_to :site
|
7
|
+
|
8
|
+
delegate :code, to: :site, prefix: true
|
9
|
+
after_create_commit :create_products
|
6
10
|
|
7
11
|
def self.create_from(product_url:)
|
8
12
|
ml_product_id = MercadolibreApi::Products::Queries::GetID.run!(product_url: product_url)
|
9
13
|
ml_seller_id = MercadolibreApi::Sellers::Queries::GetID.run!(product_id: ml_product_id)
|
14
|
+
ml_site_code = MercadolibreApi::Sites::Queries::GetCode.run!(product_url: product_url)
|
15
|
+
|
16
|
+
ml_site = MercadolibreRails::Site.where(code: ml_site_code).first_or_create
|
17
|
+
where(mercadolibre_id: ml_seller_id, site: ml_site).first_or_create
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def create_products
|
23
|
+
ordered_products = MercadolibreApi::Sellers::Products::Queries::MostSold.run!(
|
24
|
+
seller_id: mercadolibre_id, site_code: site_code
|
25
|
+
)
|
10
26
|
|
11
|
-
|
27
|
+
ordered_products.each { |product| products.where(mercadolibre_id: product[:id]).first_or_create }
|
12
28
|
end
|
13
29
|
end
|
14
30
|
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class AddSiteIdToMercadolibreRailsSellers < ActiveRecord::Migration[5.2]
|
2
|
+
def change
|
3
|
+
add_reference :mercadolibre_rails_sellers, :site, foreign_key: true
|
4
|
+
add_index :mercadolibre_rails_sellers, %i[mercadolibre_id site_id], name: 'ml_id_site_id_on_sellers'
|
5
|
+
end
|
6
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercadolibre_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Gonzaga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-10-
|
11
|
+
date: 2018-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercadolibre_api
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.10'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: paper_trail
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- db/migrate/20181010142220_create_mercadolibre_rails_versions.rb
|
185
185
|
- db/migrate/20181010142221_add_object_changes_to_mercadolibre_rails_versions.rb
|
186
186
|
- db/migrate/20181012133312_create_mercadolibre_rails_pictures.rb
|
187
|
+
- db/migrate/20181022135655_add_site_id_to_mercadolibre_rails_sellers.rb
|
187
188
|
- lib/mercadolibre_rails.rb
|
188
189
|
- lib/mercadolibre_rails/engine.rb
|
189
190
|
- lib/mercadolibre_rails/version.rb
|