crapi 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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +81 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/crapi.gemspec +31 -0
- data/lib/crapi.rb +6 -0
- data/lib/crapi/client.rb +139 -0
- data/lib/crapi/errors.rb +10 -0
- data/lib/crapi/proxy.rb +42 -0
- data/lib/crapi/version.rb +3 -0
- metadata +162 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e07d4b09fda54c274d947572692e0ca65cffeea63cc0dddb7d007417e21db00f
|
|
4
|
+
data.tar.gz: f7ac47fd70689d196806c773e3c68de646a57582ae53532d0393da1591e12b53
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e60ac2a214b04c9ba04e873242f12524dea1c26e1e97f9583ae42c0090908cce490b457e41cc0ac6bacbf88956b195df9ca805102c03de0ff54d24e79625e0fa
|
|
7
|
+
data.tar.gz: 58c452c73c69a95ce88567a0fc7d794c9920c085051db8f18450b87e93e82a23a7783794dca576c82a14c406a662cb6191f05f7e150d058947534e8b7295caf5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.5
|
|
3
|
+
Include:
|
|
4
|
+
- "**/*.rake"
|
|
5
|
+
- "**/Gemfile"
|
|
6
|
+
- "**/Rakefile"
|
|
7
|
+
- "**/Capfile"
|
|
8
|
+
- "**/Berksfile"
|
|
9
|
+
- "**/Cheffile"
|
|
10
|
+
Exclude:
|
|
11
|
+
- "vendor/**/*"
|
|
12
|
+
- "db/**/*"
|
|
13
|
+
- "tmp/**/*"
|
|
14
|
+
- "true/**/*"
|
|
15
|
+
Metrics/ClassLength:
|
|
16
|
+
Description: Avoid classes longer than 100 lines of code.
|
|
17
|
+
Enabled: false
|
|
18
|
+
CountComments: false
|
|
19
|
+
Max: 100
|
|
20
|
+
Metrics/LineLength:
|
|
21
|
+
Description: Limit lines to 100 characters.
|
|
22
|
+
Enabled: false
|
|
23
|
+
Max: 100
|
|
24
|
+
Metrics/BlockLength:
|
|
25
|
+
Exclude:
|
|
26
|
+
- 'spec/**/*.rb'
|
|
27
|
+
Metrics/MethodLength:
|
|
28
|
+
Description: Avoid methods longer than 10 lines of code.
|
|
29
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
|
30
|
+
Enabled: false
|
|
31
|
+
CountComments: false
|
|
32
|
+
Max: 10
|
|
33
|
+
Metrics/AbcSize:
|
|
34
|
+
Description: A calculated magnitude based on number of assignments, branches, and conditions.
|
|
35
|
+
Enabled: false
|
|
36
|
+
Max: 15
|
|
37
|
+
Metrics/CyclomaticComplexity:
|
|
38
|
+
Description: A complexity metric that is strongly correlated to the number of test cases needed to validate a method.
|
|
39
|
+
Enabled: false
|
|
40
|
+
Max: 6
|
|
41
|
+
Lint/Debugger:
|
|
42
|
+
Description: Warn in debugger entries
|
|
43
|
+
Enabled: false
|
|
44
|
+
Style/SymbolArray:
|
|
45
|
+
Description: Use %i or %I for arrays of symbols.
|
|
46
|
+
Enabled: false
|
|
47
|
+
Style/RegexpLiteral:
|
|
48
|
+
Description: Enforces using / or %r around regular expressions.
|
|
49
|
+
EnforcedStyle: percent_r
|
|
50
|
+
Style/AsciiComments:
|
|
51
|
+
# Disabling this so we can use non-breaking spaces (' ') in documentation comments, preventing browsers from collapsing multiple spaces in code blocks.
|
|
52
|
+
Description: This cop checks for non-ascii (non-English) characters in comments.
|
|
53
|
+
Enabled: false
|
|
54
|
+
Style/NumericLiterals:
|
|
55
|
+
Description: This cop checks for big numeric literals without _ between groups of digits in them.
|
|
56
|
+
Enabled: false
|
|
57
|
+
Style/Documentation:
|
|
58
|
+
Description: Document classes and non-namespace modules.
|
|
59
|
+
Enabled: false
|
|
60
|
+
Style/ClassAndModuleChildren:
|
|
61
|
+
Description: Use nested modules/class definitions instead of compact style.
|
|
62
|
+
Enabled: false
|
|
63
|
+
Style/FrozenStringLiteralComment:
|
|
64
|
+
Enabled: false
|
|
65
|
+
Style/EmptyMethod:
|
|
66
|
+
Enabled: false
|
|
67
|
+
Style/StderrPuts:
|
|
68
|
+
Enabled: true
|
|
69
|
+
Exclude:
|
|
70
|
+
- 'bin/**/*'
|
|
71
|
+
Style/BlockDelimiters:
|
|
72
|
+
Description: Check for uses of braces or do/end around single line or multi-line blocks.
|
|
73
|
+
Enabled: true
|
|
74
|
+
Exclude:
|
|
75
|
+
- 'spec/**/*.rb'
|
|
76
|
+
Style/RescueModifier:
|
|
77
|
+
Description: This cop checks for uses of rescue in its modifier form.
|
|
78
|
+
Enabled: false
|
|
79
|
+
Naming/UncommunicativeMethodParamName:
|
|
80
|
+
Description: This cop checks method parameter names for how descriptive they are.
|
|
81
|
+
Enabled: false
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--output-dir=./docs --no-private --markup=markdown --format=html
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
crapi (0.1.0)
|
|
5
|
+
activesupport (~> 5.2)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
activesupport (5.2.0)
|
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
12
|
+
i18n (>= 0.7, < 2)
|
|
13
|
+
minitest (~> 5.1)
|
|
14
|
+
tzinfo (~> 1.1)
|
|
15
|
+
byebug (10.0.2)
|
|
16
|
+
coderay (1.1.2)
|
|
17
|
+
concurrent-ruby (1.0.5)
|
|
18
|
+
diff-lcs (1.3)
|
|
19
|
+
i18n (1.0.1)
|
|
20
|
+
concurrent-ruby (~> 1.0)
|
|
21
|
+
method_source (0.9.0)
|
|
22
|
+
minitest (5.11.3)
|
|
23
|
+
pry (0.11.3)
|
|
24
|
+
coderay (~> 1.1.0)
|
|
25
|
+
method_source (~> 0.9.0)
|
|
26
|
+
pry-byebug (3.6.0)
|
|
27
|
+
byebug (~> 10.0)
|
|
28
|
+
pry (~> 0.10)
|
|
29
|
+
rake (10.5.0)
|
|
30
|
+
rspec (3.7.0)
|
|
31
|
+
rspec-core (~> 3.7.0)
|
|
32
|
+
rspec-expectations (~> 3.7.0)
|
|
33
|
+
rspec-mocks (~> 3.7.0)
|
|
34
|
+
rspec-core (3.7.1)
|
|
35
|
+
rspec-support (~> 3.7.0)
|
|
36
|
+
rspec-expectations (3.7.0)
|
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
38
|
+
rspec-support (~> 3.7.0)
|
|
39
|
+
rspec-mocks (3.7.0)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.7.0)
|
|
42
|
+
rspec-support (3.7.1)
|
|
43
|
+
rspec_junit_formatter (0.3.0)
|
|
44
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
|
45
|
+
thread_safe (0.3.6)
|
|
46
|
+
tzinfo (1.2.5)
|
|
47
|
+
thread_safe (~> 0.1)
|
|
48
|
+
|
|
49
|
+
PLATFORMS
|
|
50
|
+
ruby
|
|
51
|
+
|
|
52
|
+
DEPENDENCIES
|
|
53
|
+
bundler (~> 1.16)
|
|
54
|
+
crapi!
|
|
55
|
+
pry (~> 0.11)
|
|
56
|
+
pry-byebug (~> 3.6)
|
|
57
|
+
rake (~> 10.0)
|
|
58
|
+
rspec (~> 3.0)
|
|
59
|
+
rspec_junit_formatter (~> 0.3)
|
|
60
|
+
|
|
61
|
+
BUNDLED WITH
|
|
62
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Nestor Custodio
|
|
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
|
+
# Crapi
|
|
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/crapi`. 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 'crapi'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install crapi
|
|
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]/crapi.
|
|
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
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'crapi'
|
|
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
data/crapi.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'crapi/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'crapi'
|
|
8
|
+
spec.version = Crapi::VERSION
|
|
9
|
+
spec.authors = ['Nestor Custodio']
|
|
10
|
+
spec.email = ['sakimorix@gmail.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'A simple API client with built-in segment/header proxy support. "... It could be better." ™️'
|
|
13
|
+
spec.homepage = 'https://www.github.com/nestor-custodio/crapi'
|
|
14
|
+
spec.license = 'MIT'
|
|
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_development_dependency 'bundler', '~> 1.16'
|
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.11'
|
|
25
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.6'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
28
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
|
|
29
|
+
|
|
30
|
+
spec.add_dependency 'activesupport', '~> 5.2'
|
|
31
|
+
end
|
data/lib/crapi.rb
ADDED
data/lib/crapi/client.rb
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'active_support/all'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
|
|
5
|
+
require 'crapi/proxy'
|
|
6
|
+
|
|
7
|
+
class Crapi::Client
|
|
8
|
+
attr_accessor :default_headers
|
|
9
|
+
|
|
10
|
+
JSON_CONTENT_TYPE = 'application/json'.freeze
|
|
11
|
+
FORM_CONTENT_TYPE = 'application/x-www-form-urlencoded'.freeze
|
|
12
|
+
|
|
13
|
+
def initialize(base_uri, opts = {})
|
|
14
|
+
@base_uri = case base_uri
|
|
15
|
+
when URI then base_uri
|
|
16
|
+
when String then URI(base_uri)
|
|
17
|
+
else raise Crapi::ArgumentError, %(Unexpected "base_url" type: #{base_url.class})
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@proxy_host = opts[:proxy_host]
|
|
21
|
+
@proxy_port = opts[:proxy_port]
|
|
22
|
+
@proxy_username = opts[:proxy_username]
|
|
23
|
+
@proxy_password = opts[:proxy_password]
|
|
24
|
+
|
|
25
|
+
@http = Net::HTTP.new(@base_uri.host, @base_uri.port,
|
|
26
|
+
@proxy_host, @proxy_port, @proxy_username, @proxy_password)
|
|
27
|
+
@http.use_ssl = (@base_uri.scheme == 'https')
|
|
28
|
+
@http.verify_mode = ::OpenSSL::SSL::VERIFY_NONE if opts[:insecure].present?
|
|
29
|
+
|
|
30
|
+
@default_headers = { 'Content-Type': JSON_CONTENT_TYPE }.with_indifferent_access
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def new_proxy(segment = '/', headers: nil)
|
|
34
|
+
Crapi::Proxy.new(add: segment, to: self, headers: headers)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
## CRUD methods ...
|
|
38
|
+
|
|
39
|
+
def delete(path, headers: {}, query: {})
|
|
40
|
+
headers = @default_headers.merge(headers)
|
|
41
|
+
|
|
42
|
+
response = @http.delete(full_path(path, query: query), headers)
|
|
43
|
+
ensure_success!(response)
|
|
44
|
+
parse_response(response)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get(path, headers: {}, query: {})
|
|
48
|
+
headers = @default_headers.merge(headers)
|
|
49
|
+
|
|
50
|
+
response = @http.get(full_path(path, query: query), headers)
|
|
51
|
+
ensure_success!(response)
|
|
52
|
+
parse_response(response)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def patch(path, headers: {}, query: {}, payload: {})
|
|
56
|
+
headers = @default_headers.merge(headers)
|
|
57
|
+
payload = format_payload(payload, as: headers[:'Content-Type'])
|
|
58
|
+
|
|
59
|
+
response = @http.patch(full_path(path, query: query), payload, headers)
|
|
60
|
+
ensure_success!(response)
|
|
61
|
+
parse_response(response)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def post(path, headers: {}, query: {}, payload: {})
|
|
65
|
+
headers = @default_headers.merge(headers)
|
|
66
|
+
payload = format_payload(payload, as: headers[:'Content-Type'])
|
|
67
|
+
|
|
68
|
+
response = @http.post(full_path(path, query: query), payload, headers)
|
|
69
|
+
ensure_success!(response)
|
|
70
|
+
parse_response(response)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def put(path, headers: {}, query: {}, payload: {})
|
|
74
|
+
headers = @default_headers.merge(headers)
|
|
75
|
+
payload = format_payload(payload, as: headers[:'Content-Type'])
|
|
76
|
+
|
|
77
|
+
response = @http.put(full_path(path, query: query), payload, headers)
|
|
78
|
+
ensure_success!(response)
|
|
79
|
+
parse_response(response)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
##
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
##
|
|
87
|
+
|
|
88
|
+
def full_path(path, query: {})
|
|
89
|
+
path = [@base_uri.path, path].map { |i| i.gsub(%r{^/|/$}, '') }.keep_if(&:present?)
|
|
90
|
+
path = "/#{path.join('/')}"
|
|
91
|
+
|
|
92
|
+
if query.present?
|
|
93
|
+
path += case query
|
|
94
|
+
when Hash, Array then "?#{URI.encode_www_form(query)}"
|
|
95
|
+
when String then "?#{query}"
|
|
96
|
+
else raise Crapi::ArgumentError, %(Unexpected "query" type: #{query.class})
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
path
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def ensure_success!(response)
|
|
104
|
+
return if response.is_a? Net::HTTPSuccess
|
|
105
|
+
raise(Crapi::BadHttpResponseError, "#{response.code} - #{response.message}")
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def format_payload(payload, as: JSON_CONTENT_TYPE)
|
|
109
|
+
## Non-Hash payloads are passed through as-is.
|
|
110
|
+
return payload unless payload.is_a? Hash
|
|
111
|
+
|
|
112
|
+
## Massage Hash-like payloads into a suitable format.
|
|
113
|
+
case as
|
|
114
|
+
when JSON_CONTENT_TYPE
|
|
115
|
+
JSON.generate(payload.as_json)
|
|
116
|
+
when FORM_CONTENT_TYPE
|
|
117
|
+
payload.to_query
|
|
118
|
+
else
|
|
119
|
+
payload.to_s
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def parse_response(response)
|
|
124
|
+
case response.content_type
|
|
125
|
+
when JSON_CONTENT_TYPE
|
|
126
|
+
JSON.parse(response.body, quirks_mode: true, symbolize_names: true)
|
|
127
|
+
else
|
|
128
|
+
response.body
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
## Net::HTTP needs a shortcut instance method for PUT calls like it does for GET/DELETE/PATCH/POST.
|
|
134
|
+
##
|
|
135
|
+
class Net::HTTP
|
|
136
|
+
def put(path, data, initheader = nil, dest = nil, &block)
|
|
137
|
+
send_entity(path, data, initheader, dest, Put, &block)
|
|
138
|
+
end
|
|
139
|
+
end
|
data/lib/crapi/errors.rb
ADDED
data/lib/crapi/proxy.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'active_support/all'
|
|
2
|
+
|
|
3
|
+
class Crapi::Proxy
|
|
4
|
+
attr_accessor :default_headers
|
|
5
|
+
|
|
6
|
+
def initialize(add:, to:, headers: nil)
|
|
7
|
+
@parent = to
|
|
8
|
+
@segment = add
|
|
9
|
+
@default_headers = (headers || {}).with_indifferent_access
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def new_proxy(segment = '/', headers: nil)
|
|
13
|
+
Crapi::Proxy.new(add: segment, to: self, headers: headers)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
## CRUD methods ...
|
|
17
|
+
|
|
18
|
+
def delete(path, headers: {}, query: {})
|
|
19
|
+
@parent.delete("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
|
|
20
|
+
headers: @default_headers.merge(headers), query: query)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get(path, headers: {}, query: {})
|
|
24
|
+
@parent.get("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
|
|
25
|
+
headers: @default_headers.merge(headers), query: query)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def patch(path, headers: {}, query: {}, payload: {})
|
|
29
|
+
@parent.patch("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
|
|
30
|
+
heades: @default_headers.merge(headers), query: query, payload: payload)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def post(path, headers: {}, query: {}, payload: {})
|
|
34
|
+
@parent.post("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
|
|
35
|
+
headers: @default_headers.merge(headers), query: query, payload: payload)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def put(path, headers: {}, query: {}, payload: {})
|
|
39
|
+
@parent.put("/#{@segment}/#{path}".gsub(%r{/+}, '/'),
|
|
40
|
+
headers: @default_headers.merge(headers), query: query, payload: payload)
|
|
41
|
+
end
|
|
42
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crapi
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nestor Custodio
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: pry
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.11'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.11'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: pry-byebug
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.6'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.6'
|
|
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
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '3.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '3.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec_junit_formatter
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0.3'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0.3'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: activesupport
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '5.2'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '5.2'
|
|
111
|
+
description:
|
|
112
|
+
email:
|
|
113
|
+
- sakimorix@gmail.com
|
|
114
|
+
executables: []
|
|
115
|
+
extensions: []
|
|
116
|
+
extra_rdoc_files: []
|
|
117
|
+
files:
|
|
118
|
+
- ".gitignore"
|
|
119
|
+
- ".rspec"
|
|
120
|
+
- ".rubocop.yml"
|
|
121
|
+
- ".ruby-version"
|
|
122
|
+
- ".travis.yml"
|
|
123
|
+
- ".yardopts"
|
|
124
|
+
- Gemfile
|
|
125
|
+
- Gemfile.lock
|
|
126
|
+
- LICENSE.txt
|
|
127
|
+
- README.md
|
|
128
|
+
- Rakefile
|
|
129
|
+
- bin/console
|
|
130
|
+
- bin/setup
|
|
131
|
+
- crapi.gemspec
|
|
132
|
+
- lib/crapi.rb
|
|
133
|
+
- lib/crapi/client.rb
|
|
134
|
+
- lib/crapi/errors.rb
|
|
135
|
+
- lib/crapi/proxy.rb
|
|
136
|
+
- lib/crapi/version.rb
|
|
137
|
+
homepage: https://www.github.com/nestor-custodio/crapi
|
|
138
|
+
licenses:
|
|
139
|
+
- MIT
|
|
140
|
+
metadata: {}
|
|
141
|
+
post_install_message:
|
|
142
|
+
rdoc_options: []
|
|
143
|
+
require_paths:
|
|
144
|
+
- lib
|
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
|
+
requirements:
|
|
147
|
+
- - ">="
|
|
148
|
+
- !ruby/object:Gem::Version
|
|
149
|
+
version: '0'
|
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - ">="
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: '0'
|
|
155
|
+
requirements: []
|
|
156
|
+
rubyforge_project:
|
|
157
|
+
rubygems_version: 2.7.6
|
|
158
|
+
signing_key:
|
|
159
|
+
specification_version: 4
|
|
160
|
+
summary: A simple API client with built-in segment/header proxy support. "... It could
|
|
161
|
+
be better." ™️
|
|
162
|
+
test_files: []
|