ortega 0.0.6

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f56eb0e7e3b21f9980007be2393a63bac1db3e29aa12ebeda31c1a38910603a6
4
+ data.tar.gz: 3bc66aeefd7227f2b999afe23ff71f2c18b149a0d9912e49a5399b942fda23b7
5
+ SHA512:
6
+ metadata.gz: 8fbe9c71f5b1f280eb0063c849222605536f43fd91cea4f213a8d7d91c0e0081b2671bd0e9635cd781ddd4be1d21b52f54fb408a8dee3231092ccfc8ff43643a
7
+ data.tar.gz: c5dbca6d91b708b6805051d38052c56f382880c253b947f482ee0aef4a9a99181ffbbacee11f6b3b91b2ae43d23c3d052293e32f61004b366a0bc644e48d4529
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
+ Gemfile.lock
13
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Farhad
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,39 @@
1
+ # Ortega
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/ortega`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ortega'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ortega
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ortega.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ortega'
5
+ require 'pry'
6
+
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
File without changes
@@ -0,0 +1,40 @@
1
+ module Ortega
2
+ class File
3
+ attr_reader :name, :destination
4
+
5
+ def initialize(args = {})
6
+ @name = args[:name]
7
+ @destination = args[:path]
8
+ @extension = args[:extension]
9
+ end
10
+
11
+ def write(response)
12
+ ::File.open(@destination, 'wb') do |io|
13
+ content_length = response.header['Content-Length']
14
+ chunk_size = 0
15
+ puts "Downloading #{@name}"
16
+ response.read_body do |chunk|
17
+ io.write chunk
18
+ chunk_size += chunk.size
19
+ percent = ((chunk_size * 100) / content_length.to_i)
20
+ $stdout.print "#{'#' * percent} #{percent.to_s.rjust(103 - percent, ' ')} %\r"
21
+ $stdout.flush
22
+ end
23
+ end
24
+ end
25
+
26
+ def self.get_path(options)
27
+ options = options.with_indifferent_access
28
+ file = new(options)
29
+
30
+ file.instance_eval do
31
+ @name = @name.split('/').last
32
+ @destination = ::File.join(
33
+ "#{file.destination ? ::File.expand_path(file.destination) : '.'}",
34
+ file.name)
35
+ end
36
+
37
+ return file
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,31 @@
1
+ require 'net/http'
2
+ require 'ortega/file'
3
+ require 'active_support/core_ext/hash/indifferent_access'
4
+
5
+ module Ortega
6
+ module HTTP
7
+ def download(url, options = {}, &block)
8
+ options = options.with_indifferent_access
9
+ url = HTTP.url_helper(url)
10
+ options[:name] = url.path if options[:name].nil?
11
+ file = Ortega::File.get_path(options)
12
+
13
+ http = Net::HTTP.new(url.host, url.port)
14
+ http.use_ssl = true if url.scheme == 'https'
15
+
16
+ http.start do |http|
17
+ http.request Net::HTTP::Get.new url do |response|
18
+ file.write(response)
19
+ end
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def url_helper(url)
25
+ url.insert(0, 'http://') unless url.match(/http/)
26
+ return URI url
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,3 @@
1
+ module Ortega
2
+ VERSION = "0.0.6"
3
+ end
data/lib/ortega.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'ortega/http'
2
+
3
+ module Ortega
4
+ extend Ortega::HTTP
5
+ end
data/ortega.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ortega/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ortega"
7
+ spec.version = Ortega::VERSION
8
+ spec.authors = ["Farhad"]
9
+ spec.email = ["farhad9801@gmail.com"]
10
+
11
+ spec.summary = %q{Ruby file downloader}
12
+ spec.homepage = "https://github.com/0x2C6/ortega_ruby"
13
+ spec.license = "MIT"
14
+
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency 'pry', '~> 0.12.2'
24
+ spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+
28
+ spec.add_dependency 'activesupport', '~> 5.2', '>= 5.2.2'
29
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ortega
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Farhad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
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.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.2'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 5.2.2
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '5.2'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 5.2.2
89
+ description:
90
+ email:
91
+ - farhad9801@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".rspec"
98
+ - ".travis.yml"
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/ortega.rb
106
+ - lib/ortega/errors.rb
107
+ - lib/ortega/file.rb
108
+ - lib/ortega/http.rb
109
+ - lib/ortega/version.rb
110
+ - ortega.gemspec
111
+ homepage: https://github.com/0x2C6/ortega_ruby
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 3.0.0.beta3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Ruby file downloader
135
+ test_files: []