0
我正在为ruby中的外部服务创建api包装器。我使用HTTParty,我期待的回应可以像任何一种格式:api包装器必须处理可变响应
response = {one: two:{three:{four: {five: "hello there"}}}}
response = {one: two:{three:{four: {five: ["hello there", "good by now"]}}}} #notice array
response = {one: two:{three:{four: {five: six:{seven: {eight: {nine:{ten: "wow, ugly"}}}}}}}}
response = {one: "bad response"}
response = {one: two:[{three:{four: {five: "hello there"}}}, "check here too"]}
我已经创造了许多if else
检查。请记住one
,two
等......不是真正的关键名称。真正的钥匙名称更像FirstBusinessType
,CommercialPropertyLocationAddress1
。所以,所有这些都会导致我的屏幕充满长长的丑角。我如何将它全部抽象到另一个课堂或一个对象中?有没有我应该看看你可以推荐的教程? Github API封装(如Twitter)看起来不错。我几乎看不到任何关键或这种性质的条件。如何让我的代码看起来像ruby,而不是像api的响应?
感谢