Skip to content

Commit 7bfcc47

Browse files
author
Paul C Roberts
committed
Initial commit
0 parents  commit 7bfcc47

File tree

1,207 files changed

+57908
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,207 files changed

+57908
-0
lines changed

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Visual studio stuff
2+
*.suo
3+
*.user
4+
5+
#ignore build contents
6+
[dD]ebug/
7+
[rR]elease/
8+
[bB]in/
9+
[oO]bj/
10+
[Ll]ast[Bb]uild.log
11+
12+
# test stuff
13+
[Tt]est[Rr]esult*/
14+
[Bb]uild[Ll]og.*
15+
16+
17+
## vim files
18+
*.un~
19+
*~
20+
21+
## nuget packages
22+
*/[pP]ackages/*/
23+
*.nupkg
24+
25+
## nuget tools
26+
*/.nuget/
27+
28+
##pyc
29+
*.pyc
30+
31+
## files containing keys
32+
*.[Dd]o[Nn]ot[Ss]ync.*
33+
*.pfx
34+
35+
## Stylecop cache
36+
[Ss]tyle[Cc]op.[Cc]ache

Dropbox.Api/ApiException.cs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="ApiException.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api
8+
{
9+
using System;
10+
11+
using Dropbox.Api.Babel;
12+
13+
/// <summary>
14+
/// The exception type that will be raised by an <see cref="ITransport" />
15+
/// implementation if there is an error processing the request.
16+
/// </summary>
17+
/// <typeparam name="TError">The type of the error.</typeparam>
18+
public sealed class ApiException<TError> : Exception, IEncodable<ApiException<TError>>
19+
where TError : IEncodable<TError>, new()
20+
{
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
23+
/// </summary>
24+
/// <remarks>This constructor is only used when deserializing from JSON.</remarks>
25+
public ApiException()
26+
: this(default(TError))
27+
{
28+
}
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
32+
/// </summary>
33+
/// <param name="errorResponse">The error response.</param>
34+
public ApiException(TError errorResponse)
35+
: this(errorResponse, null, null)
36+
{
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
41+
/// </summary>
42+
/// <param name="errorResponse">The error response.</param>
43+
/// <param name="message">The message.</param>
44+
public ApiException(TError errorResponse, string message)
45+
: this(errorResponse, message, null)
46+
{
47+
}
48+
49+
/// <summary>
50+
/// Initializes a new instance of the <see cref="ApiException{TError}"/> class.
51+
/// </summary>
52+
/// <param name="errorResponse">The error response.</param>
53+
/// <param name="message">The message.</param>
54+
/// <param name="inner">The inner.</param>
55+
public ApiException(TError errorResponse, string message, Exception inner)
56+
: base(message, inner)
57+
{
58+
this.ErrorResponse = errorResponse;
59+
}
60+
61+
/// <summary>
62+
/// Gets the error response.
63+
/// </summary>
64+
/// <value>
65+
/// The error response.
66+
/// </value>
67+
public TError ErrorResponse { get; private set; }
68+
69+
/// <summary>
70+
/// Encodes the object using the supplied encoder.
71+
/// </summary>
72+
/// <param name="encoder">The encoder being used to serialize the object.</param>
73+
/// <exception cref="System.NotImplementedException"></exception>
74+
void IEncodable<ApiException<TError>>.Encode(IEncoder encoder)
75+
{
76+
throw new NotSupportedException("Exceptions cannot be encoded");
77+
}
78+
79+
/// <summary>
80+
/// Decodes on object using the supplied decoder.
81+
/// </summary>
82+
/// <param name="decoder">The decoder used to deserialize the object.</param>
83+
/// <returns>
84+
/// The deserialized object. Note: this is not necessarily the current instance.
85+
/// </returns>
86+
/// <exception cref="System.NotImplementedException"></exception>
87+
ApiException<TError> IEncodable<ApiException<TError>>.Decode(IDecoder decoder)
88+
{
89+
using (var obj = decoder.GetObject())
90+
{
91+
this.ErrorResponse = obj.GetFieldObject<TError>("reason");
92+
}
93+
94+
return this;
95+
}
96+
}
97+
}

Dropbox.Api/Babel/Empty.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="Empty.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api.Babel
8+
{
9+
/// <summary>
10+
/// An empty object used when a route doesn't have one or more of the
11+
/// request, response, or error types specified.
12+
/// </summary>
13+
public sealed class Empty : IEncodable<Empty>
14+
{
15+
/// <summary>
16+
/// A static instance of the <see cref="Empty"/> class.
17+
/// </summary>
18+
public static readonly Empty Instance = new Empty();
19+
20+
/// <summary>
21+
/// Encodes the object using the supplied encoder.
22+
/// </summary>
23+
/// <param name="encoder">The encoder being used to serialize the object.</param>
24+
public void Encode(IEncoder encoder)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Decodes on object using the supplied decoder.
30+
/// </summary>
31+
/// <param name="decoder">The decoder used to deserialize the object.</param>
32+
/// <returns>
33+
/// The deserialized object. Note: this is not necessarily the current instance.
34+
/// </returns>
35+
public Empty Decode(IDecoder decoder)
36+
{
37+
return this;
38+
}
39+
}
40+
}

Dropbox.Api/Babel/IDecoder.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="IDecoder.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api.Babel
8+
{
9+
using System;
10+
using System.Collections.Generic;
11+
12+
/// <summary>
13+
/// Interface that is used to decode objects that implement the
14+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface.
15+
/// </summary>
16+
public interface IDecoder
17+
{
18+
/// <summary>
19+
/// Used to get the name of the current union.
20+
/// </summary>
21+
/// <returns>The union name</returns>
22+
string GetUnionName();
23+
24+
/// <summary>
25+
/// Gets a context for the current object, the context object is used to access
26+
/// individual fields.
27+
/// </summary>
28+
/// <returns>The decoder context for the current object.</returns>
29+
IDecoderContext GetObject();
30+
31+
/// <summary>
32+
/// Sets the current source for this instance.
33+
/// </summary>
34+
/// <param name="source">The source as a string.</param>
35+
void SetSource(string source);
36+
37+
/// <summary>
38+
/// Sets the current source for this instance.
39+
/// </summary>
40+
/// <param name="source">The source as a byte array.</param>
41+
void SetSource(byte[] source);
42+
}
43+
44+
/// <summary>
45+
/// A context used to get decoded field values from an encoded object.
46+
/// </summary>
47+
public interface IDecoderContext : IDisposable
48+
{
49+
/// <summary>
50+
/// Indicates whether the specified field is present in the object.
51+
/// </summary>
52+
/// <param name="name">The name of the field to check.</param>
53+
/// <returns><c>true</c> if the field is present; <c>false</c> otherwise.</returns>
54+
bool HasField(string name);
55+
56+
/// <summary>
57+
/// Gets the value of a field.
58+
/// </summary>
59+
/// <typeparam name="T">The expected type of the field.</typeparam>
60+
/// <param name="name">The name of the field to get.</param>
61+
/// <returns>The decoded value of the field.</returns>
62+
T GetField<T>(string name);
63+
64+
/// <summary>
65+
/// Gets the value of a field which is an object.
66+
/// </summary>
67+
/// <typeparam name="T">The expected type of the object. This must implement the
68+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface.</typeparam>
69+
/// <param name="name">The name of the field to get.</param>
70+
/// <returns>The decoded value of the field.</returns>
71+
T GetFieldObject<T>(string name) where T : IEncodable<T>, new();
72+
73+
/// <summary>
74+
/// Gets the value of a field which is a list.
75+
/// </summary>
76+
/// <typeparam name="T">The expected type of the list elements.</typeparam>
77+
/// <param name="name">The name of the field.</param>
78+
/// <returns>The decoded list of items.</returns>
79+
IEnumerable<T> GetFieldList<T>(string name);
80+
81+
/// <summary>
82+
/// Gets the value of a field which is a list of objects that implement
83+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/>.
84+
/// </summary>
85+
/// <typeparam name="T">The expected type of the list elements.</typeparam>
86+
/// <param name="name">The name of the fields.</param>
87+
/// <returns>The decoded list of items.</returns>
88+
IEnumerable<T> GetFieldObjectList<T>(string name) where T : IEncodable<T>, new();
89+
}
90+
}

Dropbox.Api/Babel/IEncodable.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="IEncodable.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api.Babel
8+
{
9+
/// <summary>
10+
/// Interface implemented by all objects generated by the babel API generator.
11+
/// This is used to support transport serialization of objects.
12+
/// </summary>
13+
/// <typeparam name="T">The type of the object to encode.</typeparam>
14+
public interface IEncodable<T>
15+
{
16+
/// <summary>
17+
/// Encodes the object using the supplied encoder.
18+
/// </summary>
19+
/// <param name="encoder">The encoder being used to serialize the object.</param>
20+
void Encode(IEncoder encoder);
21+
22+
/// <summary>
23+
/// Decodes on object using the supplied decoder.
24+
/// </summary>
25+
/// <param name="decoder">The decoder used to deserialize the object.</param>
26+
/// <returns>The deserialized object. Note: this is not necessarily the current instance.</returns>
27+
T Decode(IDecoder decoder);
28+
}
29+
}

Dropbox.Api/Babel/IEncoder.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//-----------------------------------------------------------------------------
2+
// <copyright file="IEncoder.cs" company="Dropbox Inc">
3+
// Copyright (c) Dropbox Inc. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------------
6+
7+
namespace Dropbox.Api.Babel
8+
{
9+
using System;
10+
using System.Collections.Generic;
11+
12+
/// <summary>
13+
/// Interface that is used to encode objects that implement the
14+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface.
15+
/// </summary>
16+
public interface IEncoder
17+
{
18+
/// <summary>
19+
/// Adds an object, returning an encoder context that can be used to
20+
/// add fields to the object.
21+
/// </summary>
22+
/// <returns>The encoder context.</returns>
23+
IEncoderContext AddObject();
24+
25+
/// <summary>
26+
/// Gets the encoded object as a string.
27+
/// </summary>
28+
/// <returns>The string encoding of the object.</returns>
29+
string GetEncodedString();
30+
31+
/// <summary>
32+
/// Gets the encoded object as a byte array.
33+
/// </summary>
34+
/// <returns>The byte array encoding of the object.</returns>
35+
byte[] GetEncodedBytes();
36+
}
37+
38+
/// <summary>
39+
/// A context used to set field values for an encoded object.
40+
/// </summary>
41+
public interface IEncoderContext : IDisposable
42+
{
43+
/// <summary>
44+
/// Adds a field to the current encoding context.
45+
/// </summary>
46+
/// <typeparam name="T">The type of the field that is being added.</typeparam>
47+
/// <param name="name">The field name.</param>
48+
/// <param name="value">The value of the field.</param>
49+
void AddField<T>(string name, T value);
50+
51+
/// <summary>
52+
/// Adds a field that implements the
53+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface to the current
54+
/// encoding context.
55+
/// </summary>
56+
/// <typeparam name="T">The type of the field that is being added.</typeparam>
57+
/// <param name="name">The field name.</param>
58+
/// <param name="value">The value of the field.</param>
59+
void AddFieldObject<T>(string name, T value)
60+
where T : IEncodable<T>, new();
61+
62+
/// <summary>
63+
/// Adds a field that is a list of items.
64+
/// </summary>
65+
/// <typeparam name="T">The element type of each list item.</typeparam>
66+
/// <param name="name">The field name.</param>
67+
/// <param name="value">The value of the field.</param>
68+
void AddFieldList<T>(string name, IEnumerable<T> value);
69+
70+
/// <summary>
71+
/// Adds a field that is a list of objects that implement the
72+
/// <see cref="T:Dropbox.Api.Babel.IEncodable`1"/> interface.
73+
/// </summary>
74+
/// <typeparam name="T">The element type of each list item.</typeparam>
75+
/// <param name="name">The field name.</param>
76+
/// <param name="value">The value of the field.</param>
77+
void AddFieldObjectList<T>(string name, IEnumerable<T> value)
78+
where T : IEncodable<T>, new();
79+
}
80+
}

0 commit comments

Comments
 (0)