Class: MageHand::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_request_token = nil, session_access_token_key = nil, session_access_token_secret = nil, callback = nil, params = nil) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ob_port/client.rb', line 16

def initialize(session_request_token=nil, session_access_token_key=nil, session_access_token_secret=nil,
    callback=nil, params=nil)
  @request_token = session_request_token
  @access_token_key = session_access_token_key
  @access_token_secret = session_access_token_secret
    
  if !logged_in? && params && params[:oauth_verifier]
    temp_token = @request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
    @access_token_key = temp_token.token
    @access_token_secret = temp_token.secret          
  elsif !logged_in?
    @request_token = consumer.get_request_token(:oauth_callback => callback)
  end
end

Instance Attribute Details

#access_token_keyObject

Returns the value of attribute access_token_key.



3
4
5
# File 'lib/ob_port/client.rb', line 3

def access_token_key
  @access_token_key
end

#access_token_secretObject

Returns the value of attribute access_token_secret.



3
4
5
# File 'lib/ob_port/client.rb', line 3

def access_token_secret
  @access_token_secret
end

#request_tokenObject

Returns the value of attribute request_token.



3
4
5
# File 'lib/ob_port/client.rb', line 3

def request_token
  @request_token
end

Class Method Details

.get_client(session_request_token = nil, session_access_token_key = nil, session_access_token_secret = nil, callback = nil, params = nil) ⇒ Object



10
11
12
13
14
# File 'lib/ob_port/client.rb', line 10

def self.get_client(session_request_token=nil, session_access_token_key=nil, session_access_token_secret=nil,
    callback=nil, params=nil)
    Client.new(session_request_token, session_access_token_key, session_access_token_secret,
      callback, params)
end

.set_app_keys(key, secret) ⇒ Object



5
6
7
8
# File 'lib/ob_port/client.rb', line 5

def self.set_app_keys(key, secret)
  @@key = key
  @@secret = secret
end

Instance Method Details

#access_tokenObject



45
46
47
48
# File 'lib/ob_port/client.rb', line 45

def access_token
  return nil unless logged_in?
  @access_token ||= OAuth::AccessToken.new(consumer, access_token_key, access_token_secret)          
end

#campaign(id) ⇒ Object



55
56
57
# File 'lib/ob_port/client.rb', line 55

def campaign(id)
  MageHand::Campaign.new(self, JSON.parse(access_token.get("/v1/campaigns/#{id}.json").body))
end

#consumerObject



35
36
37
38
39
40
41
42
43
# File 'lib/ob_port/client.rb', line 35

def consumer
  raise(OAuthConfigurationError, "Need to set application key and secret before initializing a consumer.") unless
    @@key && @@secret
  @consumer ||= OAuth::Consumer.new( @@key, @@secret, {
    :site => 'http://api.obsidianportal.com',
    :request_token_url => 'https://www.obsidianportal.com/oauth/request_token',
    :authorize_url => 'https://www.obsidianportal.com/oauth/authorize',
    :access_token_url => 'https://www.obsidianportal.com/oauth/access_token'})
end

#create_wiki_page(options) ⇒ Object



59
60
61
# File 'lib/ob_port/client.rb', line 59

def create_wiki_page(options)
  MageHand::WikiPage.new(self, options)
end

#current_userObject Also known as: me



50
51
52
# File 'lib/ob_port/client.rb', line 50

def current_user
  @current_user ||= OPUser.new(self, JSON.parse(access_token.get('/v1/users/me.json').body))
end

#logged_in?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ob_port/client.rb', line 31

def logged_in?
  !!access_token_secret && !!access_token_key
end