Class: Endo::Core
Instance Method Summary collapse
- #base_url(url) ⇒ Object
- #basic_auth(user, pass) ⇒ Object
- #delete(endpoint, &block) ⇒ Object
-
#from(method, endpoint, prop = nil, &_block) ⇒ Object
TODO: Limit scope.
- #get(endpoint, &block) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
-
#param(key, val = nil) ⇒ Object
TODO: Limit scope.
- #patch(endpoint, &block) ⇒ Object
- #post(endpoint, &block) ⇒ Object
- #put(endpoint, &block) ⇒ Object
Methods included from Matchers
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
11 12 13 |
# File 'lib/endo/core.rb', line 11 def initialize @responses = {} end |
Instance Method Details
#base_url(url) ⇒ Object
15 16 17 |
# File 'lib/endo/core.rb', line 15 def base_url(url) @base_url = url end |
#basic_auth(user, pass) ⇒ Object
19 20 21 22 23 |
# File 'lib/endo/core.rb', line 19 def basic_auth(user, pass) @basic_auth = { user: user, pass: pass } end |
#delete(endpoint, &block) ⇒ Object
33 34 35 |
# File 'lib/endo/core.rb', line 33 def delete(endpoint, &block) request(endpoint, :delete, &block) end |
#from(method, endpoint, prop = nil, &_block) ⇒ Object
TODO: Limit scope
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/endo/core.rb', line 52 def from(method, endpoint, prop = nil, &_block) key = build_response_key(method, endpoint) raise "NotFoundKey [#{key}]" unless @responses.key? key res = @responses[key] val = if !prop.nil? if prop.is_a?(String) res[prop] elsif prop.is_a?(Array) res.dig(*prop) elsif prop.is_a?(Proc) res.instance_exec(&prop) else raise ArgumentError, 'BadPropType' end elsif block_given? yield res else raise ArgumentError, 'UndefinedBlock' end unless val.is_a?(String) || val.is_a?(Integer) || val.is_a?(Numeric) raise 'BadValueType' end val end |
#get(endpoint, &block) ⇒ Object
25 26 27 |
# File 'lib/endo/core.rb', line 25 def get(endpoint, &block) request(endpoint, :get, &block) end |
#param(key, val = nil) ⇒ Object
TODO: Limit scope
46 47 48 49 |
# File 'lib/endo/core.rb', line 46 def param(key, val = nil) raise ArgumentError, 'DupValue' unless !val.nil? ^ block_given? @params[key.to_s] = val ? val : yield end |
#patch(endpoint, &block) ⇒ Object
37 38 39 |
# File 'lib/endo/core.rb', line 37 def patch(endpoint, &block) request(endpoint, :patch, &block) end |
#post(endpoint, &block) ⇒ Object
29 30 31 |
# File 'lib/endo/core.rb', line 29 def post(endpoint, &block) request(endpoint, :post, &block) end |
#put(endpoint, &block) ⇒ Object
41 42 43 |
# File 'lib/endo/core.rb', line 41 def put(endpoint, &block) request(endpoint, :put, &block) end |