Class: Thingiverse::Connection
- Inherits:
-
Object
- Object
- Thingiverse::Connection
- Includes:
- HTTParty
- Defined in:
- lib/thingiverse/connection.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
debug_output $stderr.
-
#auth_url ⇒ Object
debug_output $stderr.
-
#base_url ⇒ Object
debug_output $stderr.
-
#client_id ⇒ Object
debug_output $stderr.
-
#client_secret ⇒ Object
debug_output $stderr.
-
#code ⇒ Object
debug_output $stderr.
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(client_id = nil, client_secret = nil, code = nil) ⇒ Connection
constructor
A new instance of Connection.
- #things ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(client_id = nil, client_secret = nil, code = nil) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 |
# File 'lib/thingiverse/connection.rb', line 7 def initialize(client_id = nil, client_secret = nil, code = nil) @client_id = client_id @client_secret = client_secret @code = code self.class.base_uri(self.base_url) self.get_token if @client_id and @client_secret and @code end |
Instance Attribute Details
#access_token ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def access_token @access_token end |
#auth_url ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def auth_url @auth_url end |
#base_url ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def base_url @base_url end |
#client_id ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def client_secret @client_secret end |
#code ⇒ Object
debug_output $stderr
5 6 7 |
# File 'lib/thingiverse/connection.rb', line 5 def code @code end |
Instance Method Details
#get_token ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/thingiverse/connection.rb', line 35 def get_token auth_response = self.class.post(@auth_url, :query => {:client_id => @client_id, :client_secret => @client_secret, :code => @code}) raise "#{auth_response.code}: #{auth_response.body.inspect}" unless auth_response.success? response = CGI::parse(auth_response.parsed_response) @access_token = response['access_token'].to_s self.class.headers "Authorization" => "Bearer #{@access_token}" @access_token end |
#things ⇒ Object
49 50 51 |
# File 'lib/thingiverse/connection.rb', line 49 def things Thingiverse::Things end |
#users ⇒ Object
53 54 55 |
# File 'lib/thingiverse/connection.rb', line 53 def users Thingiverse::Users end |