Class: GistKV::Client
- Inherits:
-
Object
- Object
- GistKV::Client
- Defined in:
- lib/gistkv.rb
Instance Attribute Summary collapse
-
#read_only ⇒ Object
readonly
Returns the value of attribute read_only.
Class Method Summary collapse
Instance Method Summary collapse
- #get(key) ⇒ Object (also: #[])
-
#initialize(gist_id, auth = nil) ⇒ Client
constructor
A new instance of Client.
- #keys ⇒ Object
- #set(key, value) ⇒ Object (also: #[]=)
- #update(changes) ⇒ Object
Constructor Details
#initialize(gist_id, auth = nil) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 |
# File 'lib/gistkv.rb', line 17 def initialize(gist_id, auth = nil) @gist_id = gist_id @auth = auth @read_only = @auth.nil? headers = GistKV::Client.headers(@auth) @conn = GistKV::Client.conn(headers) end |
Instance Attribute Details
#read_only ⇒ Object (readonly)
Returns the value of attribute read_only.
15 16 17 |
# File 'lib/gistkv.rb', line 15 def read_only @read_only end |
Class Method Details
Instance Method Details
#get(key) ⇒ Object Also known as: []
36 37 38 |
# File 'lib/gistkv.rb', line 36 def get(key) get_gist[key.to_s] end |
#keys ⇒ Object
32 33 34 |
# File 'lib/gistkv.rb', line 32 def keys get_gist.keys end |
#set(key, value) ⇒ Object Also known as: []=
42 43 44 45 46 47 48 |
# File 'lib/gistkv.rb', line 42 def set(key, value) return if @auth.nil? gist = get_gist gist[key.to_s] = value patch_gist(gist) value end |
#update(changes) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/gistkv.rb', line 52 def update(changes) gist = get_gist changes.each {|key,val| gist[key.to_s] = val } patch_gist(gist) changes end |