def test_connect(self): return_value = MockResponse() return_value.text = "authentication_url=http%3A%2F%2Fapi.shapeways.com%2Flogin%3Foauth_token=052f70be42a6fe0971d4056eb4492c31115353f3&oauth_token_secret=7e412bef15092d4ed06a529b60d3a8c6925cbcf3&oauth_callback_confirmed=true" with mock.patch.object(requests, "post", return_value=return_value): client = Client( "key", "secret", callback_url="http://localhost:3000/callback" ) url = client.connect() requests.post.assert_called() self.assertEqual( url, "http://api.shapeways.com/login?oauth_token=052f70be42a6fe0971d4056eb4492c31115353f3" ) self.assertEqual( client.oauth_secret, "7e412bef15092d4ed06a529b60d3a8c6925cbcf3" ) args = requests.post.call_args[1] self.assertEqual( args["url"], "https://api.shapeways.com/oauth1/request_token/v1" ) self.assertIsInstance(args["auth"], OAuth1)
def test_connect(self): return_value = MockResponse() return_value.text = "authentication_url=http%3A%2F%2Fapi.shapeways.com%2Flogin%3Foauth_token=052f70be42a6fe0971d4056eb4492c31115353f3&oauth_token_secret=7e412bef15092d4ed06a529b60d3a8c6925cbcf3&oauth_callback_confirmed=true" with mock.patch.object(requests, "post", return_value=return_value): client = Client("key", "secret", callback_url="http://localhost:3000/callback") url = client.connect() requests.post.assert_called() self.assertEqual( url, "http://api.shapeways.com/login?oauth_token=052f70be42a6fe0971d4056eb4492c31115353f3" ) self.assertEqual(client.oauth_secret, "7e412bef15092d4ed06a529b60d3a8c6925cbcf3") args = requests.post.call_args[1] self.assertEqual( args["url"], "https://api.shapeways.com/oauth1/request_token/v1") self.assertIsInstance(args["auth"], OAuth1)
from shapeways.client import Client import keys from urlparse import parse_qs __author__ = 'rob' client = Client(keys.__consumer_key__, keys.__consumer_secret__) url = client.connect() data = parse_qs(url.split('?')[1]) token = data.get("oauth_token", [None])[0] print url verifierCode = raw_input("Verifier Code: ") url = url + "&oauth_verifier=" + verifierCode client.verify_url(url) print 'Token: ' + client.oauth_token print 'Secret: ' + client.oauth_secret
start_response("302 Found", [ ("Location", str(url)), ]) return [""] elif url.startswith("/callback"): client.verify_url(environ["QUERY_STRING"]) start_response("302 Found", [ ("Location", "http://localhost:3000/"), ]) return [""] else: #this is where steps after verification goes response = client.get_api_info() start_response("200 Ok", [ ("Content-Type", "application/json"), ]) return [json.dumps(response)] if __name__ == "__main__": from wsgiref.simple_server import make_server try: httpd = make_server("", 3000, application) print "Tracking Server Listening on Port 3000..." url=client.connect() webbrowser.open(url,new=2) httpd.serve_forever() except KeyboardInterrupt: print "Exiting..."