Class: FellowshipOne::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/fellowship_one.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_secretObject (readonly)

Returns the value of attribute api_secret.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def api_secret
  @api_secret
end

.api_tokenObject (readonly)

Returns the value of attribute api_token.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def api_token
  @api_token
end

.church_codeObject (readonly)

Returns the value of attribute church_code.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def church_code
  @church_code
end

.consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def consumer_key
  @consumer_key
end

.consumer_secretObject (readonly)

Returns the value of attribute consumer_secret.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def consumer_secret
  @consumer_secret
end

.is_productionObject (readonly)

Returns the value of attribute is_production.



21
22
23
# File 'lib/fellowship_one.rb', line 21

def is_production
  @is_production
end

Class Method Details

.connect(church_code, consumer_key, consumer_secret, oauth_token, oauth_secret, production = true) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/fellowship_one.rb', line 42

def self.connect(church_code, consumer_key, consumer_secret, oauth_token, oauth_secret, production = true)
  raise FellowshipOneExceptions::UnableToConnectToFellowshipOne.new('Church Code, Token and Secret cannot be nil.') if oauth_token.nil? or oauth_secret.nil?
  @church_code = church_code
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret      
  @api_token = oauth_token
  @api_secret = oauth_secret
  @is_production = production
end

.establish_connection(church_code, consumer_key, consumer_secret, callback_url, production = true) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fellowship_one.rb', line 24

def self.establish_connection(church_code, consumer_key, consumer_secret, callback_url, production = true)
  if church_code.nil? or consumer_key.nil? or consumer_secret.nil?
    raise FellowshipOneExceptions::UnableToConnectToFellowshipOne.new('Church code, Consumer Key and Consumer Secret cannot be nil.') 
  end

  consumer_env = production ? '' : '.staging' # Yes, blank is production

  puts "F1 URL: https://#{church_code}#{consumer_env}.fellowshiponeapi.com"

  consumer = OAuth::Consumer.new(consumer_key, consumer_secret, 
                                 :site => "https://#{church_code}#{consumer_env}.fellowshiponeapi.com",
                                 :request_token_path => '/v1/Tokens/RequestToken', 
                                 :authorize_path     => '/v1/PortalUser/Login',
                                 :access_token_path  => '/v1/Tokens/AccessToken')

  consumer.get_request_token(:oauth_callback => callback_url)
end