Пример #1
0
 public ServiceResult<Item> GetItem(int id)
 {
     GetClient();
     Item i = new Item();
     ServiceResult<Item> r = new ServiceResult<Item>(true, i, "");
     return r;
 }
Пример #2
0
 public ServiceResult<CustomerList> GetCustomers()
 {
     GetClient();
     CustomerList cl = new CustomerList();
     cl.Add(new Customer { id = 1, name="steve" });
     cl.Add(new Customer { id = 2, name = "jane" });
     ServiceResult<CustomerList> r = new ServiceResult<CustomerList>(true,cl,"");
     return r;
 }
Пример #3
0
 public ServiceResult<Customer> GetCustomer(int id)
 {
     GetClient();
     try
     {
         Customer c = new Customer();
         //
         //The real web service call & deserialisation of JSON result to object
         //
         ServiceResult<Customer> r = new ServiceResult<Customer>(true, c, "");
         return r;
     }
     catch (Exception e)
     {
         Customer c = new Customer();
         ServiceResult<Customer> r = new ServiceResult<Customer>(false, c, e.Message);
         return r;
     }
 }
Пример #4
0
        /// <summary>
        /// This function returns every Event associated with an account as an 'EventsResults' and truncates the descriptions to the given length.
        /// </summary>
        /// <returns>EventsResults</returns>
        public ServiceResult<EventsResults> GetEvents(int length)
        {
            try
            {
                GetClient();
                var url = string.Format("{0}/users/{1}/events/?token={2}", _baseURL, _eb_user, _token);
                var result = client.DownloadString(url);
                var tempResults = new ServiceResult<EventsResults>(true, JsonConvert.DeserializeObject<EventsResults>(result), "");
                var finalResults = new EventsResults();

                if (tempResults.Data.Pagination.page_count > 1)
                {
                    for (int i = 0; i < tempResults.Data.Pagination.page_count; i++)
                    {
                        var tUrl = string.Format("{0}/users/{1}/events/?token={2}&page={3}", _baseURL, _eb_user, _token, i + 1);
                        var tResult = client.DownloadString(tUrl);
                        var tResults = new ServiceResult<EventsResults>(true, JsonConvert.DeserializeObject<EventsResults>(result), "");
                        if (finalResults.events == null)
                            finalResults.events = new List<Event>();
                        if (tResults.Data.events != null)
                            finalResults.events.AddRange(tResults.Data.events);
                    }
                }
                else
                    finalResults.events = tempResults.Data.events;
                foreach (Event e in finalResults.events)
                {
                    e.description.text = Truncate(e.description.text, length);
                }
                return new ServiceResult<EventsResults>(true, finalResults, "");
            }
            catch (Exception e)
            {
                GetClient();
                return new ServiceResult<EventsResults>(false, new EventsResults(), e.Message);
            }
        }
Пример #5
0
 /// <summary>
 /// This function returns a single Event, as dictated by the eventId given, and with strings clipped to the specified length.
 /// </summary>
 /// <param name="eventId"></param>
 /// <returns>Event</returns>
 public ServiceResult<Event> GetEvent(string eventId, int length)
 {
     try
     {
         GetClient();
         var url = string.Format("{0}/events/{1}/?token={2}", _baseURL, eventId, _token);
         var result = client.DownloadString(url);
         ServiceResult<Event> events = new ServiceResult<Event>(true, JsonConvert.DeserializeObject<Event>(result), "");
         events.Data.description.text = Truncate(events.Data.description.text, length);
         return events;
     }
     catch (Exception e)
     {
         GetClient();
         return new ServiceResult<Event>(false, new Event(), e.Message);
     }
 }