discogs-wishlist 0.1.0

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: b96b2b304588ed2cfd70ae7eb08a74f61541acfb96032b3aabc5501526e49be1
4
+ data.tar.gz: 566a0fc5266ba269c3d045a646825281d403a91a98b19dcada4467fdc9abf5b5
5
+ SHA512:
6
+ metadata.gz: 375af0c0452862b194b2f8615e69a80d6582cbfc9d08fc777bd38c713bedda4dd7b7a4909e2538ce44a50de70f4575bf5371926a695af0b8e1f296d0f65d9999
7
+ data.tar.gz: ca1e96bf418a7f6ad8e7c2144ea2df9559f381df957a19b9433d9d1783338c96457a9470fc28765eebdfa322213cddd63d1c7f07d8ec61190fcd98bd5e9460ba
data/.envrc.example ADDED
@@ -0,0 +1,2 @@
1
+ export DISCOGS_APP_NAME=""
2
+ export DISCOGS_USER_TOKEN=""
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
+ .envrc
13
+ .tool-versions
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.0.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [v1.0.0] - 2021-06-13
9
+
10
+ ### Changed
11
+
12
+ - Created Initial Release
13
+
14
+ [v1.0.0]: https://github.com/envato/influx-router/releases/tag/v1.0.0
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at matt.patterson@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in discogs-wishlist.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,110 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ discogs-wishlist (0.1.0)
5
+ countries (~> 3.0.1)
6
+ discogs-wrapper (~> 2.5.1)
7
+ httparty (~> 0.18.1)
8
+ monetize (~> 1.10.0)
9
+ money (~> 6.14.0)
10
+ nokogiri (~> 1.11.1)
11
+ ruby-limiter (~> 1.1.0)
12
+ terminal-table (~> 2.0.0)
13
+ thor (~> 1.1.0)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ ast (2.4.2)
19
+ coderay (1.1.3)
20
+ concurrent-ruby (1.1.9)
21
+ countries (3.0.1)
22
+ i18n_data (~> 0.10.0)
23
+ sixarm_ruby_unaccent (~> 1.1)
24
+ unicode_utils (~> 1.4)
25
+ diff-lcs (1.4.4)
26
+ discogs-wrapper (2.5.1)
27
+ hashie (~> 3.0)
28
+ httparty (~> 0.14)
29
+ oauth (~> 0.5.1)
30
+ hashie (3.6.0)
31
+ httparty (0.18.1)
32
+ mime-types (~> 3.0)
33
+ multi_xml (>= 0.5.2)
34
+ i18n (1.8.10)
35
+ concurrent-ruby (~> 1.0)
36
+ i18n_data (0.10.0)
37
+ method_source (1.0.0)
38
+ mime-types (3.3.1)
39
+ mime-types-data (~> 3.2015)
40
+ mime-types-data (3.2021.0704)
41
+ monetize (1.10.0)
42
+ money (~> 6.12)
43
+ money (6.14.1)
44
+ i18n (>= 0.6.4, <= 2)
45
+ multi_xml (0.6.0)
46
+ nokogiri (1.11.7-x86_64-darwin)
47
+ racc (~> 1.4)
48
+ oauth (0.5.6)
49
+ parallel (1.20.1)
50
+ parser (3.0.2.0)
51
+ ast (~> 2.4.1)
52
+ pry (0.14.1)
53
+ coderay (~> 1.1)
54
+ method_source (~> 1.0)
55
+ racc (1.5.2)
56
+ rainbow (3.0.0)
57
+ rake (13.0.6)
58
+ regexp_parser (2.1.1)
59
+ rexml (3.2.5)
60
+ rspec (3.10.0)
61
+ rspec-core (~> 3.10.0)
62
+ rspec-expectations (~> 3.10.0)
63
+ rspec-mocks (~> 3.10.0)
64
+ rspec-core (3.10.1)
65
+ rspec-support (~> 3.10.0)
66
+ rspec-expectations (3.10.1)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.10.0)
69
+ rspec-mocks (3.10.2)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-support (3.10.2)
73
+ rubocop (1.18.3)
74
+ parallel (~> 1.10)
75
+ parser (>= 3.0.0.0)
76
+ rainbow (>= 2.2.2, < 4.0)
77
+ regexp_parser (>= 1.8, < 3.0)
78
+ rexml
79
+ rubocop-ast (>= 1.7.0, < 2.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 1.4.0, < 3.0)
82
+ rubocop-ast (1.7.0)
83
+ parser (>= 3.0.1.1)
84
+ rubocop-performance (1.11.4)
85
+ rubocop (>= 1.7.0, < 2.0)
86
+ rubocop-ast (>= 0.4.0)
87
+ ruby-limiter (1.1.0)
88
+ ruby-progressbar (1.11.0)
89
+ sixarm_ruby_unaccent (1.2.0)
90
+ standard (1.1.5)
91
+ rubocop (= 1.18.3)
92
+ rubocop-performance (= 1.11.4)
93
+ terminal-table (2.0.0)
94
+ unicode-display_width (~> 1.1, >= 1.1.1)
95
+ thor (1.1.0)
96
+ unicode-display_width (1.7.0)
97
+ unicode_utils (1.4.0)
98
+
99
+ PLATFORMS
100
+ x86_64-darwin-20
101
+
102
+ DEPENDENCIES
103
+ discogs-wishlist!
104
+ pry
105
+ rake (~> 13.0)
106
+ rspec (~> 3.0)
107
+ standard
108
+
109
+ BUNDLED WITH
110
+ 2.2.21
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Matt Patterson
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,37 @@
1
+ # Discogs::Wishlist
2
+
3
+ This tool is used to generate your Discogs Wishlist in your terminal. It also has options which will pull sale information for your wishlist items, and can be filtered to a country of your choice.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'discogs-wishlist'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Generate Wishlist
14
+
15
+ wishlist-for-sale --username mattpatterson
16
+
17
+ #### With Sale Information
18
+
19
+ wishlist-for-sale --username mattpatterson --for-sale --country-code AU
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/discogs-wishlist. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/discogs-wishlist/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Discogs::Wishlist project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/discogs-wishlist/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "discogs/wishlist"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/discogs/wishlist/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "discogs-wishlist"
7
+ spec.version = Discogs::Wishlist::VERSION
8
+ spec.authors = ["Matt Patterson"]
9
+ spec.email = ["hey@mattdoesdev.com"]
10
+
11
+ spec.summary = "A CLI tool to generate a discogs user wishlist"
12
+ spec.description = "This gem uses the discogs wrapper gem to fetch user wishlist information and then does some custom scraping to get items for sale in your selected country."
13
+ spec.homepage = "https://mattdoesdev.com"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/mattpatterson94/discogs-wishlist"
19
+ spec.metadata["changelog_uri"] = "https://github.com/mattpatterson94/discogs-wishlist"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "thor", "~> 1.1.0"
31
+ spec.add_dependency "countries", "~> 3.0.1"
32
+ spec.add_dependency "discogs-wrapper", "~> 2.5.1"
33
+ spec.add_dependency "httparty", "~> 0.18.1"
34
+ spec.add_dependency "monetize", "~> 1.10.0"
35
+ spec.add_dependency "money", "~> 6.14.0"
36
+ spec.add_dependency "nokogiri", "~> 1.11.1"
37
+ spec.add_dependency "ruby-limiter", "~> 1.1.0"
38
+ spec.add_dependency "terminal-table", "~> 2.0.0"
39
+
40
+ spec.add_development_dependency "pry"
41
+ spec.add_development_dependency "standard"
42
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "discogs/wishlist"
4
+
5
+ Discogs::Wishlist::CLI.start(ARGV)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "wishlist/version"
5
+ require_relative "wishlist/commands/wishlist"
6
+
7
+ module Discogs
8
+ module Wishlist
9
+ class Error < StandardError; end
10
+
11
+ class CLI < Thor
12
+ package_name "discogs-wishlist"
13
+
14
+ desc "print USERNAME", "Generate Wishlist Table"
15
+ method_option :for_sale, aliases: "-s", type: :boolean, default: false, desc: "Show For Sale Information"
16
+ method_option :country_code, aliases: "-c", default: "US", desc: "Country Code (to display sale items)"
17
+ def print(username)
18
+ Commands::Wishlist.new(
19
+ username: username,
20
+ for_sale: options[:for_sale],
21
+ country_code: options[:country_code]
22
+ ).perform
23
+ end
24
+
25
+ def self.exit_on_failure?
26
+ true
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,60 @@
1
+ require "countries"
2
+
3
+ require_relative "../populators/wishlist_populator"
4
+ require_relative "../populators/items_for_sale_populator"
5
+ require_relative "../models/wishlist"
6
+ require_relative "../printers/wishlist_printer"
7
+ require_relative "../mixins/output_suppressor"
8
+
9
+ module Commands
10
+ class Wishlist
11
+ include OutputSuppressor
12
+
13
+ def initialize(username:, for_sale:, country_code:)
14
+ @username = username
15
+ @for_sale = for_sale
16
+ @country_code = country_code
17
+ end
18
+
19
+ def perform
20
+ suppress_output do
21
+ populate_wishlist
22
+ populate_items_for_sale if show_for_sale?
23
+ end
24
+
25
+ print_wishlist
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :username, :for_sale, :country_code
31
+
32
+ def print_wishlist
33
+ WishlistPrinter.new(wishlist: wishlist, show_for_sale: show_for_sale?).print!
34
+ end
35
+
36
+ def populate_wishlist
37
+ WishlistPopulator.new(wishlist: wishlist).populate!
38
+ end
39
+
40
+ def populate_items_for_sale
41
+ ItemsForSalePopulator.new(wishlist: wishlist).populate!
42
+ end
43
+
44
+ def wishlist
45
+ @wishlist ||= ::Wishlist.new(username: username, country: country)
46
+ end
47
+
48
+ def show_for_sale?
49
+ for_sale && !!country
50
+ end
51
+
52
+ def country
53
+ @country || begin
54
+ return nil unless country_code
55
+
56
+ ISO3166::Country.new(country_code)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,31 @@
1
+ require "discogs"
2
+
3
+ class DiscogsApi
4
+ MAX_RESULTS_PER_PAGE = 100
5
+
6
+ def fetch_authenticated_user_identity
7
+ discogs_api.get_identity
8
+ end
9
+
10
+ def fetch_by_username(username)
11
+ discogs_api.get_user_wantlist(username, per_page: MAX_RESULTS_PER_PAGE).wants
12
+ end
13
+
14
+ def get_release_by_id(id, currency)
15
+ discogs_api.get_release(id, currency)
16
+ end
17
+
18
+ private
19
+
20
+ def discogs_api
21
+ @discogs_api ||= Discogs::Wrapper.new(discogs_app_name, user_token: discogs_user_token)
22
+ end
23
+
24
+ def discogs_app_name
25
+ ENV["DISCOGS_APP_NAME"] || "discogs-wishlist"
26
+ end
27
+
28
+ def discogs_user_token
29
+ ENV["DISCOGS_USER_TOKEN"]
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ require "discogs"
2
+
3
+ class DiscogsWeb
4
+ include HTTParty
5
+ base_uri "discogs.com"
6
+
7
+ def sell(release_id, currency)
8
+ self.class.get("/sell/release/#{release_id}?currency=#{currency}")
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module OutputSuppressor
2
+ def suppress_output
3
+ original_stdout = $stdout.clone
4
+ original_stderr = $stderr.clone
5
+ $stderr.reopen File.new("/dev/null", "w")
6
+ $stdout.reopen File.new("/dev/null", "w")
7
+ yield
8
+ ensure
9
+ $stdout.reopen original_stdout
10
+ $stderr.reopen original_stderr
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ThreadsPerSlice
2
+ def threads_per_slice(enumerator, number_of_slices)
3
+ mutex = Mutex.new
4
+ threads = []
5
+
6
+ enumerator.each_slice(number_of_slices) do |slice|
7
+ threads << Thread.new { yield slice, mutex }
8
+ end
9
+
10
+ threads.each(&:join)
11
+ end
12
+ end
@@ -0,0 +1,51 @@
1
+ class Album
2
+ attr_reader :id
3
+
4
+ def initialize(id)
5
+ @id = id
6
+ end
7
+
8
+ def add_variation(variation)
9
+ variations << variation
10
+ end
11
+
12
+ def title
13
+ @title ||= variations.first&.title
14
+ end
15
+
16
+ def artist
17
+ @artist ||= variations.first&.artist
18
+ end
19
+
20
+ def lowest_price
21
+ @lowest_price ||= begin
22
+ return nil unless items_for_sale_count.positive?
23
+
24
+ saleable_variations.map(&:lowest_price).min_by { |price| price[:price] }
25
+ end
26
+ end
27
+
28
+ def lowest_price_cost
29
+ return nil if lowest_price.nil?
30
+
31
+ @lowest_price_cost ||= lowest_price[:price].format
32
+ end
33
+
34
+ def lowest_price_shipping
35
+ return nil if lowest_price.nil?
36
+
37
+ @lowest_price_shipping ||= lowest_price[:shipping].format
38
+ end
39
+
40
+ def items_for_sale_count
41
+ @items_for_sale_count ||= saleable_variations.sum(&:items_for_sale_count)
42
+ end
43
+
44
+ def saleable_variations
45
+ @saleable_variations ||= variations.select(&:saleable?)
46
+ end
47
+
48
+ def variations
49
+ @variations ||= []
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ class AlbumVariation
2
+ def initialize(variation)
3
+ @variation = variation
4
+ end
5
+
6
+ def saleable?
7
+ return false unless @items_for_sale
8
+
9
+ @items_for_sale.length.positive?
10
+ end
11
+
12
+ def add_items_for_sale(for_sale_items)
13
+ new_items = items_for_sale.dup + for_sale_items.compact.sort_by { |info| info[:price] }
14
+
15
+ @items_for_sale = new_items
16
+ end
17
+
18
+ def id
19
+ variation.id
20
+ end
21
+
22
+ def url
23
+ variation.basic_information.resource_url
24
+ end
25
+
26
+ def master_id
27
+ variation.basic_information.master_id
28
+ end
29
+
30
+ def items_for_sale_count
31
+ @items_for_sale.length
32
+ end
33
+
34
+ def lowest_price
35
+ @lowest_price ||= @items_for_sale.first
36
+ end
37
+
38
+ def title
39
+ variation.basic_information.title
40
+ end
41
+
42
+ def artist
43
+ variation.basic_information.artists.map(&:name)&.join(", ")
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :variation
49
+
50
+ def items_for_sale
51
+ @items_for_sale ||= []
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ require_relative "album"
2
+ require_relative "album_variation"
3
+
4
+ class Wishlist
5
+ include Enumerable
6
+
7
+ attr_reader :username, :country
8
+
9
+ def initialize(username:, country:)
10
+ @username = username
11
+ @country = country
12
+ end
13
+
14
+ def add_to_wishlist(item)
15
+ variation = AlbumVariation.new(item)
16
+
17
+ album = get_album_from_variation(variation)
18
+
19
+ album.add_variation(variation)
20
+
21
+ wishlist.sort_by!(&:artist)
22
+ end
23
+
24
+ def each(&block)
25
+ wishlist.each(&block)
26
+ end
27
+
28
+ private
29
+
30
+ def wishlist
31
+ @wishlist ||= []
32
+ end
33
+
34
+ def get_album_from_variation(variation)
35
+ album = wishlist.find { |wishlist_album| wishlist_album.id == variation.master_id }
36
+
37
+ return create_new_album(variation) if album.nil?
38
+
39
+ album
40
+ end
41
+
42
+ def create_new_album(variation)
43
+ album = Album.new(variation.master_id)
44
+
45
+ wishlist << album
46
+
47
+ album
48
+ end
49
+ end
@@ -0,0 +1,37 @@
1
+ require "nokogiri"
2
+ require "monetize"
3
+
4
+ class ItemPriceParser
5
+ def initialize(html, country)
6
+ @html = html
7
+ @country = country
8
+ end
9
+
10
+ def parse
11
+ return [] unless rows.length.positive?
12
+
13
+ rows.map do |row|
14
+ price = row.search(".item_price .price").text.gsub(/[^\d.]+/, "")
15
+ shipping = row.search(".item_shipping").first.text.gsub(/[^\d.]+/, "")
16
+
17
+ return nil if price.nil? || shipping.nil?
18
+
19
+ {
20
+ price: Monetize.parse(price, country.currency.iso_code),
21
+ shipping: Monetize.parse(shipping, country.currency.iso_code)
22
+ }
23
+ end.compact
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :html, :country
29
+
30
+ def rows
31
+ @rows ||= parsed_html.search(".mpitems tbody tr")
32
+ end
33
+
34
+ def parsed_html
35
+ @parsed_html ||= Nokogiri::HTML(html.body)
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ require "limiter"
2
+ require "httparty"
3
+
4
+ require_relative "../parsers/item_price_parser"
5
+ require_relative "../data_fetchers/discogs_web"
6
+ require_relative "../mixins/threads_per_slice"
7
+
8
+ class ItemsForSalePopulator
9
+ include ThreadsPerSlice
10
+
11
+ def initialize(wishlist:)
12
+ @wishlist = wishlist
13
+
14
+ configure_money
15
+ end
16
+
17
+ def populate!
18
+ threads_per_slice(wishlist, 2) do |slice, mutex|
19
+ slice.each do |wishlist_album|
20
+ wishlist_album.variations.each do |variation|
21
+ mutex.synchronize do
22
+ variation.add_items_for_sale(find_items_for_sale(variation.id))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :wishlist
32
+
33
+ def find_items_for_sale(variation_id)
34
+ raw = discogs_web.sell(variation_id, wishlist.country&.currency&.iso_code)
35
+
36
+ ItemPriceParser.new(raw, wishlist.country).parse
37
+ end
38
+
39
+ def configure_money
40
+ ISO3166.configuration.enable_currency_extension!
41
+ Money.locale_backend = nil
42
+ Money.default_currency = nil
43
+ Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
44
+ end
45
+
46
+ def discogs_web
47
+ @discogs_web ||= DiscogsWeb.new
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ require_relative "../data_fetchers/discogs_api"
2
+
3
+ class WishlistPopulator
4
+ def initialize(wishlist:)
5
+ @wishlist = wishlist
6
+ end
7
+
8
+ def populate!
9
+ wantlist = discogs_api.fetch_by_username(wishlist.username)
10
+
11
+ wantlist.each do |wantlist_item|
12
+ wishlist.add_to_wishlist(wantlist_item)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :wishlist
19
+
20
+ def discogs_api
21
+ @discogs_api ||= DiscogsApi.new
22
+ end
23
+ end
@@ -0,0 +1,62 @@
1
+ require "terminal-table"
2
+
3
+ class WishlistPrinter
4
+ def initialize(wishlist:, show_for_sale:)
5
+ @wishlist = wishlist
6
+ @show_for_sale = show_for_sale
7
+ end
8
+
9
+ def print!
10
+ populate_table
11
+
12
+ puts table
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :wishlist, :show_for_sale
18
+
19
+ def populate_table
20
+ wishlist.each do |album|
21
+ table.add_row(album_columns(album))
22
+ end
23
+ end
24
+
25
+ def table
26
+ @table ||= Terminal::Table.new(title: title, headings: headings)
27
+ end
28
+
29
+ def title
30
+ "Wishlist"
31
+ end
32
+
33
+ def album_columns(album)
34
+ columns = [
35
+ album.title,
36
+ album.artist,
37
+ album.variations.length
38
+ ]
39
+
40
+ return columns unless show_for_sale
41
+
42
+ columns + [
43
+ album.items_for_sale_count,
44
+ album.lowest_price_cost,
45
+ album.lowest_price_shipping
46
+ ]
47
+ end
48
+
49
+ def headings
50
+ common_headings = ["Title", "Artist", "Variations"]
51
+
52
+ return common_headings unless show_for_sale
53
+
54
+ country_code = wishlist.country ? "(#{wishlist.country.alpha2})" : ""
55
+
56
+ common_headings + [
57
+ "For Sale #{country_code}",
58
+ "Lowest Price #{country_code}",
59
+ "Shipping #{country_code}"
60
+ ]
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Discogs
4
+ module Wishlist
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/screenshot.jpg ADDED
Binary file
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: discogs-wishlist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Patterson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: countries
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: discogs-wrapper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.5.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.5.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.18.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.18.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: monetize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.10.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.10.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: money
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 6.14.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 6.14.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.11.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.11.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: ruby-limiter
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.1.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: terminal-table
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.0.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: standard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: This gem uses the discogs wrapper gem to fetch user wishlist information
168
+ and then does some custom scraping to get items for sale in your selected country.
169
+ email:
170
+ - hey@mattdoesdev.com
171
+ executables:
172
+ - discogs-wishlist
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - ".envrc.example"
177
+ - ".gitignore"
178
+ - ".rspec"
179
+ - ".tool-versions"
180
+ - CHANGELOG.md
181
+ - CODE_OF_CONDUCT.md
182
+ - Gemfile
183
+ - Gemfile.lock
184
+ - LICENSE.txt
185
+ - README.md
186
+ - Rakefile
187
+ - bin/console
188
+ - bin/setup
189
+ - discogs-wishlist.gemspec
190
+ - exe/discogs-wishlist
191
+ - lib/discogs/wishlist.rb
192
+ - lib/discogs/wishlist/commands/wishlist.rb
193
+ - lib/discogs/wishlist/data_fetchers/discogs_api.rb
194
+ - lib/discogs/wishlist/data_fetchers/discogs_web.rb
195
+ - lib/discogs/wishlist/mixins/output_suppressor.rb
196
+ - lib/discogs/wishlist/mixins/threads_per_slice.rb
197
+ - lib/discogs/wishlist/models/album.rb
198
+ - lib/discogs/wishlist/models/album_variation.rb
199
+ - lib/discogs/wishlist/models/wishlist.rb
200
+ - lib/discogs/wishlist/parsers/item_price_parser.rb
201
+ - lib/discogs/wishlist/populators/items_for_sale_populator.rb
202
+ - lib/discogs/wishlist/populators/wishlist_populator.rb
203
+ - lib/discogs/wishlist/printers/wishlist_printer.rb
204
+ - lib/discogs/wishlist/version.rb
205
+ - screenshot.jpg
206
+ homepage: https://mattdoesdev.com
207
+ licenses:
208
+ - MIT
209
+ metadata:
210
+ homepage_uri: https://mattdoesdev.com
211
+ source_code_uri: https://github.com/mattpatterson94/discogs-wishlist
212
+ changelog_uri: https://github.com/mattpatterson94/discogs-wishlist
213
+ post_install_message:
214
+ rdoc_options: []
215
+ require_paths:
216
+ - lib
217
+ required_ruby_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: 2.3.0
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubygems_version: 3.2.3
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: A CLI tool to generate a discogs user wishlist
232
+ test_files: []