lib/doggy/model/dash.rb in doggy-0.1.0 vs lib/doggy/model/dash.rb in doggy-0.1.1

- old
+ new

@@ -48,30 +48,38 @@ dash.push dash.save end def raw - @raw ||= Doggy.client.dog.get_dashboard(@id)[1]['dash'].sort.to_h + @raw ||= begin + result = Doggy.client.dog.get_dashboard(@id) + result && result[1]['dash'] && result[1]['dash'].sort.to_h || {} + end end def raw_local return {} unless File.exists?(path) @raw_local ||= Doggy.serializer.load(File.read(path)) end def save - puts raw['errors'] and return if raw['errors'] # do now download an item if it doesn't exist + return if raw['errors'] # do now download an item if it doesn't exist return if raw['title'] =~ Doggy::DOG_SKIP_REGEX + return if raw.empty? File.write(path, Doggy.serializer.dump(raw)) end def push return unless File.exists?(path) return if @title =~ Doggy::DOG_SKIP_REGEX if @id - Doggy.client.dog.update_dashboard(@id, @title, @description, @graphs, @template_variables) + Doggy.with_retry do + Doggy.client.dog.update_dashboard(@id, @title, @description, @graphs, @template_variables) + end else - dash = Doggy.client.dog.create_dashboard(@title, @description, @graphs) + Doggy.with_retry do + dash = Doggy.client.dog.create_dashboard(@title, @description, @graphs) + end # FIXME: Remove duplication @id = dash[1]['id'] @graphs = dash[1]['graphs'] end end