Module: DiasporaClient
- Defined in:
- lib/diaspora-client.rb,
lib/diaspora-client/app.rb,
lib/diaspora-client/railtie.rb,
lib/diaspora-client/access_token.rb,
lib/diaspora-client/resource_server.rb
Defined Under Namespace
Classes: AccessToken, App, Railtie, RegistrationError, ResourceServer
Constant Summary
- PROFILE =
"profile"- PHOTOS =
"photos"- READ =
"read"- WRITE =
"write"
Class Method Summary (collapse)
-
+ (Addressable::URI) application_base_url
Normalizes and adds a scheme and port to @application_base_url.
-
+ (void) config(&block)
Calls DiasporaClient.initialize_instance_variables and yields to a given (optional) config block.
-
+ (Hash) generate_manifest
Generates the manifest content used in DiasporaClient.package_manifest.
-
+ (void) getter(*fields)
Sets getter field(s) for the module.
-
+ (void) initialize_instance_variables
Initilizes public & private keys, permissions and manifest fields.
-
+ (void) manifest_field(field, value)
Defines a field to be placed in the application's manifest.
-
+ (String) package_manifest
Generates a manifest of the form => key, :jwt => jwt.
-
+ (void) permission(type, access, description)
Defines the permissions the applicaiton is attempting to access.
-
+ (OpenSSL::PKey::RSA) private_key
Retreive the application's private key.
-
+ (String) public_key
Retreive the application's public key.
-
+ (String) scheme
Application's current protocol (http/https).
-
+ (void) set_test_defaults
Sets default config values for testing.
-
+ (void) setter(*fields)
Sets setter field(s) for the module.
-
+ (void) setup_faraday
Configures Faraday for JSON requests.
-
+ (String) sign(plaintext)
A SHA256 signature of the passed in plaintext with the DiasporaClient.private_key.
-
+ (Symbol) which_faraday_adapter?
Returns either :em_synchrony or :net_http for Faraday according to if the application is running in an EventMachine reactor loop.
Class Method Details
+ (Addressable::URI) application_base_url
Normalizes and adds a scheme and port to @application_base_url.
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/diaspora-client.rb', line 137 def self.application_base_url if @application_base_url.match(/^localhost:\d+/) @application_base_url = DiasporaClient.scheme + "://" + @application_base_url end host = Addressable::URI.heuristic_parse(@application_base_url) host.scheme = self.scheme host.port ||= host.inferred_port host.path = '/' if host.path.blank? host end |
+ (void) config(&block)
This method returns an undefined value.
Calls initialize_instance_variables and yields to a given (optional) config block.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/diaspora-client.rb', line 73 def self.config(&block) self.initialize_instance_variables if block_given? block.call(self) end if @test_mode self.set_test_defaults end end |
+ (Hash) generate_manifest
Generates the manifest content used in package_manifest.
201 202 203 204 |
# File 'lib/diaspora-client.rb', line 201 def self.generate_manifest @manifest_fields.merge(:permissions => @permissions, :application_base_url => self.application_base_url.to_s) end |
+ (void) getter(*fields)
This method returns an undefined value.
Sets getter field(s) for the module.
34 35 36 37 38 |
# File 'lib/diaspora-client.rb', line 34 def self.getter(*fields) fields.each do |f| eval("def self.#{f} ; @#{f} ; end") end end |
+ (void) initialize_instance_variables
This method returns an undefined value.
Initilizes public & private keys, permissions and manifest fields.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/diaspora-client.rb', line 152 def self.initialize_instance_variables app_name = (defined?(Rails)) ? "#{Rails.application.class.parent_name}." : "" app_root = (defined?(Rails)) ? "#{Rails.root}" : "" @permissions = {} @manifest_fields = {} @private_key_path = "#{app_root}/config/#{app_name}private.pem" @private_key = nil @public_key_path = "#{app_root}/config/#{app_name}public.pem" @public_key = nil @test_mode = false @faraday_initialized = nil end |
+ (void) manifest_field(field, value)
This method returns an undefined value.
Defines a field to be placed in the application's manifest.
179 180 181 182 |
# File 'lib/diaspora-client.rb', line 179 def self.manifest_field(field, value) @manifest_fields[field] = value nil end |
+ (String) package_manifest
Generates a manifest of the form => key, :jwt => jwt
209 210 211 212 |
# File 'lib/diaspora-client.rb', line 209 def self.package_manifest JSON.generate({:public_key => self.public_key, :jwt => JWT.encode(self.generate_manifest, self.private_key, "RS512")}) end |
+ (void) permission(type, access, description)
This method returns an undefined value.
Defines the permissions the applicaiton is attempting to access.
193 194 195 196 197 |
# File 'lib/diaspora-client.rb', line 193 def self.(type, access, description) @permissions[type] = {:type => "DiasporaClient::#{type.to_s.upcase}".constantize, :access => "DiasporaClient::#{access.to_s.upcase}".constantize, :description => description} end |
+ (OpenSSL::PKey::RSA) private_key
Retreive the application's private key.
103 104 105 |
# File 'lib/diaspora-client.rb', line 103 def self.private_key @private_key ||= OpenSSL::PKey::RSA.new(File.read(@private_key_path)) end |
+ (String) public_key
Retreive the application's public key.
96 97 98 |
# File 'lib/diaspora-client.rb', line 96 def self.public_key @public_key ||= File.read(@public_key_path) end |
+ (String) scheme
Application's current protocol (http/https). The test_mode configuration flag will turn SSL off.
89 90 91 |
# File 'lib/diaspora-client.rb', line 89 def self.scheme @test_mode ? 'http' : 'https' end |
+ (void) set_test_defaults
This method returns an undefined value.
Sets default config values for testing
216 217 218 |
# File 'lib/diaspora-client.rb', line 216 def self.set_test_defaults @application_base_url ||= "example.com" end |
+ (void) setter(*fields)
This method returns an undefined value.
Sets setter field(s) for the module.
24 25 26 27 28 |
# File 'lib/diaspora-client.rb', line 24 def self.setter(*fields) fields.each do |f| eval("def self.#{f}=(val) ; @#{f} = val ; end") end end |
+ (void) setup_faraday
This method returns an undefined value.
Configures Faraday for JSON requests.
127 128 129 130 131 132 |
# File 'lib/diaspora-client.rb', line 127 def self.setup_faraday @faraday_initialized ||= Faraday.default_connection = Faraday::Connection.new do |builder| builder.use Faraday::Request::JSON builder.adapter self.which_faraday_adapter? end end |
+ (String) sign(plaintext)
A SHA256 signature of the passed in plaintext with the private_key
108 109 110 |
# File 'lib/diaspora-client.rb', line 108 def self.sign(plaintext) self.private_key.sign(OpenSSL::Digest::SHA256.new, plaintext) end |
+ (Symbol) which_faraday_adapter?
Returns either :em_synchrony or :net_http for Faraday according to if the application is running in an EventMachine reactor loop.
116 117 118 119 120 121 122 |
# File 'lib/diaspora-client.rb', line 116 def self.which_faraday_adapter? if(defined?(EM::Synchrony) && EM.reactor_running?) :em_synchrony else :net_http end end |