Class: Endo::Core
Instance Method Summary collapse
- #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, &block) ⇒ Object
TODO: 制限.
- #patch(endpoint, &block) ⇒ Object
- #post(endpoint, &block) ⇒ Object
- #put(endpoint, &block) ⇒ Object
- #set(key, val) ⇒ Object
Methods included from Matchers
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
10 11 12 13 14 |
# File 'lib/endo/core.rb', line 10 def initialize @props = {} @responses = {} @expect_alls = {} end |
Instance Method Details
#basic_auth(user, pass) ⇒ Object
78 79 80 81 82 |
# File 'lib/endo/core.rb', line 78 def basic_auth(user, pass) @basic_auth = { user: user, pass: pass } end |
#delete(endpoint, &block) ⇒ Object
29 30 31 |
# File 'lib/endo/core.rb', line 29 def delete(endpoint, &block) request(endpoint, :delete, &block) end |
#from(method, endpoint, lmd = nil, &block) ⇒ Object
TODO: Limit scope
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/endo/core.rb', line 56 def from(method, endpoint, lmd=nil, &block) key = build_response_key(method, endpoint) unless @responses.has_key? key raise RuntimeError.new("NotFoundKey [#{key}]") end res = @responses[key] val = if lmd res.instance_exec &lmd elsif block block.call(res) else raise ArgumentError.new('UndefinedBlock') end unless val.is_a?(String) || val.is_a?(Integer) || val.is_a?(Numeric) raise RuntimeError.new('BadValueType') end val end |
#get(endpoint, &block) ⇒ Object
21 22 23 |
# File 'lib/endo/core.rb', line 21 def get(endpoint, &block) request(endpoint, :get, &block) end |
#param(key, val = nil, &block) ⇒ Object
TODO: 制限
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/endo/core.rb', line 42 def param(key, val=nil, &block) unless (!val.nil?) ^ (!block.nil?) # Only either one raise ArgumentError.new('DupValue') end @params[key.to_s] = if val val else block.call end end |
#patch(endpoint, &block) ⇒ Object
33 34 35 |
# File 'lib/endo/core.rb', line 33 def patch(endpoint, &block) request(endpoint, :patch, &block) end |
#post(endpoint, &block) ⇒ Object
25 26 27 |
# File 'lib/endo/core.rb', line 25 def post(endpoint, &block) request(endpoint, :post, &block) end |
#put(endpoint, &block) ⇒ Object
37 38 39 |
# File 'lib/endo/core.rb', line 37 def put(endpoint, &block) request(endpoint, :put, &block) end |
#set(key, val) ⇒ Object
16 17 18 19 |
# File 'lib/endo/core.rb', line 16 def set(key, val) #TODO: validate key @props[key] = val end |