lex-http 0.1.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: 164560b9265b962324d49a55538177a0bc2514fdcfd0f02fb000a163aab9412f
4
+ data.tar.gz: 4b9c8ed65a0a406d40fc1aaac9d22e61dfd6bd94e67f226b396c75098e18c986
5
+ SHA512:
6
+ metadata.gz: abc5250220cc63a1f9d0d4f8e2a2f06081a672a3916588fa2608cf4cab88ff5652150cf352eecb15430821310993639093b5c7749c30fce40be1e81dc21f593f
7
+ data.tar.gz: e1aa4c6b0d7429d54bff5977defea190de47f401421d290c1910c3f2443e9c0cdbdabdc00f5916aadc15c2089ec0d27f94f63bc3594569c76d30a6dd828fe342
@@ -0,0 +1,11 @@
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,28 @@
1
+ Layout/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Metrics/BlockLength:
8
+ Max: 50
9
+ Metrics/AbcSize:
10
+ Max: 30
11
+ Layout/SpaceAroundEqualsInParameterDefault:
12
+ EnforcedStyle: space
13
+ Style/SymbolArray:
14
+ Enabled: true
15
+ Layout/HashAlignment:
16
+ EnforcedHashRocketStyle: table
17
+ EnforcedColonStyle: table
18
+ Style/Documentation:
19
+ Enabled: false
20
+ AllCops:
21
+ TargetRubyVersion: 2.5
22
+ NewCops: enable
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
25
+ Naming/FileName:
26
+ Enabled: false
27
+ Style/ClassAndModuleChildren:
28
+ Enabled: false
@@ -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 matthewdiverson@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in legion-extensions-http.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Esity
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,70 @@
1
+ # Legion::Extensions::Http
2
+
3
+ A Legion Extension designed to make HTTP requests
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lex-http'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lex-http
20
+
21
+ ## Adding to Legion
22
+ You can manually install with a `gem install lex-http` command or by adding it into your settings with something like this
23
+ ```json
24
+ {
25
+ "extensions": {
26
+ "http": {
27
+ "enabled": true, "workers": 1
28
+ }
29
+ }
30
+ }
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ There is only a single runner in this LEX. It can make the following calls
36
+ ##### Functions
37
+ |function|open_timeout|timeout|Port|Params|Body|Host|URI|
38
+ |---|---|---|---|---|---|---|---|
39
+ |get |Optional|Optional|80|Optional|Optional|Required|\|
40
+ |post |Optional|Optional|80|Optional|Optional|Required|\|
41
+ |patch |Optional|Optional|80|Optional|Optional|Required|\|
42
+ |put |Optional|Optional|80|Optional|Optional|Required|\|
43
+ |delete |Optional|Optional|80|Optional|Optional|Required|\|
44
+ |options|Optional|Optional|80|Optional|Optional|Required|\|
45
+ |head |Optional|Optional|80|Optional|Optional|Required|\|
46
+
47
+ #### Example Payloads
48
+ ```json
49
+ {"host": "https://google.com"}
50
+ ```
51
+
52
+ ```json
53
+ {"host": "https://google.com", "uri": "/", "port": 443}
54
+ ```
55
+
56
+ ```json
57
+ {"host": "http://192.168.1.1", "uri": "/my_custom_api", "port": 8080, "params": {"foo": "bar"} }
58
+ ```
59
+
60
+ ## Development
61
+ 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.
62
+
63
+ 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).
64
+
65
+ ## Contributing
66
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/legion-io/lex-http.
67
+
68
+ ## License
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
70
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'legion/extensions/http'
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__)
@@ -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,32 @@
1
+ require_relative 'lib/legion/extensions/http/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lex-http'
5
+ spec.version = Legion::Extensions::Http::VERSION
6
+ spec.authors = ['Esity']
7
+ spec.email = ['matthewdiverson@gmail.com']
8
+
9
+ spec.summary = 'LEX HTTP'
10
+ spec.description = 'Connections Legion to any HTTP source'
11
+ spec.homepage = 'https://bitbucket.org/legion-io/lex-http/src'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-http/src'
17
+ spec.metadata['changelog_uri'] = 'https://bitbucket.org/legion-io/lex-http/src/master/CHANGELOG.md'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'rubocop'
28
+
29
+ spec.add_dependency 'faraday'
30
+ spec.add_dependency 'multi_json'
31
+ spec.add_dependency 'multi_xml'
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'legion/extensions/http/version'
2
+ require 'legion/extensions'
3
+
4
+ module Legion
5
+ module Extensions
6
+ module Http
7
+ extend Legion::Extensions::Core
8
+
9
+ def self.default_settings
10
+ {
11
+ options: {
12
+ open_timeout: 5,
13
+ read_timeout: 10,
14
+ timeout: 10
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,124 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Legion
5
+ module Extensions
6
+ module Http
7
+ module Runners
8
+ module Http
9
+ def get(host:, uri: '', port: 80, **opts)
10
+ conn = Faraday.new(host) do |c|
11
+ c.options[:open_timeout] = settings[:options][:open_timeout]
12
+ c.options[:timeout] = settings[:options][:timeout]
13
+ c.port = port
14
+ c.response :xml, content_type: /\bxml$/
15
+ c.response :json, content_type: /\bjson$/
16
+ end
17
+
18
+ conn.get(uri) do |req|
19
+ req.params = opts[:params] unless opts[:params].nil?
20
+ req.body = opts[:body] if opts.key?(:body)
21
+ end.to_hash
22
+ end
23
+
24
+ def post(host:, uri: '', port: 80, **opts)
25
+ conn = Faraday.new(host) do |c|
26
+ c.options[:open_timeout] = settings[:options][:open_timeout]
27
+ c.options[:timeout] = settings[:options][:timeout]
28
+ c.port = port
29
+ c.response :xml, content_type: /\bxml$/
30
+ c.response :json, content_type: /\bjson$/
31
+ end
32
+ conn.post(uri) do |req|
33
+ req.params = opts[:params] unless opts[:params].nil?
34
+ req.body = opts[:body] if opts.key?(:body)
35
+ req.url uri
36
+ end.to_hash
37
+ end
38
+
39
+ def patch(host:, uri: '', port: 80, **opts)
40
+ conn = Faraday.new(host) do |c|
41
+ c.options[:open_timeout] = settings[:options][:open_timeout]
42
+ c.options[:timeout] = settings[:options][:timeout]
43
+ c.port = port
44
+ c.response :xml, content_type: /\bxml$/
45
+ c.response :json, content_type: /\bjson$/
46
+ end
47
+
48
+ conn.patch(uri) do |req|
49
+ req.params = opts[:params] unless opts[:params].nil?
50
+ req.body = opts[:body] if opts.key?(:body)
51
+ req.url uri
52
+ end.to_hash
53
+ end
54
+
55
+ def put(host:, uri: '/', port: 80, **opts)
56
+ conn = Faraday.new(host) do |c|
57
+ c.options[:open_timeout] = settings[:options][:open_timeout]
58
+ c.options[:timeout] = settings[:options][:timeout]
59
+ c.port = port
60
+ c.response :xml, content_type: /\bxml$/
61
+ c.response :json, content_type: /\bjson$/
62
+ end
63
+
64
+ conn.put(uri) do |req|
65
+ req.params = opts[:params] unless opts[:params].nil?
66
+ req.body = opts[:body] if opts.key?(:body)
67
+ req.url uri
68
+ end.to_hash
69
+ end
70
+
71
+ def delete(host:, uri: '/', port: 80, **opts)
72
+ conn = Faraday.new(host) do |c|
73
+ c.options[:open_timeout] = settings[:options][:open_timeout]
74
+ c.options[:timeout] = settings[:options][:timeout]
75
+ c.port = port
76
+ c.response :xml, content_type: /\bxml$/
77
+ c.response :json, content_type: /\bjson$/
78
+ end
79
+
80
+ conn.delete(uri) do |req|
81
+ req.params = opts[:params] unless opts[:params].nil?
82
+ req.body = opts[:body] if opts.key?(:body)
83
+ req.url uri
84
+ end.to_hash
85
+ end
86
+
87
+ def head(host:, uri: '/', port: 80, **opts)
88
+ conn = Faraday.new(host) do |c|
89
+ c.options[:open_timeout] = settings[:options][:open_timeout]
90
+ c.options[:timeout] = settings[:options][:timeout]
91
+ c.port = port
92
+ c.response :xml, content_type: /\bxml$/
93
+ c.response :json, content_type: /\bjson$/
94
+ end
95
+
96
+ conn.head(uri) do |req|
97
+ req.params = opts[:params] unless opts[:params].nil?
98
+ req.body = opts[:body] if opts.key?(:body)
99
+ req.url uri
100
+ end.to_hash
101
+ end
102
+
103
+ def options(host:, uri: '/', port: 80, **opts)
104
+ conn = Faraday.new(host) do |c|
105
+ c.options[:open_timeout] = settings[:options][:open_timeout]
106
+ c.options[:timeout] = settings[:options][:timeout]
107
+ c.port = port
108
+ c.response :xml, content_type: /\bxml$/
109
+ c.response :json, content_type: /\bjson$/
110
+ end
111
+
112
+ conn.options(uri) do |req|
113
+ req.params = opts[:params] unless opts[:params].nil?
114
+ req.body = opts[:body] if opts.key?(:body)
115
+ req.url uri
116
+ end.to_hash
117
+ end
118
+
119
+ include Legion::Extensions::Helpers::Lex
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,7 @@
1
+ module Legion
2
+ module Extensions
3
+ module Http
4
+ VERSION = '0.1.0'.freeze
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Connections Legion to any HTTP source
98
+ email:
99
+ - matthewdiverson@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".rubocop.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - legion-extensions-http.gemspec
115
+ - lib/legion/extensions/http.rb
116
+ - lib/legion/extensions/http/runners/http.rb
117
+ - lib/legion/extensions/http/version.rb
118
+ homepage: https://bitbucket.org/legion-io/lex-http/src
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ homepage_uri: https://bitbucket.org/legion-io/lex-http/src
123
+ source_code_uri: https://bitbucket.org/legion-io/lex-http/src
124
+ changelog_uri: https://bitbucket.org/legion-io/lex-http/src/master/CHANGELOG.md
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 2.5.0
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubygems_version: 3.1.2
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: LEX HTTP
144
+ test_files: []