Class: ContextIO::OAuthProvider

Inherits:
Resource
  • Object
show all
Defined in:
lib/context-io/oauth_provider.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

#delete, #get, #post, #put, #request

Instance Attribute Details

#consumer_keyString (readonly)

Returns The OAuth consumer key.

Returns:

  • (String)

    The OAuth consumer key.



10
11
12
# File 'lib/context-io/oauth_provider.rb', line 10

def consumer_key
  @consumer_key
end

#consumer_secretString (readonly)

Returns The OAuth consumer secret.

Returns:

  • (String)

    The OAuth consumer secret.



14
15
16
# File 'lib/context-io/oauth_provider.rb', line 14

def consumer_secret
  @consumer_secret
end

#typeString (readonly)

Returns The identification of the OAuth provider. This must be either “GMAIL” or “GOOGLEAPPSMARKETPLACE”.

Returns:

  • (String)

    The identification of the OAuth provider. This must be either “GMAIL” or “GOOGLEAPPSMARKETPLACE”.



6
7
8
# File 'lib/context-io/oauth_provider.rb', line 6

def type
  @type
end

Class Method Details

.allArray<ContextIO::OAuthProvider>

Get all OAuth providers configured

Returns:



21
22
23
# File 'lib/context-io/oauth_provider.rb', line 21

def self.all
  get('/2.0/oauth_providers').map { |provider| from_json(provider) }
end

.create(type, consumer_key, consumer_secret) ⇒ true, false

Create an OAuth provider

Parameters:

  • type ('GMAIL', 'GOOGLEAPPSMARKETPLACE', :gmail, :googleappsmarketplace)

    The identification of the OAuth provider.

  • consumer_key (#to_s)

    The OAuth consumer key.

  • consumer_secret (#to_s)

    The OAuth consumer secret.

Returns:

  • (true, false)

    Whether the create succeeded or not.



35
36
37
38
39
40
41
# File 'lib/context-io/oauth_provider.rb', line 35

def self.create(type, consumer_key, consumer_secret)
  post('/2.0/oauth_providers', {
    :type => type.to_s.upcase,
    :provider_consumer_key => consumer_key.to_s,
    :provider_consumer_secret => consumer_secret.to_s
  })['success']
end

.find(consumer_key) ⇒ ContextIO::OAuthProvider

Retrieve an OAuth provider

Parameters:

  • consumer_key (#to_s)

    The OAuth consumer key.

Returns:



50
51
52
# File 'lib/context-io/oauth_provider.rb', line 50

def self.find(consumer_key)
  from_json(get("/2.0/oauth_providers/#{consumer_key}"))
end

.from_json(json) ⇒ ContextIO::OAuthProvider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create an OAuth provider with the JSON data from Context.IO.

Parameters:

  • json (Hash)

    The parsed JSON object returned by a Context.IO API request. See their documentation for possible keys.

Returns:



72
73
74
75
76
77
78
79
80
81
# File 'lib/context-io/oauth_provider.rb', line 72

def self.from_json(json)
  provider = new
  provider.instance_eval do
    @type = json['type']
    @consumer_key = json['provider_consumer_key']
    @consumer_secret = json['provider_consumer_secret']
  end

  provider
end

Instance Method Details

#destroytrue, false

Destroy the OAuth provider

Returns:

  • (true, false)

    Whether the destroy was successful or not.



59
60
61
# File 'lib/context-io/oauth_provider.rb', line 59

def destroy
  delete("/2.0/oauth_providers/#@consumer_key")['success']
end