Skip to content

Commit 094058e

Browse files
committed
OAuth::Comsumer#options hash is now handled by snaky_hash
- extracted from `oauth2`
1 parent ba94eac commit 094058e

File tree

3 files changed

+47
-42
lines changed

3 files changed

+47
-42
lines changed

lib/oauth.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
# third party gems
4+
require "snaky_hash"
45
require "version_gem"
56

67
require "oauth/version"

lib/oauth/consumer.rb

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,49 @@ class Consumer
3030
end
3131
CA_FILE = nil unless defined?(CA_FILE)
3232

33-
@@default_options = {
34-
# Signature method used by server. Defaults to HMAC-SHA1
35-
signature_method: "HMAC-SHA1",
36-
37-
# default paths on site. These are the same as the defaults set up by the generators
38-
request_token_path: "/oauth/request_token",
39-
authenticate_path: "/oauth/authenticate",
40-
authorize_path: "/oauth/authorize",
41-
access_token_path: "/oauth/access_token",
42-
43-
proxy: nil,
44-
# How do we send the oauth values to the server see
45-
# https://oauth.net/core/1.0/#consumer_req_param for more info
46-
#
47-
# Possible values:
48-
#
49-
# :header - via the Authorize header (Default) ( option 1. in spec)
50-
# :body - url form encoded in body of POST request ( option 2. in spec)
51-
# :query_string - via the query part of the url ( option 3. in spec)
52-
scheme: :header,
53-
54-
# Default http method used for OAuth Token Requests (defaults to :post)
55-
http_method: :post,
56-
57-
# Add a custom ca_file for consumer
58-
# :ca_file => '/etc/certs.pem'
59-
60-
# Possible values:
61-
#
62-
# nil, false - no debug output
63-
# true - uses $stdout
64-
# some_value - uses some_value
65-
debug_output: nil,
66-
67-
# Defaults to producing a body_hash as part of the signature but
68-
# can be disabled since it's not officially part of the OAuth 1.0
69-
# spec. Possible values are true and false
70-
body_hash_enabled: true,
71-
72-
oauth_version: "1.0"
73-
}
33+
@@default_options = SnakyHash::SymbolKeyed.new(
34+
{
35+
# Signature method used by server. Defaults to HMAC-SHA1
36+
signature_method: "HMAC-SHA1",
37+
38+
# default paths on site. These are the same as the defaults set up by the generators
39+
request_token_path: "/oauth/request_token",
40+
authenticate_path: "/oauth/authenticate",
41+
authorize_path: "/oauth/authorize",
42+
access_token_path: "/oauth/access_token",
43+
44+
proxy: nil,
45+
# How do we send the oauth values to the server see
46+
# https://oauth.net/core/1.0/#consumer_req_param for more info
47+
#
48+
# Possible values:
49+
#
50+
# :header - via the Authorize header (Default) ( option 1. in spec)
51+
# :body - url form encoded in body of POST request ( option 2. in spec)
52+
# :query_string - via the query part of the url ( option 3. in spec)
53+
scheme: :header,
54+
55+
# Default http method used for OAuth Token Requests (defaults to :post)
56+
http_method: :post,
57+
58+
# Add a custom ca_file for consumer
59+
# :ca_file => '/etc/certs.pem'
60+
61+
# Possible values:
62+
#
63+
# nil, false - no debug output
64+
# true - uses $stdout
65+
# some_value - uses some_value
66+
debug_output: nil,
67+
68+
# Defaults to producing a body_hash as part of the signature but
69+
# can be disabled since it's not officially part of the OAuth 1.0
70+
# spec. Possible values are true and false
71+
body_hash_enabled: true,
72+
73+
oauth_version: "1.0"
74+
}
75+
)
7476

7577
attr_accessor :options, :key, :secret
7678
attr_writer :site, :http
@@ -103,7 +105,8 @@ def initialize(consumer_key, consumer_secret, options = {})
103105
@secret = consumer_secret
104106

105107
# ensure that keys are symbols
106-
@options = @@default_options.merge(options.transform_keys(&:to_sym))
108+
snaky_options = SnakyHash::SymbolKeyed.new(options)
109+
@options = @@default_options.merge(snaky_options)
107110
end
108111

109112
# The default http method

oauth.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative "lib/oauth/version"
44

55
Gem::Specification.new do |spec|
6+
spec.add_dependency("snaky_hash", "~> 2.0")
67
spec.add_dependency("version_gem", "~> 1.1")
78

89
spec.name = "oauth"

0 commit comments

Comments
 (0)