Using Carbon dates in Laravel/Lumen - laravel-5.1

I am building a webservice based on the latest version of Lumen to use with a Guzzle 6 client. The webservice is working but when I acces a carbon date on the client with:
$newsitem->publish_start->formatLocalized('%A %d %B %Y')
I get the following error:
Call to a member function formatLocalized() on a non-object
In my webservice 'News' model part I have:
protected $dates = [
'publish_start',
'publish_end'
];
If I remove these and access the date with
date('Y/m', strtotime($newsitem->publish_start))
it all works fine.
What am I missing here? How do I get Carbon dates through the webservice? Do I have to activate Carbon manually on Lumen?

You must include the Carbon namespace at the top of your file.
use Carbon\Carbon;

Related

Devops server 2019 - Is there an REST api to add members to project and team

I was looking to add members to Project using REST API.
I was able to create project using API:
POST https://{instance}/{collection}/_apis/projects?api-version=5.0
Also, I was able to create a team in a project using REST API:
POST https://{instance}/{collection}/_apis/projects/{projectId}/teams?api-version=5.0
However, I was not able to get a REST API to add members to team and project.
Can you please help?
Devops server 2019 - Is there an REST api to add members to project
and team
For this issue,I think there is no out of box rest api to achieve it . The Members - Add rest api is currently not available for Azure DevOps Server 2019.
As a workaround ,we can track this rest api by press F12 in browser then select Network.
Sample request url :
https://collectionName/DefaultCollection/projectId/_api/_identity/AddIdentities?__v=5
Sample request body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
In this step ,you need to convert the name of the member you want to add and the name of the team to json, then add to the request body. Here is a case states how to convert a string to JSON in C#.
From this record ,we can get the request url and request body.
I test this with postman and can successfully add a member to a project team.
Here are two cases(case1 , case2) with similar problems. You can also refer to them.
The use voice instance in the above case is no longer available. You could submit a new one to our main forum for product suggestions. Our PM and Product Group are reviewing these suggestion regularly and considering take it as plan.
The REST API to add members to projects and team is not documented. As Hugh mentioned we can track the REST API with develop tools (press F12 in browser), however as we can see we can only use the user and team/group GUID in the request json body.
Post https://wsicads2019/DefaultCollection/{project}/_api/_identity/AddIdentities?api-version=5.0
Request Body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
For the specific team/groups we can use the REST APIs Projects and teams to get their GUID.
For the user, actually it's used the TeamFoundationId, the unique TeamFoundationId is automatically generated when a user is added to Azure DevOps Server. We cannot generate the ID with external tools.
So, to use that REST API, we need to get the TeamFoundationId of the specific user which you want to add it to the projects/teams.
Currently, no REST API to list TeamFoundationId of the users in Azure DevOps Server 2019, however we can get it with Client API:
Below sample for your reference to get the TeamFoundationId of a specific user: (It will also export the user list with their TeamFoundationId to userlist.txt)
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System.Linq;
using System.IO;
namespace Getuserlist
{
class Program
{
static void Main(string[] args)
{
TfsConfigurationServer tcs = new TfsConfigurationServer(new Uri("https://wsicads2019"));
IIdentityManagementService ims = tcs.GetService<IIdentityManagementService>();
TeamFoundationIdentity tfi = ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None);
TeamFoundationIdentity[] ids = ims.ReadIdentities(tfi.Members, MembershipQuery.None, ReadIdentityOptions.None);
using (StreamWriter file = new StreamWriter("userlist.txt"))
foreach (TeamFoundationIdentity id in ids)
{
if (id.Descriptor.IdentityType == "System.Security.Principal.WindowsIdentity" && id.UniqueName == "Domain\\User")
{ Console.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId); }
file.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId);
}
var count = ids.Count(x => ids.Contains(x));
Console.WriteLine(count);
Console.ReadLine();
}
}
}

microsoft graph createreply wrong timezone

In our Angular 5 application, we are using Microsoft Graph to retrieve mail messages from a mailbox and then send a reply. For creating the reply, we use the REST API:
https://graph.microsoft.com/v1.0/me/messages/{message ID}/createReply
This creates a reply with a timezone that is UTC, but we expect it to be GMT+1. For example, in the mail body it says:
From: Melissa van Dijk
Sent: Friday, February 23, 2018 9:51:49 AM (wrong timestamp)
To: Melissa van Dijk
Subject: Meet for lunch?
We checked the settings in our Office 365 mail account and there it is specified that our local timezone is GMT+1 (Brussels, Amsterdam...).
(When replying via Outlook webmail, we get a correct timestamp).
Is this a bug or do we have to correct this timestamp ourselves? Or do we need to pass the timezone with the REST call somehow?
Thanks in advance!
I'm not sure if you can adjust the human-formatted timestamps in the HTML message body, but you can certainly use the ISO 8601 formatted timestamps in the other fields in the JSON of the response. For example, you'll find:
{
...
"sentDateTime": "2018-02-23T09:51:49Z",
...
}
While this is also in UTC (denoted by the Z), you can easily parse it by using a JavaScript Date object, or Angular's own datetime functions, or your favorite time library such as Luxon, Moment, or Date-fns. From there, displaying it in local time is trivial.

