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 upgrades in later releases if needed.

Constant Summary collapse

@@store =
nil

Instance Method Summary collapse

Constructor Details

#initializeOAuthStore

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
  @@store = Store.new(
    :collections => [
      :cloudkit_oauth_nonces,
      :cloudkit_oauth_tokens,
      :cloudkit_oauth_request_tokens,
      :cloudkit_oauth_consumers]
    ) 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(CloudKit::URI.new(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(CloudKit::URI.new(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.



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

def load_static_consumer
  json = JSON.generate(:secret => '')
  @@store.put(CloudKit::URI.new('/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(CloudKit::URI.new(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(CloudKit::URI.new(uri), options)
end

#versionObject

Return the version number for this store.



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

def version; 1; end