koine-rest_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da36fc4df6eb2531f9c94cb98cfc95e56a0943464a517b73ad1d5845a1944cc0
4
+ data.tar.gz: ad8f8705d5da75a29caddb8ffae8477fc1e308771b6c559cb113206b9e707fba
5
+ SHA512:
6
+ metadata.gz: 5137beef343e4fb1d7b038fe7b6f38dcd996acf4203e4bf6796f6492af2d0dc04c727533c7e9033e1f2a2fca990a8e00054ece027306139da27e1b57d1306756
7
+ data.tar.gz: 795b538464313e54b848a7fa7a405d053b4158069df31e6148e2e7633248fda106abb95deeeed152103fad3c4cab5deeaefe7482c7fe6825dd2f94c79f14d787
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ detectors:
2
+ UtilityFunction:
3
+ public_methods_only: true
4
+
5
+ exclude_paths:
6
+ - spec
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,44 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ Metrics/BlockLength:
6
+ Exclude:
7
+ - 'spec/**/*'
8
+ - '*.gemspec'
9
+
10
+ Metrics/LineLength:
11
+ Max: 100
12
+ Exclude:
13
+ - '*.gemspec'
14
+
15
+ Style/GuardClause:
16
+ Enabled: false
17
+
18
+ Style/IfUnlessModifier:
19
+ Enabled: false
20
+
21
+ Layout/MultilineMethodCallIndentation:
22
+ EnforcedStyle: indented
23
+
24
+ Layout/MultilineOperationIndentation:
25
+ Enabled: true
26
+ EnforcedStyle: indented
27
+
28
+ Naming/RescuedExceptionsVariableName:
29
+ PreferredName: 'exception'
30
+
31
+ RSpec/ExampleLength:
32
+ Max: 10
33
+ Exclude:
34
+ - spec/upsell/rest_client/rspec_mock_client_spec.rb
35
+
36
+ RSpec/MultipleExpectations:
37
+ Enabled: false
38
+
39
+ RSpec/NestedGroups:
40
+ Exclude:
41
+ - spec/upsell/rest_client/async_builder_spec.rb
42
+
43
+ # AllCops:
44
+ # Exclude:
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,11 @@
1
+ Changelog
2
+ ----------------
3
+
4
+ ## v1.0.1
5
+
6
+ Parse requests outside the threads. The fetching of the requests still happens inside threads for async requests
7
+
8
+
9
+ ## v1.0.0
10
+
11
+ Add the ability of setting headers to the requests
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at marcelo.jacobus@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in koine-rest_client.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Marcelo Jacobus
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.
@@ -0,0 +1,139 @@
1
+ # Koine::RestClient
2
+
3
+ Another http client with async
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'koine-rest_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install koine-rest_client
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # default configuration for every request
25
+ request = Koine::RestClient::Request.new(
26
+ base_url: 'http://some.endpoint.com/rest',
27
+ query_params: { auth_token: 'the-auth-token' },
28
+ headers: { 'X-Client' => 'The Collest Client' }
29
+ )
30
+ client = Koine::RestClient::Client.new(base_request: request)
31
+ json_response = client.get('foo/bar')
32
+
33
+ json_response = client.post(
34
+ 'foo/bar',
35
+ campaign_data,
36
+ query_params: { auth_token: 'other_rid' } # other auth_token
37
+ )
38
+
39
+ # or throw on non 200
40
+
41
+ json_response = client.post(
42
+ 'foo/bar',
43
+ campaign_data,
44
+ query_params: { auth_token: nil } # remove auth_token param
45
+ )
46
+ ```
47
+
48
+ If you care for the response details:
49
+
50
+ ```ruby
51
+
52
+ json_response = client.get('foo/bar') do |response|
53
+ if response.code == 1
54
+ raise 'what, really?'
55
+ end
56
+ end
57
+ ```
58
+
59
+ ### Async calls
60
+
61
+ ```ruby
62
+ data = client.async do |builder|
63
+ builder.get('foo', rid: 'bar') do |response|
64
+ builder.get('bar') do |response|
65
+ Rails.logger.log(response)
66
+ end
67
+
68
+ builder.post('baz', { payload: :value })
69
+
70
+ # optional. Raise error if ommited
71
+ builder.on_error do |exception|
72
+ # ignore
73
+ end
74
+ end
75
+
76
+ data[0] # foo response
77
+ data[1] # bar response
78
+ data[2] # baz response
79
+ ```
80
+
81
+ ### Mocking in rspec
82
+
83
+ ```ruby
84
+ require 'koine/rest_client/rspec_mock_client'
85
+
86
+ let(:mock_client) { Koine::RestClient::RspecMockClient.new(spec) }
87
+
88
+ client.mock do |mocker|
89
+ mocker.get('foo').will_return(body: { foo: :bar })
90
+ mocker.put('bar', baz: :foo).will_return(body: { baz: :bar })
91
+ mocker.delete('error').will_return(code: 400, body: { message: :oops })
92
+ end
93
+
94
+ # or with custom response use the block
95
+
96
+ client.mock do |mocker|
97
+ mocker.get('foo').will_return(body: 'parsed-body') do |response|
98
+ double(code: 200, parsed_response: "the #{response.parsed_response}")
99
+ end
100
+ end
101
+ ```
102
+
103
+ ### Mocking a server
104
+
105
+ Start the server
106
+
107
+ ```bash
108
+ ./bin/mock_server
109
+ ```
110
+
111
+ ```ruby
112
+ request = Koine::RestClient::Request.new(
113
+ base_url: 'http://localhost:4321/something',
114
+ query_params: { rid: 'internal' },
115
+ headers: { 'X-Foo-Bar' => 'foo-bar' }
116
+ )
117
+ client = Koine::RestClient::Client.new(base_request: request)
118
+
119
+ client.get('foo') # check the response
120
+ ```
121
+
122
+
123
+ ## Development
124
+
125
+ 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.
126
+
127
+ 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).
128
+
129
+ ## Contributing
130
+
131
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mjacobus/koine-rest_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+ ## Code of Conduct
138
+
139
+ Everyone interacting in the Koine::RestClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mjacobus/koine-rest_client/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'koine/rest_client'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rack'
5
+ require 'json'
6
+
7
+ app = proc do |env|
8
+ request = Rack::Request.new(env)
9
+ headers = {}
10
+ request.each_header do |name, value|
11
+ unless name.match('rack.')
12
+ headers[name] = value
13
+ end
14
+ end
15
+ response = {
16
+ path: request.path,
17
+ method: request.request_method,
18
+ params: request.params,
19
+ request_headers: headers
20
+ }
21
+ code = request.params['response_code'] || 200
22
+ [code, { 'Content-Type' => 'application/json' }, [response.to_json]]
23
+ end
24
+
25
+ Rack::Handler.default.run app, Port: 4321
@@ -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
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'koine/rest_client/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'koine-rest_client'
9
+ spec.version = Koine::RestClient::VERSION
10
+ spec.authors = ['Marcelo Jacobus']
11
+ spec.email = ['marcelo.jacobus@gmail.com']
12
+
13
+ spec.summary = 'Another http client'
14
+ spec.description = 'Another http client - with support to async calls'
15
+ spec.homepage = 'https://github.com/mjacobus/koine-rest_client'
16
+ spec.license = 'MIT'
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'addressable', '>= 2.3'
34
+ spec.add_dependency 'httparty', '>= 0.17.0'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 2.0'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'reek'
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'rubocop'
41
+ spec.add_development_dependency 'rubocop-performance'
42
+ spec.add_development_dependency 'rubocop-rspec'
43
+ spec.add_development_dependency 'simplecov'
44
+ spec.add_development_dependency 'object_comparator'
45
+ spec.add_development_dependency 'awesome_print'
46
+ end