Module: Rapidash::OAuthClient

Defined in:
lib/rapidash/oauth_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



6
7
8
# File 'lib/rapidash/oauth_client.rb', line 6

def access_token
  @access_token
end

#secretObject

Returns the value of attribute secret.



6
7
8
# File 'lib/rapidash/oauth_client.rb', line 6

def secret
  @secret
end

#siteObject

Returns the value of attribute site.



6
7
8
# File 'lib/rapidash/oauth_client.rb', line 6

def site
  @site
end

#uidObject

Returns the value of attribute uid.



6
7
8
# File 'lib/rapidash/oauth_client.rb', line 6

def uid
  @uid
end

Instance Method Details

#access_token_from_code(code, url) ⇒ Object



31
32
33
34
# File 'lib/rapidash/oauth_client.rb', line 31

def access_token_from_code(code, url)
  token = client.auth_code.get_token(code, :redirect_uri => url)
  self.access_token = token.token
end

#initialize(options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rapidash/oauth_client.rb', line 8

def initialize(options)
  [:uid, :secret, :site].each do |key|
    if options[key]
      self.send("#{key.to_s}=".to_sym, options[key])
    else
      unless self.class.respond_to?(key) && send(key)
        raise ConfigurationError.new "Missing #{key} value"
      end
    end
  end

  self.access_token = options[:access_token] if options[:access_token]
end

#request(verb, url, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/rapidash/oauth_client.rb', line 22

def request(verb, url, options = {})
  url = normalize_url(url)
  options[:body] = options[:body].to_json if options[:body]
  options[:raise_errors] = self.class.respond_to?(:raise_error) && self.class.raise_error
  response = oauth_access_token.send(verb.to_sym, "#{site}/#{url}", options)

  response.body
end