gig2 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ca181c7efb3d9ae4d414a6209def1429964464c6e85acee411ca4110550fde9f
4
+ data.tar.gz: 2c1b9e504e2d847cc4b1f187fef370436866c905ac0d4c8dc4a7399c10731f0d
5
+ SHA512:
6
+ metadata.gz: c9c59d0d1e8d5cb5ac3c4ff48f829769ff9f465661ae58ea754515ea549f06aaf196711b5afa5df37177ab6f1d5fc86f1136ad2dfa9fbfa86678d012cf5d6975
7
+ data.tar.gz: b2eef08190673b9de125cac8b8e2c94ff924d606010180aaf56d5d31a36d350e8d7b6f85228e59d817abe3f55ff6a64ecc135f87ad0a70e61c16d7e58b2a4b43
Binary file
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gig.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+
8
+ # Library for making http requests
9
+ gem "httparty"
10
+
11
+ group :development do
12
+ # Library for debugging using breakpoints
13
+ gem "pry-byebug"
14
+ end
15
+
16
+ # Installing gems for testing
17
+ group :test do
18
+ gem "rspec", "~> 3.0"
19
+ # Library needed to mock responses
20
+ gem "webmock"
21
+ end
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gig2 (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ crack (0.4.3)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.4.4)
16
+ hashdiff (1.0.1)
17
+ httparty (0.18.1)
18
+ mime-types (~> 3.0)
19
+ multi_xml (>= 0.5.2)
20
+ method_source (1.0.0)
21
+ mime-types (3.3.1)
22
+ mime-types-data (~> 3.2015)
23
+ mime-types-data (3.2020.1104)
24
+ multi_xml (0.6.0)
25
+ pry (0.13.1)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ pry-byebug (3.9.0)
29
+ byebug (~> 11.0)
30
+ pry (~> 0.13.0)
31
+ public_suffix (4.0.4)
32
+ rake (12.3.3)
33
+ rspec (3.10.0)
34
+ rspec-core (~> 3.10.0)
35
+ rspec-expectations (~> 3.10.0)
36
+ rspec-mocks (~> 3.10.0)
37
+ rspec-core (3.10.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-expectations (3.10.0)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-mocks (3.10.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.10.0)
45
+ rspec-support (3.10.0)
46
+ safe_yaml (1.0.5)
47
+ webmock (3.8.3)
48
+ addressable (>= 2.3.6)
49
+ crack (>= 0.3.2)
50
+ hashdiff (>= 0.4.0, < 2.0.0)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ gig2!
57
+ httparty
58
+ pry-byebug
59
+ rake (~> 12.0)
60
+ rspec (~> 3.0)
61
+ webmock
62
+
63
+ BUNDLED WITH
64
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ife Runsewe
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.
@@ -0,0 +1,44 @@
1
+ # Gig
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/gig`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ This gem focuses on github's search api for repositories and downloading repositories's owner images. More information can be found [here](https://docs.github.com/en/free-pro-team@latest/rest/reference/search#search-repositories).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gig'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gig
22
+
23
+ ## Usage
24
+
25
+ Once you've installed gig, you should be able to run the gem by executing the following command `bin/gig <argument> <argument>`. You can find out what qualifies as an argument in the [github documentation](https://docs.github.com/en/free-pro-team@latest/rest/reference/search#search-repositories).
26
+
27
+ Example of a command to run is `bin/gig topic:ruby topic:rails`.
28
+
29
+ If your response is a good one (status 200) then the program will retrieve each owner of the relative repositories returned and downloach each one's image. These images will be downloaded to
30
+ a directory at the root of this project. The directory's name represents the query you made e.g. from the example above the directory would be called `topic:ruby-topic:rails`.
31
+
32
+ The github API has a rate limit of no more than 10 requests per second. If this rate limit is hit then you should see a message that explains what has happened and how long till you can make a request. Please find out more [here](https://docs.github.com/en/free-pro-team@latest/rest/reference/search#rate-limit)
33
+
34
+ You should also see a message if any other status code apart from 200 is returned from the API. Please find out more about which status codes could be returned here [here](https://docs.github.com/en/free-pro-team@latest/rest/reference/search#search-repositories).
35
+
36
+ ## Development
37
+
38
+ 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.
39
+
40
+ 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).
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gig"
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/gig ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'gig'
5
+
6
+ gig = Gig::Gig.new(ARGV)
7
+ gig.run
@@ -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,28 @@
1
+ require_relative 'lib/gig/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "gig2"
5
+ spec.version = Gig::VERSION
6
+ spec.authors = ["Ife Runsewe"]
7
+ spec.email = ["iferunsewe@gmail.com"]
8
+
9
+ spec.summary = "This repo allows you to download repository owner's images given a search term"
10
+ spec.description = "This repo allows you to download repository owner's images given a search term"
11
+ spec.homepage = "http://www.ifesgig.co.uk"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/iferunsewe/gig"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,6 @@
1
+ require 'httparty'
2
+ require 'open-uri'
3
+ require 'gig/version'
4
+ require 'gig/gig'
5
+ require 'gig/repositories'
6
+ require 'gig/downloader'
@@ -0,0 +1,17 @@
1
+ # A Module to deal with downloading files/images given a path and a uri
2
+ module Gig
3
+ module Downloader
4
+ def self.run(directory, filename, uri)
5
+ Dir.mkdir(directory) unless Dir.exist?(directory)
6
+
7
+ path = "#{Dir.pwd}/#{directory}/#{filename}.jpg"
8
+ return false if File.exist?(path)
9
+
10
+ URI.open(path, 'wb') do |file|
11
+ puts "Downloading #{filename}.jpg to #{Dir.pwd}/#{directory}"
12
+ file << URI.open(uri).read
13
+ end
14
+ true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Gig
2
+ class Gig
3
+ attr_reader :query, :directory, :repositories
4
+
5
+ def initialize(args)
6
+ raise ArgumentError.new('You must provide some arguments to build a search query') if args.count.zero?
7
+
8
+ @directory = args.join('-')
9
+ @query = args.join(' ')
10
+ @repositories = nil
11
+ end
12
+
13
+ def run
14
+ puts 'Running gig...'
15
+ @repositories = intialize_repositories
16
+ return false unless @repositories.search
17
+
18
+ @repositories.owners.each do |response|
19
+ Downloader.run(directory, response['login'], response['avatar_url'])
20
+ end
21
+ true
22
+ end
23
+
24
+ private
25
+
26
+ def intialize_repositories
27
+ Repositories.new(query)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,65 @@
1
+ module Gig
2
+ class Repositories
3
+ attr_reader :query, :owners, :response
4
+ API_PATH = '/search/repositories'.freeze
5
+
6
+ def initialize(query)
7
+ @query = query
8
+ @owners = []
9
+ @response = nil
10
+ end
11
+
12
+ def search
13
+ puts 'Searching for repositories....'
14
+ request_repositories
15
+ return handle_ok_response if response.code == 200
16
+ return !handle_hit_rate_limit if response.code == 403 && rate_limit_hit?
17
+
18
+ puts "Status: #{response.code}. Message: #{response.parsed_response['message']}"
19
+ false
20
+ end
21
+
22
+ private
23
+
24
+ def request_repositories
25
+ @response = HTTParty.get(
26
+ "https://api.github.com#{API_PATH}",
27
+ query: {
28
+ q: query
29
+ },
30
+ headers: headers
31
+ )
32
+ end
33
+
34
+ def headers
35
+ {
36
+ 'Accept' => 'application/vnd.github.v3+json'
37
+ }
38
+ end
39
+
40
+ def handle_ok_response
41
+ puts "Found #{response.parsed_response['total_count']} repositories"
42
+ return false if response.parsed_response['total_count'].zero?
43
+
44
+ @owners = response.parsed_response['items'].map { |item| item['owner'] }
45
+ true
46
+ end
47
+
48
+ def handle_hit_rate_limit
49
+ return false unless rate_limit_hit?
50
+
51
+ rate_limit_limit = response.headers['x-ratelimit-limit'][0]
52
+ rate_limit_reset = response.headers['x-ratelimit-reset'][0]
53
+ time_til_limit_reset = rate_limit_reset - Time.now.to_i
54
+ puts "You are attempting to make more than #{rate_limit_limit} requests in a minute. " \
55
+ "This is not allowed so please wait #{time_til_limit_reset} seconds before making the next request. " \
56
+ "Please find out more information here https://developer.github.com/v3/#rate-limiting"
57
+ true
58
+ end
59
+
60
+ def rate_limit_hit?
61
+ rate_limit_remaining = response.headers['x-ratelimit-remaining'][0]
62
+ rate_limit_remaining.to_i.zero?
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ module Gig
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gig2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ife Runsewe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This repo allows you to download repository owner's images given a search
14
+ term
15
+ email:
16
+ - iferunsewe@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".DS_Store"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/gig
31
+ - bin/setup
32
+ - gig.gemspec
33
+ - lib/gig.rb
34
+ - lib/gig/downloader.rb
35
+ - lib/gig/gig.rb
36
+ - lib/gig/repositories.rb
37
+ - lib/gig/version.rb
38
+ homepage: http://www.ifesgig.co.uk
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org
43
+ homepage_uri: http://www.ifesgig.co.uk
44
+ source_code_uri: https://github.com/iferunsewe/gig
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.1.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: This repo allows you to download repository owner's images given a search
64
+ term
65
+ test_files: []