Class: FreshBooks::OAuthClient
- Inherits:
-
Object
- Object
- FreshBooks::OAuthClient
- Includes:
- Client
- Defined in:
- lib/freshbooks.rb
Overview
OAuth 1.0 client. access token and secret must be obtained elsewhere. cf. the oauth gem
Instance Method Summary collapse
- #auth ⇒ Object
-
#initialize(domain, consumer_key, consumer_secret, token, token_secret) ⇒ OAuthClient
constructor
A new instance of OAuthClient.
- #nonce ⇒ Object
- #signature ⇒ Object
- #timestamp ⇒ Object
Methods included from Client
#api_url, build_xml, #method_missing, new, #post, post, xml_body
Constructor Details
#initialize(domain, consumer_key, consumer_secret, token, token_secret) ⇒ OAuthClient
Returns a new instance of OAuthClient.
182 183 184 185 186 187 188 |
# File 'lib/freshbooks.rb', line 182 def initialize(domain, consumer_key, consumer_secret, token, token_secret) @domain = domain @consumer_key = consumer_key @consumer_secret = consumer_secret @token = token @token_secret = token_secret end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FreshBooks::Client
Instance Method Details
#auth ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/freshbooks.rb', line 190 def auth data = { :realm => '', :oauth_version => '1.0', :oauth_consumer_key => @consumer_key, :oauth_token => @token, :oauth_timestamp => , :oauth_nonce => nonce, :oauth_signature_method => 'PLAINTEXT', :oauth_signature => signature, }.map { |k,v| %Q[#{k}="#{v}"] }.join(',') { 'Authorization' => "OAuth #{data}" } end |
#nonce ⇒ Object
209 210 211 |
# File 'lib/freshbooks.rb', line 209 def nonce [OpenSSL::Random.random_bytes(10)].pack('m').gsub(/\W/, '') end |
#signature ⇒ Object
205 206 207 |
# File 'lib/freshbooks.rb', line 205 def signature CGI.escape("#{@consumer_secret}&#{@token_secret}") end |
#timestamp ⇒ Object
213 214 215 |
# File 'lib/freshbooks.rb', line 213 def Time.now.to_i end |