Class: Endo::Core
Instance Method Summary collapse
- #base_url(url) ⇒ Object
- #basic_auth(user, pass) ⇒ Object
- #delete(endpoint, &block) ⇒ Object
-
#from(method, endpoint, lmd = nil, &_block) ⇒ Object
TODO: Limit scope.
- #get(endpoint, &block) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
-
#param(key, val = nil) ⇒ Object
TODO: 制限.
- #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.
10 11 12 13 |
# File 'lib/endo/core.rb', line 10 def initialize @responses = {} @expect_alls = {} end |
Instance Method Details
#base_url(url) ⇒ Object
64 65 66 |
# File 'lib/endo/core.rb', line 64 def base_url(url) @base_url = url end |
#basic_auth(user, pass) ⇒ Object
68 69 70 71 72 |
# File 'lib/endo/core.rb', line 68 def basic_auth(user, pass) @basic_auth = { user: user, pass: pass } end |
#delete(endpoint, &block) ⇒ Object
23 24 25 |
# File 'lib/endo/core.rb', line 23 def delete(endpoint, &block) request(endpoint, :delete, &block) end |
#from(method, endpoint, lmd = nil, &_block) ⇒ Object
TODO: Limit scope
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/endo/core.rb', line 43 def from(method, endpoint, lmd = nil, &_block) key = build_response_key(method, endpoint) raise RuntimeError "NotFoundKey [#{key}]" unless @responses.key? key res = @responses[key] val = nil if !lmd.nil? val = res.instance_exec(&lmd) elsif block_given? val = 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
15 16 17 |
# File 'lib/endo/core.rb', line 15 def get(endpoint, &block) request(endpoint, :get, &block) end |
#param(key, val = nil) ⇒ Object
TODO: 制限
36 37 38 39 40 |
# File 'lib/endo/core.rb', line 36 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
27 28 29 |
# File 'lib/endo/core.rb', line 27 def patch(endpoint, &block) request(endpoint, :patch, &block) end |
#post(endpoint, &block) ⇒ Object
19 20 21 |
# File 'lib/endo/core.rb', line 19 def post(endpoint, &block) request(endpoint, :post, &block) end |
#put(endpoint, &block) ⇒ Object
31 32 33 |
# File 'lib/endo/core.rb', line 31 def put(endpoint, &block) request(endpoint, :put, &block) end |