Created
January 29, 2016 19:06
-
-
Save jerry-tao/0b71e2eaac660175107a to your computer and use it in GitHub Desktop.
Service Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SO | |
attr_accessor :url | |
def initialize(url) | |
url=url | |
end | |
def fetch! | |
get(url) do |response| | |
@attributes = response | |
end | |
end | |
def get(url, options={format: :json}) | |
begin | |
res = Resource.get(url) | |
yield(send(options[:format], res)) | |
rescue->e | |
yield {"content" => e.message} | |
end | |
end | |
def respond_to?(name) | |
true if @attributes[name] | |
super | |
end | |
def method_missing(name, *argv, &block) | |
return @attributes[name] if respond_to? name | |
super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment