lib/doggy/model/screen.rb in doggy-0.1.0 vs lib/doggy/model/screen.rb in doggy-0.1.1
- old
+ new
@@ -35,29 +35,37 @@
item.push
item.save
end
def raw
- @raw ||= Doggy.client.dog.get_screenboard(@id)[1].sort.to_h
+ @raw ||= begin
+ result = Doggy.client.dog.get_screenboard(@id)
+ result && result[1] && result[1].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['board_title'] =~ Doggy::DOG_SKIP_REGEX
+ return if raw.empty?
File.write(path, Doggy.serializer.dump(raw))
end
def push
return if @description =~ Doggy::DOG_SKIP_REGEX
if @id
- Doggy.client.dog.update_screenboard(@id, @description)
+ Doggy.with_retry do
+ Doggy.client.dog.update_screenboard(@id, @description)
+ end
else
- result = Doggy.client.dog.create_screenboard(@description)
+ Doggy.with_retry do
+ result = Doggy.client.dog.create_screenboard(@description)
+ end
@id = result[1]['id']
@description = result[1]
end
end