class Stormpath::Client

Attributes

application[R]
data_store[R]

Public Class Methods

new(options) click to toggle source
   # File lib/stormpath-sdk/client.rb
25 def initialize(options)
26   base_url = options[:base_url]
27   cache_opts = options[:cache] || {}
28 
29   api_key = ApiKey(options)
30 
31   assert_not_nil api_key, "No API key has been provided. Please pass an 'api_key' or " \
32                           "'api_key_file_location' to the Stormpath::Client constructor."
33 
34   request_executor = Stormpath::Http::HttpClientRequestExecutor.new(proxy: options[:proxy])
35   @data_store = Stormpath::DataStore.new(request_executor, api_key, cache_opts, self, base_url)
36 end

Public Instance Methods

client() click to toggle source
   # File lib/stormpath-sdk/client.rb
42 def client
43   self
44 end
tenant(expansion = nil) click to toggle source
   # File lib/stormpath-sdk/client.rb
38 def tenant(expansion = nil)
39   tenants.get('current', expansion)
40 end
verify_email_token(token) click to toggle source
   # File lib/stormpath-sdk/client.rb
50 def verify_email_token(token)
51   token_href = "#{href}/emailVerificationTokens/#{token}"
52   token = Stormpath::Resource::EmailVerificationToken.new(token_href, client)
53   data_store.save token, Stormpath::Resource::Account
54 end

Private Instance Methods

ApiKey(options = {}) click to toggle source
   # File lib/stormpath-sdk/client.rb
68 def ApiKey(options = {})
69   if api_key = options[:api_key]
70     case api_key
71     when ApiKey then api_key
72     when Hash then ApiKey.new(api_key[:id], api_key[:secret])
73     end
74   elsif options[:api_key_file_location]
75     load_api_key_file(
76       options[:api_key_file_location],
77       options[:api_key_id_property_name],
78       options[:api_key_secret_property_name]
79     )
80   end
81 end
api_key_warning_message(id_or_secret, api_key_file_location) click to toggle source
    # File lib/stormpath-sdk/client.rb
102 def api_key_warning_message(id_or_secret, api_key_file_location)
103   "No API #{id_or_secret} in properties. Please provide a 'apiKey.#{id_or_secret}' property " \
104     "in '#{api_key_file_location}' or pass in an 'api_key_#{id_or_secret}_property_name' " \
105     'to the Stormpath::Client constructor to specify an alternative property.'
106 end
load_api_key_file(api_key_file_location, id_property_name, secret_property_name) click to toggle source
    # File lib/stormpath-sdk/client.rb
 83 def load_api_key_file(api_key_file_location, id_property_name, secret_property_name)
 84   begin
 85     api_key_properties = JavaProperties::Properties.new(api_key_file_location)
 86   rescue
 87     raise ArgumentError, "No API Key file could be found or loaded from '#{api_key_file_location}'."
 88   end
 89 
 90   id_property_name ||= 'apiKey.id'
 91   secret_property_name ||= 'apiKey.secret'
 92 
 93   api_key_id = api_key_properties[id_property_name]
 94   assert_not_nil api_key_id, api_key_warning_message(:id, api_key_file_location)
 95 
 96   api_key_secret = api_key_properties[secret_property_name]
 97   assert_not_nil api_key_secret, api_key_warning_message(:secret, api_key_file_location)
 98 
 99   ApiKey.new(api_key_id, api_key_secret)
100 end