Google Calendar API gives 404 while inserting events to calendar after pods updation.

i integrated google calendar in my iOS application, and insert events from application using this Call "
https://www.googleapis.com/calendar/v3/calendars/primary/events "
and events inserted sucessfully in my google calendar
i updated pods due to ios 11 now this api
now it gives this error in response. cant figure it out where the problem is.
ERROR: Invalid value for: Invalid format: \"2017-12-07 07:00:00\" is malformed at \" 07:00:00\
The error prolly is due to wrong time format. Follow the RFC3339 for date time formats. It looks something like:
2015-05-28T09:00:00-07:00
Notice the letter T which stands for full date/full-time.

Issue in generating invoice using Stripe api

I have integrated stripe API in my Rails application. I am facing a problem while getting invoiceitems from the JSON object.
Here i have provide you the details.
OS: CentOS
Ruby: v1.9.3
Rails: v3.0
Stripe: v1.8.3
cus_invoices = Stripe::Invoice.all(:customer=>customer.id, :count=>1).data
cus_invoices.each do |invoices|
invoiceitems = invoices.lines.invoiceitems.each do |lineitems|
Here, the transaction got successful and while returning the stripe ListObject, it throws an error as follows.
CLASS_NAME: NoMethodError
MESSAGE: undefined method invoiceitems' for #<Stripe::ListObject:0xbd9b13c>
TRACE: /usr/local/lib/ruby/gems/1.9.1/gems/stripe-1.8.3/lib/stripe/stripe_object.rb:148:inmethod_missing'
I didn't face this issue previously. Please let me know if any change in JSON object structure.
Kindly provide your support to solve this issue.
Thanks,
Jude
https://stripe.com/docs/api#list_customer_invoices shows the json
invoices.lines.each do |line|
line_item = line.data
line_item.id
line_item.amount
end
You should check your API version (https://stripe.com/docs/api#versioning). If Stripe makes backward incompatible changes, it ups the API version.
Stripe sets the API version based on when you first use the API. So, if you recently got new API keys, it could use a new API version than when you originally started using it.
You can change your API version in your config initializer. Example:
Stripe.api_version = "2013-02-13"

How to get twitter server time?

So I'm trying to build a real time monitoring tool for twitter key words using tweet sharp. I'm using the search API to collect queries every 10-15 seconds. When I make the calls, I only want to collect tweets that have appeared since the pervious update.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = currentResponseDateTime;
My issue is that the twitter server time is different from the client times by a few seconds. I looked around and tried to get the datetime I recieved the response from the Response.ResponseDate property, but it looks like that is set based on the local computer time. I.e currentResponseDateTime is a few seconds ahead of the Twitter Server time. So I end up not collecting a few of the tweets.
Does anyone know how I can get the current server time from twitter search or REST API?
Thanks
I'm not sure how you would get the local server time of the twitter service, but one approach you could take is to store the date of the most recent twitter update seen in the "lastUpdateDateTime" field. That way, you're guaranteed to get all the messages since the last one you saw, regardless of the offset of the twitter server.
var twitter = FluentTwitter.CreateRequest().AuthenticateAs("username", "password").Search().Query().Containing("key word").Take(1000);
var response = twitter.Request();
currentResponseDateTime= Convert.ToDateTime(response.ResponseDate);
var messages = from m in response.AsSearchResult().Statuses
where m.CreatedDate > lastUpdateDateTime
select m;
lastUpdateDateTime = messages.Select(m => m.CreatedDate).Max();
Another approach (and one that Twitter recommends) is to pull the Date header from their API server's response, which provides Twitter's notion of time in GMT. This assumes that you can access the server response headers, and that depends on the method you're using to access the API.
For example, hitting https://api.twitter.com/1/help/test.json
$ lynx --dump --head https://api.twitter.com/1/help/test.json
HTTP/1.0 200 OK
Date: Tue, 22 Jan 2013 13:30:36 GMT
...
Reference: how to get the twitter server time (synchronize)? on dev.twitter.com support site.
Quoting Taylor Singletary:
The current time that Twitter "thinks" it is is returned in the "Date" HTTP header of every response to an API call you make. You can also issue a simple HTTP HEAD request to GET help/test to get the header as an initial syncing step for your app.

Resources