mercadolibre_api 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 10992099c067297a6ba5d2a9bcec468cadcfb3209e4802ef37762c76f2e40fae
4
+ data.tar.gz: efa9f8c6ec53ded8c110d0c853987c90b0757ece3ca9f8dc651c2e63446cbe21
5
+ SHA512:
6
+ metadata.gz: ee8cf859bc86c6d76ba85c4a5a19bdc72cfdc8bbef461c5d3ecc5b3158dfd2e789470170205d11a6466e6f4b722bb4f3b9dc2651b6daab022b1f562fb9d2baa0
7
+ data.tar.gz: 40b6e4796879146a0397b18fd43fd818c2909b22bfd3b2f8e95e0cfb35c93226fb26b0494c302eaf842a76235f8e8e782fef89d62fafb0586aa3de817f7527c7
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea/
13
+ *.swp
14
+ .DS_Store
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
3
+
4
+ Lint/AmbiguousBlockAssociation:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Style/Documentation:
11
+ Enabled: false
12
+
13
+ Style/MixinUsage:
14
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ mercadolibre_api
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.5
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mercadolibre_api (0.1.0)
5
+ active_interaction (~> 3.6)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ active_interaction (3.6.2)
11
+ activemodel (>= 4, < 6)
12
+ activemodel (5.2.1)
13
+ activesupport (= 5.2.1)
14
+ activesupport (5.2.1)
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ i18n (>= 0.7, < 2)
17
+ minitest (~> 5.1)
18
+ tzinfo (~> 1.1)
19
+ addressable (2.5.2)
20
+ public_suffix (>= 2.0.2, < 4.0)
21
+ ast (2.4.0)
22
+ concurrent-ruby (1.0.5)
23
+ crack (0.4.3)
24
+ safe_yaml (~> 1.0.0)
25
+ diff-lcs (1.3)
26
+ hashdiff (0.3.7)
27
+ i18n (1.1.0)
28
+ concurrent-ruby (~> 1.0)
29
+ jaro_winkler (1.5.1)
30
+ minitest (5.11.3)
31
+ parallel (1.12.1)
32
+ parser (2.5.1.2)
33
+ ast (~> 2.4.0)
34
+ powerpack (0.1.2)
35
+ public_suffix (3.0.3)
36
+ rainbow (3.0.0)
37
+ rake (12.3.1)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.0)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.1)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.0)
51
+ rubocop (0.59.2)
52
+ jaro_winkler (~> 1.5.1)
53
+ parallel (~> 1.10)
54
+ parser (>= 2.5, != 2.5.1.1)
55
+ powerpack (~> 0.1)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (~> 1.0, >= 1.0.1)
59
+ ruby-progressbar (1.10.0)
60
+ safe_yaml (1.0.4)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.5)
63
+ thread_safe (~> 0.1)
64
+ unicode-display_width (1.4.0)
65
+ vcr (4.0.0)
66
+ webmock (3.4.2)
67
+ addressable (>= 2.3.6)
68
+ crack (>= 0.3.2)
69
+ hashdiff
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.16)
76
+ mercadolibre_api!
77
+ rake (~> 12.3)
78
+ rspec (~> 3.8)
79
+ rubocop (~> 0.59)
80
+ vcr (~> 4.0)
81
+ webmock (~> 3.4)
82
+
83
+ BUNDLED WITH
84
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Pablo Gonzaga
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # MercadolibreApi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mercadolibre_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mercadolibre_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mercadolibre_api
20
+
21
+ ## Usage
22
+
23
+ ### Products by seller
24
+
25
+ #### Most sold
26
+ ```
27
+ MercadolibreApi::Sellers::Products::Queries::MostSold.run!(seller_id: 95592600, site_code: 'MLU')
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mercadolibre_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the MercadolibreApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mercadolibre_api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'mercadolibre_api'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,45 @@
1
+ require 'active_interaction'
2
+ require 'net/http'
3
+
4
+ module MercadolibreApi
5
+ module Sellers
6
+ module Products
7
+ module Queries
8
+ class MostSold < ActiveInteraction::Base
9
+ integer :seller_id
10
+ string :site_code
11
+
12
+ def execute
13
+ results = search_uris.map do |uri|
14
+ response = Net::HTTP.get_response(uri)
15
+ JSON.parse(response.body, symbolize_names: true)[:results]
16
+ end
17
+
18
+ results.flatten!
19
+ end
20
+
21
+ private
22
+
23
+ def search_uris
24
+ response = Net::HTTP.get_response(base_uri)
25
+ response_data = JSON.parse(response.body, symbolize_names: true)
26
+
27
+ total_products = response_data.dig(:paging, :total)
28
+ product_limit = response_data.dig(:paging, :limit)
29
+ total_calls = (total_products / product_limit).to_i
30
+
31
+ 0.upto(total_calls).map { |offset_ratio| base_uri(offset: (product_limit * offset_ratio)) }
32
+ end
33
+
34
+ def base_uri(offset: 0)
35
+ if offset.positive?
36
+ URI("https://api.mercadolibre.com/sites/#{site_code}/search?seller_id=#{seller_id}&offset=#{offset}")
37
+ else
38
+ URI("https://api.mercadolibre.com/sites/#{site_code}/search?seller_id=#{seller_id}")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module MercadolibreApi
2
+ VERSION = '0.1'.freeze
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'mercadolibre_api/version'
2
+
3
+ module MercadolibreApi
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mercadolibre_api/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'mercadolibre_api'
7
+ gem.version = MercadolibreApi::VERSION
8
+ gem.authors = ['Pablo Gonzaga']
9
+ gem.email = ['pgonzaga.uy@gmail.com']
10
+
11
+ gem.summary = 'Mercadolibre API client'
12
+ gem.description = 'Client to consume all Mercadolibre endpoints'
13
+ gem.homepage = 'https://github.com/pgonzaga/mercadolibre_api_gem'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+
20
+ gem.bindir = 'exe'
21
+ gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ gem.require_paths = ['lib']
23
+
24
+ gem.add_dependency 'active_interaction', '~> 3.6'
25
+
26
+ gem.add_development_dependency 'bundler', '~> 1.16'
27
+ gem.add_development_dependency 'rake', '~> 12.3'
28
+ gem.add_development_dependency 'rspec', '~> 3.8'
29
+ gem.add_development_dependency 'rubocop', '~> 0.59'
30
+ gem.add_development_dependency 'vcr', '~> 4.0'
31
+ gem.add_development_dependency 'webmock', '~> 3.4'
32
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mercadolibre_api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Pablo Gonzaga
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_interaction
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '12.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.59'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.59'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ description: Client to consume all Mercadolibre endpoints
112
+ email:
113
+ - pgonzaga.uy@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".ruby-gemset"
122
+ - ".ruby-version"
123
+ - ".travis.yml"
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.md
128
+ - Rakefile
129
+ - bin/console
130
+ - bin/setup
131
+ - lib/mercadolibre_api.rb
132
+ - lib/mercadolibre_api/sellers/products/queries/most_sold.rb
133
+ - lib/mercadolibre_api/version.rb
134
+ - mercadolibre_api.gemspec
135
+ homepage: https://github.com/pgonzaga/mercadolibre_api_gem
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.7.6
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Mercadolibre API client
159
+ test_files: []