public async Task OAuth() { // authenticate OAuth.OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(ForgeClientID, ForgeClientSecret, new Scope[] { Scope.BucketRead, Scope.BucketCreate, Scope.DataRead, Scope.DataCreate, Scope.DataWrite }); Assert.IsFalse(string.IsNullOrWhiteSpace(oauth.AccessToken), "Access token not as expected"); Assert.IsTrue(oauth.ExpiresAt > DateTime.Now); }
/// <summary> /// Call the specified endPoint with the [Authorization: Beader TOKEN] heander /// </summary> internal static async Task <IRestResponse> MakeAuthorizedRequestAsync(OAuth.OAuth oauth, string endPoint, RestSharp.Method method, Dictionary <string, string> headers = null, Dictionary <string, string> bodyParameters = null, object dataBody = null, string file = null) { if (headers == null) { headers = new Dictionary <string, string>(); } headers.Add("Authorization", "Bearer " + oauth.AccessToken); return(await MakeRequestAsync(endPoint, method, headers, bodyParameters, dataBody, file)); }
public async Task BucketWorkflow() { string testFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestFile\Analyze.dwf"); Assert.IsTrue(File.Exists(testFile), "Test file not found"); // authenticate OAuth.OAuth oauth = await OAuth2LeggedToken.AuthenticateAsync(ForgeClientID, ForgeClientSecret, new Scope[] { Scope.BucketRead, Scope.BucketCreate, Scope.DataRead, Scope.DataCreate, Scope.DataWrite }); Assert.IsFalse(string.IsNullOrWhiteSpace(oauth.AccessToken), "Access token not as expected"); // create bucket and get list of buckets in different conditions AppBuckets buckets = new AppBuckets(oauth); IEnumerable <Bucket> listOfBuckets = await buckets.GetBucketsAsync(10); buckets = new AppBuckets(oauth); await buckets.GetBucketsAsync(120); buckets = new AppBuckets(oauth); await buckets.GetBucketsAsync(210); // create a random bucket string bucketKey = string.Format("test{0}", DateTime.Now.ToString("yyyyMMddHHmmss")); Assert.IsTrue(BucketDetails.IsValidBucketKey(bucketKey)); Bucket bucket = await buckets.CreateBucketAsync(bucketKey, PolicyKey.Transient); Assert.AreEqual(bucket.BucketKey, bucketKey); // get all objects IEnumerable <OSS.Object> objects = await bucket.GetObjectsAsync(int.MaxValue); // upload new object OSS.Object newObject = await bucket.UploadObjectAsync(testFile); // the list after should have 1 object... IEnumerable <OSS.Object> objectsAfter = await bucket.GetObjectsAsync(int.MaxValue); foreach (OSS.Object obj in objectsAfter) { Assert.AreEqual(newObject.ObjectId, obj.ObjectId); // URNs should be the same } // as there is just 1 object, bucket and object have the same size Assert.AreEqual(await bucket.Size(), newObject.Size, "Bucket size and object size don't match"); // translate HttpStatusCode res = await newObject.Translate(new SVFOutput[] { SVFOutput.Views3d, SVFOutput.Views2d }); Assert.AreEqual(res, HttpStatusCode.OK, "Translate job posted"); }
/// <summary> /// Requires bucket:read scope /// </summary> /// <param name="oauth"></param> /// <param name="bucketKey"></param> /// <returns></returns> public async static Task <BucketDetails> InitializeAsync(OAuth.OAuth oauth, string bucketKey) { if (!IsValidBucketKey(bucketKey)) { throw new Exception("BucketKey not valid: Possible values: -_.a-z0-9 (between 3-128 characters in length)"); } IRestResponse res = await REST.MakeAuthorizedRequestAsync(oauth, string.Format(END_POINTS.GET_BUCKET_DETAILS, bucketKey), RestSharp.Method.GET); if (res.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(string.Format("Endpoint {0} at BucketDetails.InitializeAsync returned {1}", Internal.END_POINTS.GET_BUCKET_DETAILS, res.StatusCode)); } BucketDetails bucket = new OSS.BucketDetails(oauth); JsonConvert.PopulateObject(res.Content, bucket); return(bucket); }
public AppBuckets(OAuth.OAuth oauth) : base(oauth) { }
internal BucketDetails(OAuth.OAuth oauth) : base(oauth) { }
/// <summary> /// Instantiate a skeleton object, consider using BucketDetails.InitializeAsync before accessing any property. /// </summary> /// <param name="oauth"></param> /// <param name="bucketKey"></param> public Bucket(OAuth.OAuth oauth, BucketKey bucketKey) : base(oauth) { this.BucketKey = bucketKey; }
protected Bucket(OAuth.OAuth oauth) : base(oauth) { }
protected ApiObject(OAuth.OAuth auth) { Authorization = auth; }
/// <summary> /// Instantiate a skeleton object, consider using BucketDetails.InitializeAsync before accessing any property. /// </summary> /// <param name="auth"></param> /// <param name="objectKey"></param> public Object(OAuth.OAuth auth, BucketKey bucketKey, ObjectId objectId) : base(auth) { BucketKey = bucketKey; ObjectId = objectId; }