Class: Semantria::Authenticator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer_key, consumer_secret) ⇒ Authenticator

Returns a new instance of Authenticator.



15
16
17
# File 'lib/semantria/auth.rb', line 15

def initialize(consumer_key, consumer_secret)
  @consumer_secret, @consumer_key = consumer_secret, consumer_key
end

Instance Attribute Details

#consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



12
13
14
# File 'lib/semantria/auth.rb', line 12

def consumer_key
  @consumer_key
end

#consumer_secretObject (readonly)

Returns the value of attribute consumer_secret.



12
13
14
# File 'lib/semantria/auth.rb', line 12

def consumer_secret
  @consumer_secret
end

#uriObject

Returns the value of attribute uri.



13
14
15
# File 'lib/semantria/auth.rb', line 13

def uri
  @uri
end

Instance Method Details

#headersObject



19
20
21
# File 'lib/semantria/auth.rb', line 19

def headers
  {'Authorization' => parameters_hash.merge({'OAuth realm' => '', "oauth_signature" => signature}).map { |k, v| "#{k}=#{v}" }.join(',')}
end

#parameters_hashObject



23
24
25
26
27
28
29
# File 'lib/semantria/auth.rb', line 23

def parameters_hash
  { "oauth_version" => '1.0',
    "oauth_timestamp" => timestamp,
    "oauth_nonce" => nonce,
    "oauth_signature_method" => "HMAC-SHA1",
    "oauth_consumer_key" => consumer_key }
end

#pathObject



36
37
38
# File 'lib/semantria/auth.rb', line 36

def path
  updated_uri.request_uri
end

#updated_uriObject



31
32
33
34
# File 'lib/semantria/auth.rb', line 31

def updated_uri
  uri.query = parameters_hash.map {|k, v| "#{k}=#{v}"}.join('&').gsub('+', '%20').gsub('%7E', '~')
  uri
end