foobara-http-api-command 0.0.3 → 0.0.4

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: 61615cf5f9d004cfc8525fd42c7536da93ca8c8fd55413ea56bf0080fa0002b4
4
- data.tar.gz: a303d0d85894a7ad1f17476480e73a91fdb5827e01469f025f9574150f6ebeb2
3
+ metadata.gz: 50391d8f44e37644619f61aa1d38eba3104e454d4b652d08561fae9cac5b060b
4
+ data.tar.gz: ed7174a489766ab28a190967be00f60c3b831636c60515c7f4531ce41909ea04
5
5
  SHA512:
6
- metadata.gz: 639a44361ec0e66d04a03f850c828be566c6c914fcbce3cd3a268b53d8ddb83ac971376a8079f65d2f40794f6e546f91696fb2377f7a9937a2f129a94a46c358
7
- data.tar.gz: 4ad1211996483b99d7f3f4a416d6c05540dac98e98a94a4518a31bb1472256aa95c80f8baecb6cf05b0112f99298f8f973a5e1fe4e1f53c481fe14b72acfdf25
6
+ metadata.gz: 36bd3a6473d63328347e23645aa50a87cbc8862c09516acd98eef502c6aaca1a060fec624cbf6cd696318198c0ef75326c6a4b7c649028805fb06ebe39658719
7
+ data.tar.gz: 7cb9b7b0aecde58a0b4ab81bf26b1670454fffafff66bd61cf61890f106037999fca0a372d3e4ad788b576277a3b814e1c60709b74276ca6478408b876782e85
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [0.0.4] - 2025-02-17
2
+
3
+ - Support separate base_url and path helpers
4
+
1
5
  ## [0.0.3] - 2025-02-08
2
6
 
3
7
  - Implement HttpApiPostCommand
@@ -0,0 +1,83 @@
1
+ module Foobara
2
+ module HttpApiCommand
3
+ module Concerns
4
+ module Url
5
+ include Concern
6
+
7
+ def api_url
8
+ @api_url ||= self.class.compute_api_url(self)
9
+ end
10
+
11
+ module ClassMethods
12
+ attr_accessor :foobara_base_url_block, :foobara_base_url, :foobara_path, :foobara_url_block, :foobara_url
13
+
14
+ def base_url(url = nil, &block)
15
+ if block_given?
16
+ unless url.nil?
17
+ # :nocov:
18
+ raise ArgumentError, "Cannot specify both url and block"
19
+ # :nocov:
20
+ end
21
+
22
+ self.foobara_base_url_block = block
23
+ elsif url
24
+ self.foobara_base_url = url
25
+ else
26
+ # :nocov:
27
+ raise ArgumentError, "No base url specified"
28
+ # :nocov:
29
+ end
30
+ end
31
+
32
+ def path(path = nil)
33
+ if path
34
+ self.foobara_path = path
35
+ end
36
+ end
37
+
38
+ def url(uri = nil, &block)
39
+ if block_given?
40
+ unless uri.nil?
41
+ # :nocov:
42
+ raise ArgumentError, "Cannot specify both uri and block"
43
+ # :nocov:
44
+ end
45
+
46
+ self.foobara_url_block = block
47
+ elsif uri
48
+ self.foobara_url = uri
49
+ else
50
+ # :nocov:
51
+ raise ArgumentError, "Must give either a url or a block that returns url"
52
+ # :nocov:
53
+ end
54
+ end
55
+
56
+ def compute_api_url(command)
57
+ if foobara_url
58
+ foobara_url
59
+ elsif foobara_url_block
60
+ command.instance_eval(&foobara_url_block)
61
+ elsif foobara_path
62
+ base = if foobara_base_url
63
+ foobara_base_url
64
+ elsif foobara_base_url_block
65
+ command.instance_eval(&foobara_base_url_block)
66
+ else
67
+ # :nocov:
68
+ raise "Not able to determine the api url. Did you remember to call .url or .path and .base_url?"
69
+ # :nocov:
70
+ end
71
+
72
+ "#{base}#{foobara_path}"
73
+ else
74
+ # :nocov:
75
+ raise "Not able to determine the api url. Did you remember to call .url or .path and .base_url?"
76
+ # :nocov:
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -4,6 +4,7 @@ require "net/http"
4
4
  module Foobara
5
5
  module HttpApiCommand
6
6
  include Concern
7
+ include Concerns::Url
7
8
 
8
9
  def execute
9
10
  build_request_body
@@ -15,10 +16,6 @@ module Foobara
15
16
 
16
17
  attr_accessor :request_body, :request_headers, :response, :response_body
17
18
 
18
- def api_url
19
- @api_url ||= instance_eval(&self.class.foobara_url_block)
20
- end
21
-
22
19
  def build_request_body
23
20
  self.request_body = {}
24
21
  end
@@ -51,17 +48,5 @@ module Foobara
51
48
 
52
49
  self.response_body = JSON.parse(json)
53
50
  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
51
  end
67
52
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-08 00:00:00.000000000 Z
10
+ date: 2025-02-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
@@ -34,6 +34,7 @@ files:
34
34
  - LICENSE.txt
35
35
  - README.md
36
36
  - lib/foobara/http_api_command.rb
37
+ - src/foobara/concerns/url.rb
37
38
  - src/foobara/http_api_command.rb
38
39
  - src/foobara/http_api_get_command.rb
39
40
  - src/foobara/http_api_post_command.rb