foobara-http-api-command 0.0.4 → 0.0.5

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: 50391d8f44e37644619f61aa1d38eba3104e454d4b652d08561fae9cac5b060b
4
- data.tar.gz: ed7174a489766ab28a190967be00f60c3b831636c60515c7f4531ce41909ea04
3
+ metadata.gz: 47344f134791c7562826026ebe261a8e89152295bb9c65fd8bc7d3a3e8bad97f
4
+ data.tar.gz: 3db4128c29680b07b59c66a76e8a53daccac99fc589d418ad0e0141c28069d97
5
5
  SHA512:
6
- metadata.gz: 36bd3a6473d63328347e23645aa50a87cbc8862c09516acd98eef502c6aaca1a060fec624cbf6cd696318198c0ef75326c6a4b7c649028805fb06ebe39658719
7
- data.tar.gz: 7cb9b7b0aecde58a0b4ab81bf26b1670454fffafff66bd61cf61890f106037999fca0a372d3e4ad788b576277a3b814e1c60709b74276ca6478408b876782e85
6
+ metadata.gz: 5ceca930f5086d7fd0a1814de7cc6915bbace3a0d6c85ba57e19f120004901d1ee823da5d8221c11d1d67a6e3bf82702ea959cce60246aef49b86b423a3b4744
7
+ data.tar.gz: 2ceaa7be546bde7d013c72dda00829c8f06b52267999c2e98024887d7664d81385ece7536cd3f66b04442d123edb3058d68d824ea27adc78a87e91fb62ed4374
data/CHANGELOG.md CHANGED
@@ -1,6 +1,7 @@
1
- ## [0.0.4] - 2025-02-17
1
+ ## [0.0.5] - 2025-02-17
2
2
 
3
3
  - Support separate base_url and path helpers
4
+ - Eliminate concept of separate mixins for different HTTP methods
4
5
 
5
6
  ## [0.0.3] - 2025-02-08
6
7
 
@@ -9,7 +9,20 @@ module Foobara
9
9
  end
10
10
 
11
11
  module ClassMethods
12
- attr_accessor :foobara_base_url_block, :foobara_base_url, :foobara_path, :foobara_url_block, :foobara_url
12
+ attr_accessor :foobara_base_url_block,
13
+ :foobara_base_url,
14
+ :foobara_path,
15
+ :foobara_url_block,
16
+ :foobara_url,
17
+ :foobara_http_method
18
+
19
+ def http_method(method = nil)
20
+ if method
21
+ self.foobara_http_method = method
22
+ else
23
+ foobara_http_method || :get
24
+ end
25
+ end
13
26
 
14
27
  def base_url(url = nil, &block)
15
28
  if block_given?
@@ -27,9 +27,19 @@ module Foobara
27
27
  end
28
28
 
29
29
  def issue_http_request
30
- # :nocov:
31
- raise "subclass responsibility"
32
- # :nocov:
30
+ case self.class.http_method
31
+ when :get
32
+ uri = URI(api_url)
33
+ uri.query = URI.encode_www_form(request_body)
34
+ self.response = Net::HTTP.get_response(uri, request_headers)
35
+ when :post
36
+ uri = URI.parse(api_url)
37
+ self.response = Net::HTTP.post(uri, JSON.generate(request_body), request_headers)
38
+ else
39
+ # :nocov:
40
+ raise "Unknown http method #{self.class.http_method}"
41
+ # :nocov:
42
+ end
33
43
  end
34
44
 
35
45
  def build_result
metadata CHANGED
@@ -1,7 +1,7 @@
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -36,8 +36,6 @@ files:
36
36
  - lib/foobara/http_api_command.rb
37
37
  - src/foobara/concerns/url.rb
38
38
  - src/foobara/http_api_command.rb
39
- - src/foobara/http_api_get_command.rb
40
- - src/foobara/http_api_post_command.rb
41
39
  homepage: https://github.com/foobara/http-api-command
42
40
  licenses:
43
41
  - MPL-2.0
@@ -1,14 +0,0 @@
1
- require_relative "http_api_command"
2
-
3
- module Foobara
4
- module HttpApiGetCommand
5
- include Concern
6
- include HttpApiCommand
7
-
8
- def issue_http_request
9
- uri = URI(api_url)
10
- uri.query = URI.encode_www_form(request_body)
11
- self.response = Net::HTTP.get_response(uri, request_headers)
12
- end
13
- end
14
- end
@@ -1,13 +0,0 @@
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