Class: Clever::FakeServer
- Inherits:
-
Object
- Object
- Clever::FakeServer
- Defined in:
- lib/clever/fake_server.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #get_json(verb, json) ⇒ Object
-
#initialize(opts) ⇒ FakeServer
constructor
A new instance of FakeServer.
- #method_missing(sym, *args, &block) ⇒ Object
- #request(req, body = nil) ⇒ Object
Constructor Details
#initialize(opts) ⇒ FakeServer
Returns a new instance of FakeServer.
6 7 8 |
# File 'lib/clever/fake_server.rb', line 6 def initialize opts @api_key = opts[:api_key] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/clever/fake_server.rb', line 4 def api_key @api_key end |
Instance Method Details
#get_json(verb, json) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/clever/fake_server.rb', line 38 def get_json verb, json unless verb == "GET" return Clever::FakeResponse.new("405", "") end Clever::FakeResponse.new("200", json) end |
#request(req, body = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/clever/fake_server.rb', line 10 def request(req, body=nil) return Clever::FakeResponse.new("404", "") unless req.path.start_with? "/v1.1/" path, params = req.path.split('?') resource, id, action = path.gsub(/(\/v1\.1\/|\?$)/, "").split('/') if action.nil? && id.nil? path = resource elsif id.nil? path = resource.gsub(/s$/, '') else path = resource.gsub(/s$/, '') + (action.nil? ? '' : "_#{action}") end self.send(path, req.method) #rescue => exception # return Clever::FakeResponse.new("500", exception.message) end |