Class: Boom::Storage::Gist

Inherits:
Base
  • Object
show all
Defined in:
lib/kaboom/storage/gist.rb

Instance Attribute Summary

Attributes inherited from Base

#lists

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#handle, #initialize, #item_exists?, #items, #list_exists?, #to_hash

Constructor Details

This class inherits a constructor from Boom::Storage::Base

Class Method Details

.sample_configObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/kaboom/storage/gist.rb', line 49

def self.sample_config
  %({
       "backend": "gist",
       "gist": {
         "username": "your_github_username",
         "password": "your_github_password"
       }
     }
   )
end

Instance Method Details

#bootstrapObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kaboom/storage/gist.rb', line 29

def bootstrap
  begin
    require "httparty"

    self.class.send(:include, HTTParty)
    self.class.base_uri "https://api.github.com"
  rescue LoadError
    puts "The Gist backend requires HTTParty: gem install httparty"
    exit
  end

  unless Boom.config.attributes["gist"]
    puts 'A "gist" data structure must be defined in ~/.boom.conf'
    exit
  end

  set_up_auth
  find_or_create_gist
end

#populateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kaboom/storage/gist.rb', line 60

def populate
  @storage['lists'].each do |lists|
    lists.each do |list_name, items|
      @lists << list = List.new(list_name)

      items.each do |item|
        item.each do |name,value|
          list.add_item(Item.new(name,value))
        end
      end
    end
  end
end

#saveObject



74
75
76
# File 'lib/kaboom/storage/gist.rb', line 74

def save
  self.class.post("/gists/#{@gist_id}", request_params)
end