foobara-http-api-command 0.0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eefd62884619d75957db64c7d1516f8295aef58eeb11da24ba666c22b6b8249e
4
- data.tar.gz: 9948d0ea1b6703baa80eb2d7f2892214a306ce74cbbfc156eb1e59ccd7ec7c86
3
+ metadata.gz: 61615cf5f9d004cfc8525fd42c7536da93ca8c8fd55413ea56bf0080fa0002b4
4
+ data.tar.gz: a303d0d85894a7ad1f17476480e73a91fdb5827e01469f025f9574150f6ebeb2
5
5
  SHA512:
6
- metadata.gz: 5b8a838148852a0217bf26563af54a22d1b630d1febe0453b8390ffd2dcbd0a93f7bd257a6c41e873acefc81fc7c732329b4b6af0c87ca312c479cd765b809d9
7
- data.tar.gz: 0e74fc2f8fd361485438df580f3ffdb62ee2b2f77af2d758ade7dcf0d65a63d043457f3f060bf364bc0b0596f20f699b0eac738cafc99c170732f3ce69805e2d
6
+ metadata.gz: 639a44361ec0e66d04a03f850c828be566c6c914fcbce3cd3a268b53d8ddb83ac971376a8079f65d2f40794f6e546f91696fb2377f7a9937a2f129a94a46c358
7
+ data.tar.gz: 4ad1211996483b99d7f3f4a416d6c05540dac98e98a94a4518a31bb1472256aa95c80f8baecb6cf05b0112f99298f8f973a5e1fe4e1f53c481fe14b72acfdf25
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.3] - 2025-02-08
2
+
3
+ - Implement HttpApiPostCommand
4
+
1
5
  ## [0.0.2] - 2025-01-07
2
6
 
3
7
  - Bump Ruby to 3.4.1
@@ -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
- require "uri"
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,13 +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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-07 00:00:00.000000000 Z
10
+ date: 2025-02-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -34,7 +34,9 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - lib/foobara/http_api_command.rb
37
+ - src/foobara/http_api_command.rb
37
38
  - src/foobara/http_api_get_command.rb
39
+ - src/foobara/http_api_post_command.rb
38
40
  homepage: https://github.com/foobara/http-api-command
39
41
  licenses:
40
42
  - MPL-2.0
@@ -57,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
59
  - !ruby/object:Gem::Version
58
60
  version: '0'
59
61
  requirements: []
60
- rubygems_version: 3.6.2
62
+ rubygems_version: 3.6.3
61
63
  specification_version: 4
62
64
  summary: No description. Add one.
63
65
  test_files: []