titobrasolin / Drupal7.Services

.NET API to integrate with Drupal 7 via Services 3 module.
MIT License
7 stars 3 forks source link

ExtensionMethods for all fieldable entities. #8

Closed ibuildit closed 8 years ago

ibuildit commented 8 years ago

I really like the ExtensionMethods, but they don't work with Users. I have created a BaseUser.cs file as a starting point.

namespace Drupal7.Services.BaseClasses
{
public class user_roles
{
    public entity[] und { get; set; }
}
public class user_rdf
{
    public entity[] und { get; set; }
}

public class BaseUser
{
    public user_trading_account field_user_trading_account { get; set; }
    public user_rdf rdf_mapping { get; set; }
    public user_roles roles { get; set; }

    // User ID
    private int _uid;
    public int uid
    {
        get
        {
            return _uid;
        }

        set
        {
            _uid = value;
        }
    }

    // Login
    private string _login;
    public string login
    {
        get
        {
            return _login;
        }

        set
        {
            _login = value;
        }
    }

    // Access
    private string _access;
    public string access
    {
        get
        {
            return _access;
        }

        set
        {
            _access = value;
        }
    }

    // Name
    private string _name;
    public string name
    {
        get
        {
            return _name;
        }

        set
        {
            _name = value;
        }
    }

    // Timezone
    private string _timezone;
    public string timezone
    {
        get
        {
            return _timezone;
        }

        set
        {
            _timezone = value;
        }
    }

    // Created
    private string _created;
    public string created
    {
        get
        {
            return _created;
        }

        set
        {
            _created = value;
        }
    }

    // Status
    private string _status;
    public string status
    {
        get
        {
            return _status;
        }

        set
        {
            _status = value;
        }
    }

    // Language
    private string _language;
    public string language
    {
        get
        {
            return _language;
        }

        set
        {
         _language = value;
        }
    }

    // Mail
    private string _mail;
    public string mail
    {
        get
        {
            return _mail;
        }

        set
        {
            _mail = value;
        }
    }
}   

}

ibuildit commented 8 years ago

Adding a note here that RetrieveNode() uses XmlRpcStruct and RetrieveUseR() uses DrupalUser, which hooks into a lot of other stuff related to the login.

ibuildit commented 8 years ago

I can't work out how to create a ToBaseTerm method in the ExtensionMethods class.

I tried the following:

public static BaseTaxonomyTerm ToBaseTerm(this IDictionary value)
{
return ConvertToType<BaseTaxonomyTerm>(value);
}

For now, it's possible to deserialise Taxonomy Terms this way though:

var ser = new System.Web.Script.Serialization.JavaScriptSerializer();
                WriteLine("Markets: " + ser.Deserialize<BaseTaxonomyTerm>(ser.Serialize(marketTerm)).name);

To be continued..

titobrasolin commented 8 years ago

Hi @ibuildit I have sketched a new project: Drupal7.ServiceModel It contains a few classes that can be used with XML-RPC:

    using Drupal7.ServiceModel.ContentTypes;
    using Drupal7.Services;

    var d7 = new DrupalServices ("http://www.example.net/services/xmlrpc");
    var article = d7.NodeRetrieve (1).ConvertToType<DrupalArticle>();

As well as with REST/JSON:

    using RestSharp;

    var client = new RestClient("http://www.example.net/services/rest");
    var request = new RestRequest("node/1.json");
    var response = client.Execute<DrupalArticle>(request);

The fields have been modelled as dictionaries to support entity translation.