Skip to content

Instantly share code, notes, and snippets.

@jerry-tao
Created January 29, 2016 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jerry-tao/0b71e2eaac660175107a to your computer and use it in GitHub Desktop.
Save jerry-tao/0b71e2eaac660175107a to your computer and use it in GitHub Desktop.
Service Model
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