foobara-http-api-command 0.0.1 → 0.0.3
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 +4 -4
- data/CHANGELOG.md +8 -2
- data/src/foobara/http_api_command.rb +67 -0
- data/src/foobara/http_api_get_command.rb +2 -55
- data/src/foobara/http_api_post_command.rb +13 -0
- metadata +6 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61615cf5f9d004cfc8525fd42c7536da93ca8c8fd55413ea56bf0080fa0002b4
|
4
|
+
data.tar.gz: a303d0d85894a7ad1f17476480e73a91fdb5827e01469f025f9574150f6ebeb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 639a44361ec0e66d04a03f850c828be566c6c914fcbce3cd3a268b53d8ddb83ac971376a8079f65d2f40794f6e546f91696fb2377f7a9937a2f129a94a46c358
|
7
|
+
data.tar.gz: 4ad1211996483b99d7f3f4a416d6c05540dac98e98a94a4518a31bb1472256aa95c80f8baecb6cf05b0112f99298f8f973a5e1fe4e1f53c481fe14b72acfdf25
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module HttpApiCommand
|
6
|
+
include Concern
|
7
|
+
|
8
|
+
def execute
|
9
|
+
build_request_body
|
10
|
+
build_request_headers
|
11
|
+
issue_http_request
|
12
|
+
parse_response
|
13
|
+
build_result
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :request_body, :request_headers, :response, :response_body
|
17
|
+
|
18
|
+
def api_url
|
19
|
+
@api_url ||= instance_eval(&self.class.foobara_url_block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_request_body
|
23
|
+
self.request_body = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_request_headers
|
27
|
+
self.request_headers = {
|
28
|
+
"Content-Type" => "application/json"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def issue_http_request
|
33
|
+
# :nocov:
|
34
|
+
raise "subclass responsibility"
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_result
|
39
|
+
response_body
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_response
|
43
|
+
json = if response.is_a?(Net::HTTPSuccess)
|
44
|
+
response.body
|
45
|
+
else
|
46
|
+
# :nocov:
|
47
|
+
raise "Could not successfully hit #{api_url}: " \
|
48
|
+
"#{response.code} #{response.message}"
|
49
|
+
# :nocov:
|
50
|
+
end
|
51
|
+
|
52
|
+
self.response_body = JSON.parse(json)
|
53
|
+
end
|
54
|
+
|
55
|
+
module ClassMethods
|
56
|
+
attr_accessor :foobara_url_block
|
57
|
+
|
58
|
+
def url(string = nil, &block)
|
59
|
+
self.foobara_url_block = if block_given?
|
60
|
+
block
|
61
|
+
else
|
62
|
+
proc { string }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -1,67 +1,14 @@
|
|
1
|
-
|
2
|
-
require "net/http"
|
1
|
+
require_relative "http_api_command"
|
3
2
|
|
4
3
|
module Foobara
|
5
4
|
module HttpApiGetCommand
|
6
5
|
include Concern
|
7
|
-
|
8
|
-
def execute
|
9
|
-
build_request_body
|
10
|
-
build_request_headers
|
11
|
-
issue_http_request
|
12
|
-
parse_response
|
13
|
-
build_result
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_accessor :request_body, :request_headers, :response, :response_body
|
17
|
-
|
18
|
-
def api_url
|
19
|
-
@api_url ||= instance_eval(&self.class.foobara_url_block)
|
20
|
-
end
|
21
|
-
|
22
|
-
def build_request_body
|
23
|
-
self.request_body = {}
|
24
|
-
end
|
25
|
-
|
26
|
-
def build_request_headers
|
27
|
-
self.request_headers = {
|
28
|
-
"Content-Type" => "application/json"
|
29
|
-
}
|
30
|
-
end
|
6
|
+
include HttpApiCommand
|
31
7
|
|
32
8
|
def issue_http_request
|
33
9
|
uri = URI(api_url)
|
34
10
|
uri.query = URI.encode_www_form(request_body)
|
35
11
|
self.response = Net::HTTP.get_response(uri, request_headers)
|
36
12
|
end
|
37
|
-
|
38
|
-
def build_result
|
39
|
-
response_body
|
40
|
-
end
|
41
|
-
|
42
|
-
def parse_response
|
43
|
-
json = if response.is_a?(Net::HTTPSuccess)
|
44
|
-
response.body
|
45
|
-
else
|
46
|
-
# :nocov:
|
47
|
-
raise "Could not successfully hit #{api_url}: " \
|
48
|
-
"#{response.code} #{response.message}"
|
49
|
-
# :nocov:
|
50
|
-
end
|
51
|
-
|
52
|
-
self.response_body = JSON.parse(json)
|
53
|
-
end
|
54
|
-
|
55
|
-
module ClassMethods
|
56
|
-
attr_accessor :foobara_url_block
|
57
|
-
|
58
|
-
def url(string = nil, &block)
|
59
|
-
self.foobara_url_block = if block_given?
|
60
|
-
block
|
61
|
-
else
|
62
|
-
proc { string }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
13
|
end
|
67
14
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "http_api_command"
|
2
|
+
|
3
|
+
module Foobara
|
4
|
+
module HttpApiPostCommand
|
5
|
+
include Concern
|
6
|
+
include HttpApiCommand
|
7
|
+
|
8
|
+
def issue_http_request
|
9
|
+
uri = URI.parse(api_url)
|
10
|
+
self.response = Net::HTTP.post(uri, JSON.generate(request_body), request_headers)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-http-api-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-08 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: foobara
|
@@ -24,7 +23,6 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0'
|
27
|
-
description:
|
28
26
|
email:
|
29
27
|
- azimux@gmail.com
|
30
28
|
executables: []
|
@@ -36,7 +34,9 @@ files:
|
|
36
34
|
- LICENSE.txt
|
37
35
|
- README.md
|
38
36
|
- lib/foobara/http_api_command.rb
|
37
|
+
- src/foobara/http_api_command.rb
|
39
38
|
- src/foobara/http_api_get_command.rb
|
39
|
+
- src/foobara/http_api_post_command.rb
|
40
40
|
homepage: https://github.com/foobara/http-api-command
|
41
41
|
licenses:
|
42
42
|
- MPL-2.0
|
@@ -45,7 +45,6 @@ metadata:
|
|
45
45
|
source_code_uri: https://github.com/foobara/http-api-command
|
46
46
|
changelog_uri: https://github.com/foobara/http-api-command/blob/main/CHANGELOG.md
|
47
47
|
rubygems_mfa_required: 'true'
|
48
|
-
post_install_message:
|
49
48
|
rdoc_options: []
|
50
49
|
require_paths:
|
51
50
|
- lib
|
@@ -53,15 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
52
|
requirements:
|
54
53
|
- - ">="
|
55
54
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.
|
55
|
+
version: 3.4.0
|
57
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
61
|
requirements: []
|
63
|
-
rubygems_version: 3.
|
64
|
-
signing_key:
|
62
|
+
rubygems_version: 3.6.3
|
65
63
|
specification_version: 4
|
66
64
|
summary: No description. Add one.
|
67
65
|
test_files: []
|