Class: CloudKit::OAuthStore

Inherits:
Object show all
Defined in:
lib/cloudkit/oauth_store.rb

Overview

An OAuthStore is a thin abstraction around CloudKit::Store, providing consistent collection names, and allowing automatic migrations in later releases if needed.

Constant Summary collapse

@@store =
nil

Instance Method Summary collapse

Constructor Details

#initialize(uri = nil) ⇒ OAuthStore

Initialize a Store for use with OAuth middleware. Load the static consumer resource if it does not exist.



11
12
13
14
15
16
17
18
19
20
# File 'lib/cloudkit/oauth_store.rb', line 11

def initialize(uri=nil)
  @@store = Store.new(
    :collections => [
      :cloudkit_oauth_nonces,
      :cloudkit_oauth_tokens,
      :cloudkit_oauth_request_tokens,
      :cloudkit_oauth_consumers],
    :adapter => SQLAdapter.new(uri)) unless @@store
  load_static_consumer
end

Instance Method Details

#delete(uri, options = {}) ⇒ Object

:nodoc:



34
35
36
# File 'lib/cloudkit/oauth_store.rb', line 34

def delete(uri, options={}) #:nodoc:
  @@store.delete(uri, options)
end

#get(uri, options = {}) ⇒ Object

:nodoc:



22
23
24
# File 'lib/cloudkit/oauth_store.rb', line 22

def get(uri, options={}) #:nodoc:
  @@store.get(uri, options)
end

#load_static_consumerObject

Load the static consumer entity if it does not already exist. See the OAuth Discovery spec for more info on static consumers.



47
48
49
50
# File 'lib/cloudkit/oauth_store.rb', line 47

def load_static_consumer
  json = JSON.generate(:secret => '')
  @@store.put('/cloudkit_oauth_consumers/cloudkitconsumer', :json => json)
end

#post(uri, options = {}) ⇒ Object

:nodoc:



26
27
28
# File 'lib/cloudkit/oauth_store.rb', line 26

def post(uri, options={}) #:nodoc:
  @@store.post(uri, options)
end

#put(uri, options = {}) ⇒ Object

:nodoc:



30
31
32
# File 'lib/cloudkit/oauth_store.rb', line 30

def put(uri, options={}) #:nodoc:
  @@store.put(uri, options)
end

#reset!Object

:nodoc:



38
39
40
# File 'lib/cloudkit/oauth_store.rb', line 38

def reset! #:nodoc:
  @@store.reset!
end

#versionObject

Return the version number for this store.



43
# File 'lib/cloudkit/oauth_store.rb', line 43

def version; 1; end