我有一个像这样使用的 httparty “模型”
myRest = RestModel.new
myRest.someGetResquest()
myRest.somePostRequest()
我将如何将其更改为类似于 activemodel 的工作,像这样?
RestModel.someGetRequest()
RestModel.somePostRequest()
这篇博客文章展示了如何包含单例模块,但它仍然像这样访问实例:RestModel.instance.someGetRequest()
这是我的代码:
class Managementdb
include HTTParty
base_uri "http://localhost:7001/management/"
def initialise(authToken)
self.authToken = authToken
end
def login()
response = self.class.get("/testLogin")
if response.success?
self.authToken = response["authToken"]
else
# this just raises the net/http response that was raised
raise response.response
end
end
attr_accessor :authToken
...
end
请告诉我我做错了(给我看灯)