rcurl 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31515d750261d9f1ebfc801a3a9d6eba52662301b78058aa2dde63e90bbace39
4
- data.tar.gz: 693a008d32594b0a4ac878af44234a7ebd7185b2c4536b51feb804e0c23a3273
3
+ metadata.gz: 63c14c614a9dd88c35d801d2a718169ca2937baa97c86f04f419b8e010902014
4
+ data.tar.gz: 4e96a32288b16a8aac8e725ae1fbd2b1c1f287a7235ce3d7e5adf5607632b379
5
5
  SHA512:
6
- metadata.gz: 948d5b10a37f549335ca236b0b04a659d6e3f73a6be2d0fd3f9a0da60b75218cb8d7f9e7f2db62145fab40fc8c62df0a719e72ffe8ca031dfab1507119e0d712
7
- data.tar.gz: fcce2e9efdf33b7499dc3b34f2bc4f08dc696942bfb74014b6d9ac1e251592df0cbd7db12449a5e7ebc1eaf27a8d5ede9a94d7041f3cc5b67ac4c543a15b94a0
6
+ metadata.gz: 0fa945aed7446a567e5a0dc6d3ea55ed81423faf01f4bad7accb393eb17335ced8d5b6e49280ce8d09be55dd84646d26a46559d928e390389e49ea49214edd3f
7
+ data.tar.gz: cd022efeaebb0ac6a10f569c0935200854d6443a64469324491d0370b50d380ef7c2fa42fb79ab3a3488d1cd973874da9d31a03db07c4ea62b847ae181c26b9d
data/README.md CHANGED
@@ -1,34 +1,64 @@
1
1
  # Rcurl
2
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
3
+ Simple curl command wrapper
6
4
 
7
5
  ## Installation
8
6
 
9
- Add this line to your application's Gemfile:
7
+ $ gem install rcurl
8
+
9
+ ## Usage
10
+
11
+ ### GET
10
12
 
11
- ```ruby
12
- gem 'rcurl'
13
+ Create example.yaml
14
+
15
+ ```yaml
16
+ method: GET
17
+ params:
18
+ hoge: fuga
13
19
  ```
14
20
 
15
- And then execute:
21
+ execute `rcurl` command with option `-d`
16
22
 
17
- $ bundle
23
+ ```console
24
+ $ rcurl -d @path/to/example.yaml http://example.com
18
25
 
19
- Or install it yourself as:
26
+ # => curl -sS -X GET http://example.com?hoge=fuga
27
+ ```
20
28
 
21
- $ gem install rcurl
29
+ ### POST (application/x-www-form-urlencoded)
22
30
 
23
- ## Usage
31
+ example.yaml
24
32
 
25
- TODO: Write usage instructions here
33
+ ```yaml
34
+ method: POST
35
+ params:
36
+ hoge: fuga
37
+ ```
38
+
39
+ ```console
40
+ $ rcurl -d @path/to/example.yaml http://example.com
41
+
42
+ # => curl -sS -X POST -d 'hoge=fuga' http://example.com
43
+ ```
26
44
 
27
- ## Development
45
+ ### POST (application/json)
28
46
 
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.
47
+ example.yaml
30
48
 
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).
49
+ ```yaml
50
+ method: POST
51
+ headers:
52
+ - 'Content-type: application/json'
53
+ params:
54
+ hoge: fuga
55
+ ```
56
+
57
+ ```console
58
+ $ rcurl -d @path/to/example.yaml http://example.com
59
+
60
+ # => curl -sS -X POST -H 'Content-type: application/json' -d '{"hoge":"fuga"}' http://example.com
61
+ ```
32
62
 
33
63
  ## Contributing
34
64
 
@@ -6,6 +6,7 @@ require "rcurl/error"
6
6
 
7
7
  require "rcurl/method/Base"
8
8
  require "rcurl/method/Get"
9
+ require "rcurl/method/Post"
9
10
 
10
11
  module Rcurl
11
12
  end
@@ -38,7 +38,7 @@ module Rcurl
38
38
 
39
39
  def yaml
40
40
  raise ConfigFileNotFound, "Config not found. #{@file}" unless File.exist?(file)
41
- @yaml = YAML.load(read).symbolize_keys
41
+ @yaml ||= YAML.load(read).symbolize_keys
42
42
  rescue Psych::SyntaxError
43
43
  raise InvalidConfig, 'invalid config file'
44
44
  end
@@ -4,7 +4,8 @@ module Rcurl
4
4
  class Curl
5
5
  class << self
6
6
  METHODS = {
7
- GET: 'Rcurl::Method::Get'
7
+ GET: 'Rcurl::Method::Get',
8
+ POST: 'Rcurl::Method::Post'
8
9
  }
9
10
 
10
11
  def execute(config)
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ module Rcurl
4
+ module Method
5
+ class Post < Base
6
+ def method
7
+ '-X POST'
8
+ end
9
+
10
+ def url
11
+ config.url
12
+ end
13
+
14
+ def params
15
+ if json?
16
+ "-d '#{config.params.to_json}'"
17
+ else
18
+ config.params.map{|k, v| "-d '#{k}=#{v}'"}.join(' ')
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def json?
25
+ config.headers.any? do |header|
26
+ header.downcase =~ /content-type: application\/json/
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Rcurl
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimromi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-26 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -88,6 +88,7 @@ files:
88
88
  - lib/rcurl/error.rb
89
89
  - lib/rcurl/method/base.rb
90
90
  - lib/rcurl/method/get.rb
91
+ - lib/rcurl/method/post.rb
91
92
  - lib/rcurl/version.rb
92
93
  - rcurl.gemspec
93
94
  homepage: https://github.com/kimromi/rcurl