rcurl 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 31515d750261d9f1ebfc801a3a9d6eba52662301b78058aa2dde63e90bbace39
4
+ data.tar.gz: 693a008d32594b0a4ac878af44234a7ebd7185b2c4536b51feb804e0c23a3273
5
+ SHA512:
6
+ metadata.gz: 948d5b10a37f549335ca236b0b04a659d6e3f73a6be2d0fd3f9a0da60b75218cb8d7f9e7f2db62145fab40fc8c62df0a719e72ffe8ca031dfab1507119e0d712
7
+ data.tar.gz: fcce2e9efdf33b7499dc3b34f2bc4f08dc696942bfb74014b6d9ac1e251592df0cbd7db12449a5e7ebc1eaf27a8d5ede9a94d7041f3cc5b67ac4c543a15b94a0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor
10
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rurl.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Rcurl
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/rcurl`. 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 'rcurl'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rcurl
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. 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/kimromi/rcurl.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rcurl"
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
data/exe/rcurl ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rcurl'
3
+
4
+ Rcurl::CLI.start
data/lib/rcurl/cli.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'thor'
2
+
3
+ module Rcurl
4
+ class CLI < Thor
5
+ default_command :execute
6
+
7
+ option :path, type: :string, aliases: '-d'
8
+
9
+ desc 'execute -d @path [url] [args]', 'execute curl'
10
+ def execute(*args)
11
+ invoke :help and return unless options[:path]
12
+
13
+ if url = args.find{|arg| arg.match(/^https?:\/\//) }
14
+ args.delete(url)
15
+ end
16
+
17
+ config = Configure.new(args: args, url: url, path: options[:path])
18
+ Curl.execute(config)
19
+ rescue RcurlError => e
20
+ $stderr.puts e.message
21
+ exit 1
22
+ end
23
+
24
+ map %w(--version -v) => :version
25
+ desc "--version, -v", "see version"
26
+ def version
27
+ puts Rcurl::VERSION
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,59 @@
1
+ require 'yaml'
2
+ require 'erb'
3
+ require 'active_support/core_ext/hash/keys'
4
+
5
+ module Rcurl
6
+ class Configure
7
+ def initialize(args:, url:, path:)
8
+ @args = args
9
+ @url = url
10
+ @path = path
11
+ end
12
+
13
+ def args
14
+ @args
15
+ end
16
+
17
+ def method
18
+ yaml[:method].upcase
19
+ end
20
+
21
+ def headers
22
+ Array(yaml[:headers])
23
+ end
24
+
25
+ def params
26
+ yaml[:params]
27
+ end
28
+
29
+ def url
30
+ @url || yaml[:url]
31
+ end
32
+
33
+ private
34
+
35
+ def file
36
+ @path.gsub(/^@/, '')
37
+ end
38
+
39
+ def yaml
40
+ raise ConfigFileNotFound, "Config not found. #{@file}" unless File.exist?(file)
41
+ @yaml = YAML.load(read).symbolize_keys
42
+ rescue Psych::SyntaxError
43
+ raise InvalidConfig, 'invalid config file'
44
+ end
45
+
46
+ def read
47
+ str = File.open(file).read
48
+
49
+ case File.extname(file)
50
+ when '.erb'
51
+ ERB.new(str, nil, '%-').result
52
+ when '.yaml', '.yml'
53
+ str
54
+ else
55
+ raise ConfigNotSupportExtention, 'suport extention .yaml or .yml or .erb'
56
+ end
57
+ end
58
+ end
59
+ end
data/lib/rcurl/curl.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Rcurl
4
+ class Curl
5
+ class << self
6
+ METHODS = {
7
+ GET: 'Rcurl::Method::Get'
8
+ }
9
+
10
+ def execute(config)
11
+ validate(config)
12
+ m = METHODS[config.method.to_sym].constantize.new(config)
13
+
14
+ cmds = [
15
+ 'curl -sS',
16
+ m.args,
17
+ m.method,
18
+ m.headers,
19
+ m.params,
20
+ m.url,
21
+ ]
22
+ puts `#{cmds.compact.join(' ')}`
23
+ end
24
+
25
+ def validate(config)
26
+ unless METHODS.include?(config.method.to_sym)
27
+ raise NotSupportedMethod, "not supported method: #{config.method}"
28
+ end
29
+
30
+ unless config.url
31
+ raise NotGivenUrl, "please input url"
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ module Rcurl
2
+ class RcurlError < StandardError; end
3
+
4
+ class ConfigFileNotFound < RcurlError; end
5
+ class ConfigNotSupportExtention < RcurlError; end
6
+ class InvalidConfig < RcurlError; end
7
+
8
+ class NotSupportedMethod < RcurlError; end
9
+ class NotGivenUrl < RcurlError; end
10
+ end
@@ -0,0 +1,31 @@
1
+ module Rcurl
2
+ module Method
3
+ class Base
4
+ attr_reader :config
5
+
6
+ def initialize(config)
7
+ @config = config
8
+ end
9
+
10
+ def args
11
+ config.args.join(' ')
12
+ end
13
+
14
+ def headers
15
+ config.headers.map{|h| "-H '#{h}'"}.join(' ')
16
+ end
17
+
18
+ def method
19
+ "-X #{config.method.upcase}"
20
+ end
21
+
22
+ def url
23
+ "'#{config.url}'"
24
+ end
25
+
26
+ def params
27
+ raise NotImplementError
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ require 'uri'
2
+ require 'active_support/core_ext/object/to_param'
3
+
4
+ module Rcurl
5
+ module Method
6
+ class Get < Base
7
+ def method
8
+ nil
9
+ end
10
+
11
+ def url
12
+ uri = URI(config.url)
13
+ uri.query = config.params.to_param
14
+ "'#{uri}'"
15
+ end
16
+
17
+ def params
18
+ nil
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Rcurl
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rcurl.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "rcurl/version"
2
+ require "rcurl/cli"
3
+ require "rcurl/curl"
4
+ require "rcurl/configure"
5
+ require "rcurl/error"
6
+
7
+ require "rcurl/method/Base"
8
+ require "rcurl/method/Get"
9
+
10
+ module Rcurl
11
+ end
data/rcurl.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rcurl/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rcurl"
8
+ spec.version = Rcurl::VERSION
9
+ spec.authors = ["kimromi"]
10
+ spec.email = ["kimromi4@gmail.com"]
11
+
12
+ spec.summary = %q{curl tool by ruby}
13
+ spec.description = %q{curl tool by ruby}
14
+ spec.homepage = "https://github.com/kimromi/rcurl"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ 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_dependency "thor"
24
+ spec.add_dependency "activesupport"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcurl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kimromi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-26 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: curl tool by ruby
70
+ email:
71
+ - kimromi4@gmail.com
72
+ executables:
73
+ - rcurl
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - exe/rcurl
84
+ - lib/rcurl.rb
85
+ - lib/rcurl/cli.rb
86
+ - lib/rcurl/configure.rb
87
+ - lib/rcurl/curl.rb
88
+ - lib/rcurl/error.rb
89
+ - lib/rcurl/method/base.rb
90
+ - lib/rcurl/method/get.rb
91
+ - lib/rcurl/version.rb
92
+ - rcurl.gemspec
93
+ homepage: https://github.com/kimromi/rcurl
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.7.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: curl tool by ruby
116
+ test_files: []