shc 0.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.
@@ -0,0 +1,55 @@
1
+ # Simple http(s) client
2
+
3
+ A simple HTTP(S) client in Ruby to query any RESTful API.
4
+
5
+ ---
6
+
7
+ Will be Implemented Request methods :
8
+
9
+ * GET
10
+ * POST
11
+ * PUT
12
+ * DELETE
13
+
14
+ Need to be implemented :
15
+
16
+ * HEAD
17
+ * TRACE
18
+ * OPTIONS
19
+ * CONNECT
20
+ * PATCH
21
+
22
+ ---
23
+
24
+ ### Request methods cheat-sheet
25
+
26
+ | HTTP Method | RFC | Request has Body | Response has body | Safe | Idempotent | Cacheable |
27
+ | ----------- | ------------------------------------------- | ---------------- | ----------------- | ---- | ---------- | --------- |
28
+ | GET | [7231](https://tools.ietf.org/html/rfc7231) | No | Yes | Yes | Yes | Yes |
29
+ | HEAD | [7231](https://tools.ietf.org/html/rfc7231) | No | No | Yes | Yes | Yes |
30
+ | POST | [7231](https://tools.ietf.org/html/rfc7231) | Yes | Yes | No | No | Yes |
31
+ | PUT | [7231](https://tools.ietf.org/html/rfc7231) | Yes | Yes | No | Yes | No |
32
+ | DELETE | [7231](https://tools.ietf.org/html/rfc7231) | No | Yes | No | Yes | No |
33
+ | PATCH | [5789](https://tools.ietf.org/html/rfc5789) | Yes | Yes | No | No | Yes |
34
+ | CONNECT | [7231](https://tools.ietf.org/html/rfc7231) | Yes | Yes | No | No | No |
35
+ | TRACE | [7231](https://tools.ietf.org/html/rfc7231) | No | Yes | Yes | Yes | No |
36
+ | OPTIONS | [7231](https://tools.ietf.org/html/rfc7231) | Optional | Yes | Yes | Yes | No |
37
+
38
+
39
+ ### Some "Request Methods" explanations
40
+
41
+ #### HEAD
42
+
43
+ > The HEAD method asks for a response identical to that of a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content
44
+
45
+ #### TRACE
46
+
47
+ > The TRACE method echoes the received request so that a client can see what (if any) changes or additions have been made by intermediate servers.
48
+
49
+ #### OPTIONS
50
+
51
+ > The OPTIONS method returns the HTTP methods that the server supports for the specified URL. This can be used to check the functionality of a web server by requesting '*' instead of a specific resource.
52
+
53
+ #### CONNECT
54
+
55
+ > The CONNECT method converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ ###
2
+ # SHC Namespace
3
+ #
4
+ module SHC
5
+ end
@@ -0,0 +1,26 @@
1
+ module SHC
2
+ ##
3
+ # Client class
4
+ #
5
+ class Client
6
+ attr_reader :host, :request_headers, :url
7
+
8
+ ##
9
+ # Create a new client
10
+ #
11
+ # @param host[String] base url of the API
12
+ # @param request_headers[Hash] the headers of the query
13
+ # @param url[Array<String>] the API url segments
14
+ # @param version[String] the API version
15
+ #
16
+ def initialize(host: nil, request_headers: nil, url: nil, version: nil)
17
+ @host = host
18
+ @request_headers = request_headers || {}
19
+ @url = url || []
20
+ @version = version
21
+ @methods = %w[delete get patch post put]
22
+ @query_params = nil
23
+ @request_body = nil
24
+ end
25
+ end
26
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ module SHC
2
+ class Error < StandardError; end
3
+
4
+ class ServerError < Error; end
5
+ class NotFound < Error; end
6
+ class BadRequest < Error; end
7
+ class Unauthorized < Error; end
8
+ end
File without changes
File without changes
@@ -0,0 +1,25 @@
1
+ require 'multi_json'
2
+
3
+ module SHC
4
+ ##
5
+ # Response class
6
+ #
7
+ class Response
8
+ attr_reader :headers, :status_code, :body
9
+
10
+ ##
11
+ # Create a new response
12
+ #
13
+ # @param response[Net::HTTPResponse] The response
14
+ #
15
+ def initialize(response)
16
+ @status_code = response.code
17
+ @headers = response.to_hash
18
+ @body = MultiJson.decode response.body
19
+ end
20
+
21
+ def error?
22
+ @body.has_key('error')
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module SHC
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "shc"
8
+ spec.version = SHC::VERSION
9
+ spec.authors = ["Stéphane FEUGA"]
10
+ spec.email = ["sfeuga@member.fsf.org"]
11
+ spec.summary = %q{Simple HTTP and HTTPS Client in Ruby}
12
+ spec.description = %q{A simple HTTP and HTTPS client in Ruby to query any RESTful API}
13
+ spec.homepage = "https://github.com/sfeuga/simple-http_s-client"
14
+ spec.required_ruby_version = '>= 2.3'
15
+ spec.license = "GPL-3.0-or-later"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'multi_json', '~> 1.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.17'
25
+ spec.add_development_dependency 'pry', '~> 0.12'
26
+ spec.add_development_dependency 'rake', '~> 12.3'
27
+ spec.add_development_dependency 'rubocop', '~> 0.68'
28
+ spec.add_development_dependency 'travis', '~> 1.8'
29
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stéphane FEUGA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.68'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.68'
83
+ - !ruby/object:Gem::Dependency
84
+ name: travis
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ description: A simple HTTP and HTTPS client in Ruby to query any RESTful API
98
+ email:
99
+ - sfeuga@member.fsf.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - CONTRIBUTING.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - lib/shc.rb
115
+ - lib/shc/client.rb
116
+ - lib/shc/connection.rb
117
+ - lib/shc/errors.rb
118
+ - lib/shc/headers.rb
119
+ - lib/shc/request.rb
120
+ - lib/shc/response.rb
121
+ - lib/shc/version.rb
122
+ - shc.gemspec
123
+ homepage: https://github.com/sfeuga/simple-http_s-client
124
+ licenses:
125
+ - GPL-3.0-or-later
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '2.3'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.0.4
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Simple HTTP and HTTPS Client in Ruby
146
+ test_files: []