iki-http 1.0.0 → 1.0.1

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: 299e7bff09aee36d46f395c0bba7558ddb3c654c95d60a5f96af467dc1d9787c
4
- data.tar.gz: 54ce0f6e044e2bb5920432e9092c686e87fedee2fe550a94f4b692063083e9ce
3
+ metadata.gz: eb4be45751f68d8e730b81fee36859de8dcc319e952ddf885783502de57f88f1
4
+ data.tar.gz: 7aa6b44ebd2cc746924d04fef36d7db2f3bf720f3da209b1d9fb76b9b52268f6
5
5
  SHA512:
6
- metadata.gz: a98e774e4a735a6b335d4cbc20b5b7de129a9c8a88937866b28f380f6a6d48efd16774fcf693be0db08590d5c2324f811ba8704cc99f8dbc84e6299331f8e0f4
7
- data.tar.gz: bf46a25d917a585765b86128d56ef51613a883b2be5489316a2f8373570722a6f71eb283a06d2f654e1c65d283e88293acc2d52dfa0f8194a10c67905996bb69
6
+ metadata.gz: cc649518678c575cf755b9bc1d5cd52e3ae93ef7a10afdb9e0c08440cd9629f7d277de8b88da63c73d043c85ead6d30edd5c75a0ee4a38c26421f807741ebc9e
7
+ data.tar.gz: bbbd58079392bd91f87fa07e23aec5d38444efac76baa92ce8a60790f31a76da18a2111fcd10e48aef8ca0c8e9f7bea6c2747811d806d4b2a2b7e426ac327b35
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-02-10
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "tsutae" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["daniel.vinciguerra@bivee.com.br"](mailto:"daniel.vinciguerra@bivee.com.br").
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Iki Http
2
+
3
+ Iki is a Ruby gem that provides a simple and efficient way to make HTTP requests. It is designed to be easy to use
4
+ and flexible, allowing you to customize your requests as needed.
5
+
6
+ Its a lightweight implementation of the HTTPie tool, which is a command-line HTTP client that allows you to make
7
+ HTTP requests and view the responses in a human-friendly format.
8
+
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ gem install iki-http
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ Some examples of how to use Iki:
19
+
20
+ - `iki GET https://jsonplaceholder.typicode.com/posts/1` - Makes a GET request to the specified URL and prints the response.
21
+ - `iki POST https://jsonplaceholder.typicode.com/posts title="foo" body="bar" userId=1` - Makes a POST request to the specified URL with the given data and prints the response.
22
+ - `iki GET https://jsonplaceholder.typicode.com/posts/1 Authorization:"Bearer <token>"` - Makes a GET request to the specified URL with the given header and prints the response.
23
+
24
+ ## Development
25
+
26
+ 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.
27
+
28
+ 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).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dvinciguerra/iki. 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/dvinciguerra/iki/blob/main/CODE_OF_CONDUCT.md).
33
+
34
+ ## Code of Conduct
35
+
36
+ Everyone interacting in the Tsutae project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dvinciguerra/tsutae/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/exe/iki ADDED
@@ -0,0 +1,145 @@
1
+ #!env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
5
+
6
+ require "base64"
7
+ require "erb"
8
+ require "json"
9
+ require "net/http"
10
+ require "optparse"
11
+ require "tty-markdown"
12
+ require "uri"
13
+
14
+ require "iki-http"
15
+
16
+ # globals
17
+ METHODS = %w[GET POST PUT DELETE PATCH HEAD OPTIONS].freeze
18
+
19
+ # parsing arguments
20
+ @options = { print: "HB", auth: nil, auth_type: "basic", verbose: false, raw: false }
21
+
22
+ parser = OptionParser.new do |opts|
23
+ opts.banner = %(
24
+ iki - A simple HTTP client for testing APIs from the command line.
25
+
26
+ Usage:
27
+ iki [METHOD] <url> [HEADER:VALUE] [key=value]
28
+
29
+ Examples:
30
+ iki https://api.example.com/users
31
+ iki POST https://api.example.com/users name=John age=30
32
+ iki GET :8080/api/items Authorization:"Bearer $TOKEN"
33
+ iki -A basic -a user:pass https://api.example.com/secure-data
34
+ iki --raw --print B POST https://httpbin.org/anything | jq '.headers["User-Agent"]'
35
+
36
+ Options:
37
+ )
38
+
39
+ opts.on("-p", "--print FORMAT", "Specify the output format (e.g., 'H' for headers, 'B' for body)") do |format|
40
+ @options[:print] = format.upcase || "HB" # default to printing both headers and body
41
+ warn "[Argument Error] Unsupported format: #{format}" unless format.match?(/\A[HB]+\z/i)
42
+ end
43
+
44
+ opts.on("-a", "--auth USER:PASS", "Specify basic authentication credentials") do |auth|
45
+ @options[:auth] = auth
46
+ end
47
+
48
+ opts.on("-A", "--auth-type TYPE", "Specify authentication type (e.g., basic, digest, bearer)") do |auth_type|
49
+ @options[:auth_type] = auth_type
50
+ end
51
+
52
+ opts.on("--raw", "Print raw request and response data") do
53
+ @options[:raw] = true
54
+ end
55
+
56
+ opts.on("-h", "--help", "Print this help message") do
57
+ puts opts
58
+ exit
59
+ end
60
+
61
+ opts.on("-v", "--verbose", "Print detailed request and response information") do
62
+ @options[:verbose] = true
63
+ end
64
+
65
+ opts.on("--version", "Print the version of iki") do
66
+ puts "iki-http v#{Iki::Http::VERSION}"
67
+ exit
68
+ end
69
+ end
70
+
71
+ parser.parse!(ARGV)
72
+
73
+ # resolve the HTTP method
74
+ method = METHODS.include?(ARGV[0]) ? ARGV.shift : "GET"
75
+
76
+ # resolve the URL
77
+ url = case ARGV[0]
78
+ when %r{\Ahttps?://}
79
+ ARGV.shift
80
+ when /\A:\d+/
81
+ "http://localhost#{ARGV.shift}"
82
+ else
83
+ "http://#{ARGV.shift}"
84
+ end
85
+
86
+ data =
87
+ ARGV.select { |arg| arg.include?("=") }.map.to_h { |arg| arg.split("=", 2).map(&:strip) }
88
+
89
+ headers =
90
+ { "Content-Type" => "application/json", "User-Agent" => "iki-http/#{Iki::Http::VERSION}" }
91
+ .merge(ARGV.select { |arg| arg.include?(":") }.map.to_h { |arg| arg.split(":", 2).map(&:strip) })
92
+
93
+ # prepare authentication header if auth is provided
94
+ if @options[:auth]
95
+ auth_type = @options[:auth_type] || "basic"
96
+ case auth_type.downcase
97
+ when "basic"
98
+ headers["Authorization"] = "Basic #{Base64.strict_encode64(@options[:auth])}"
99
+ when "bearer"
100
+ headers["Authorization"] = "Bearer #{@options[:auth]}"
101
+ else
102
+ warn "Unsupported authentication type: #{auth_type}"
103
+ end
104
+ end
105
+
106
+ pp [method, url, data, headers, @options, ARGV] if ENV["IKI_DEBUG"]
107
+
108
+ Net::HTTP.start(URI(url).host, URI(url).port, use_ssl: URI(url).scheme == "https") do |http|
109
+ options = @options
110
+ request_class = Net::HTTP.const_get(method.capitalize)
111
+ request = request_class.new(URI(url))
112
+
113
+ headers.each { |key, value| request[key] = value }
114
+ request["Content-Type"] ||= "application/json"
115
+
116
+ request.body = data.to_json unless data.empty?
117
+
118
+ response = http.request(request)
119
+
120
+ body = nil
121
+ if response["Content-Type"]&.include?("application/json") && response.body
122
+ begin
123
+ body ||= JSON.pretty_generate(JSON.parse(response.body))
124
+ rescue StandardError
125
+ body ||= response.body
126
+ end
127
+ else
128
+ body ||= response.body
129
+ end
130
+
131
+ if options[:raw]
132
+ if options[:print].include?("H")
133
+ puts "HTTP/#{response.http_version} #{response.code} #{response.message}"
134
+ response.each_header { |key, value| puts "#{key}: #{value}" }
135
+ puts
136
+ end
137
+
138
+ puts body if options[:print].include?("B") && body
139
+
140
+ break
141
+ end
142
+
143
+ view = Iki::Http.view(:output)
144
+ puts TTY::Markdown.parse(ERB.new(view).result(binding), color: :always)
145
+ end
data/lib/iki-http.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./iki"
data/lib/iki.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Iki
4
+ module Http
5
+ class Error < StandardError; end
6
+
7
+ VERSION = "1.0.1"
8
+
9
+ def self.view(name)
10
+ File.read(File.join(__dir__, "views", "#{name}.md.erb"))
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iki-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-02-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: tty-markdown
@@ -27,10 +27,18 @@ description: iki is a simple HTTP client for testing APIs from the command line
27
27
  with Ruby
28
28
  email:
29
29
  - daniel.vinciguerra@bivee.com.br
30
- executables: []
30
+ executables:
31
+ - iki
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
- files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - README.md
38
+ - Rakefile
39
+ - exe/iki
40
+ - lib/iki-http.rb
41
+ - lib/iki.rb
34
42
  homepage: https://github.com/dvinciguerra/iki-http
35
43
  licenses: []
36
44
  metadata:
@@ -51,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
59
  - !ruby/object:Gem::Version
52
60
  version: '0'
53
61
  requirements: []
54
- rubygems_version: 3.6.2
62
+ rubygems_version: 4.0.4
55
63
  specification_version: 4
56
64
  summary: iki is a simple HTTP client for testing APIs from the command line built
57
65
  with Ruby