How to get resource identifier from ARN string using AWS SDK? - ruby-on-rails

I have two AWS arns:
arn:aws:elasticloadbalancing:us-east-1:1234567890:app/cmy-app/b473fda15a743462
arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/my-app/1234567890
that I need to return only the targetgroup/my-app/effe001bcbfe98af and app/cmy-app/b473fda15a743462 portion. I've been trying to find a way to retrieve that through the AWS SDK but I've not been able to find the option.
I'm wondering if there is a way to do that with ruby?

You can use the Aws::ARNParser:
str = 'arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/my-app/1234567890'
arn = Aws::ARNParser.parse(str)
#=> #<Aws::ARN:0x00007f9b65d4b748 ...>
arn.resource
#=> "targetgroup/my-app/1234567890"

Related

Setting a device target on google ads API

I'm trying to create a campaign that must target mobile devices only, using the google ads API client library in python. The documentation says that I have to modify the DeviceInfo criteria, but that attribute is immutable.
This is my code rn:
campaign_service = client.get_service("CampaignService")
campaign_criterion_service = client.get_service("CampaignCriterionService")
# Create the campaign criterion.
campaign_criterion_operation = client.get_type("CampaignCriterionOperation")
campaign_criterion = campaign_criterion_operation.create
campaign_criterion.campaign = campaign_service.campaign_path(
customer_id, campaign_id
)
campaign_criterion.device = client.enums.DeviceEnum.MOBILE
What am I missing?
For most of Enums you have to use the .type_ after the value you wanna set.
So you should use:
campaign_criterion.device.type_ = client.enums.DeviceEnum.MOBILE
A nice advice is to download library code and goes into reading that.

How to list all the files that are in TFS GIT repo using REST API

All,
I am trying to get the list of all the files that are in a particular repo in TFS GIT using REST API.
I found the below one but it only display the contents of the specific file name mentioned after "scopePath=/buld.xml", it only display the contents of file build.xml.
But I am trying, only to list all the files that are in a particular repository with out mentioning the particular file name.
Please help me.
https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/items?items?scopePath=/&api-version=4.1
You can use the api below:
https://{accountName}.visualstudio.com/{project}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&api-version=4.1
Also that could be achieved using VisualStudioOnline libs (at the date of writing comment it becomes AzureDevOps): Microsoft.TeamFoundationServer.Client, Microsoft.VisualStudio.Services.Client.
First, you need to create access token. Then just use code below:
VssBasicCredential credintials = new VssBasicCredential(String.Empty, "YOUR SECRET CODE HERE");
VssConnection connection = new VssConnection(new Uri("https://yourserverurl.visualstudio.com/"), credintials);
GitHttpClient client = connection.GetClient<GitHttpClient>();
List<GitRepository> repositories = await client.GetRepositoriesAsync(true); // or use GetRepositoryAsync()
var repo = repositories.FirstOrDefault(r => r.Name == "Some.Repo.Name");
GitVersionDescriptor descriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
Version = "develop",
VersionOptions = GitVersionOptions.None
};
List<GitItem> items = await client.GetItemsAsync(repo.Id, scopePath: "/", recursionLevel: VersionControlRecursionType.Full, versionDescriptor: descriptor);
Under the hood it's using the REST API. So if you try the same effect using c# lang, better delegate it to lib.
You need to call the items endpoint first, which gives you an objectId (the gitObjectType should be "tree"):
http://{tfsURL}/tfs/{collectionId}/{teamProjectId}/_apis/git/repositories/{repositoryId}/items?recursionLevel=Full&api-version=4.1
Then call the trees end point to list the objects in the tree:
http://{tfsURL}/tfs/{collectionId}/{teamProjectId}/_apis/git/repositories/{repositoryId}/trees/{objectId}?api-version=4.1
test

Getting YouTube auto-transcript from API?

Is it possible to pull the auto (non-user) generated video transcripts from any of the YouTube APIs?
As of Aug 2019 the following method you to download transcripts:
Open in Browser
https://www.youtube.com/watch?v=[Video ID]
From Console type:
JSON.parse(ytplayer.config.args.player_response).captions.playerCaptionsTracklistRenderer.captionTracks[0].baseUrl
You may refer with this thread: How to get "transcript" in youtube-api v3
If you're authenticating with oAuth2, you could do a quick call to
this feed:
http://gdata.youtube.com/feeds/api/videos/[VIDEOID]/captiondata/[CAPTIONTRACKID]
to get the data you want. To retrieve a list of possible caption track
IDs with v2 of the API, you access this feed:
https://gdata.youtube.com/feeds/api/videos/[VIDEOID]/captions
That feed request also accepts some optional parameters, including
language, max-results, etc. For more details, along with a sample that
shows the returned format of the caption track list, see the
documentation at
https://developers.google.com/youtube/2.0/developers_guide_protocol_captions#Retrieve_Caption_Set
Also, here are some references which migh help:
https://www.quora.com/Is-there-any-way-to-download-the-YouTube-transcripts-that-are-generated-automatically
http://ccm.net/faq/40644-how-to-get-the-transcript-of-a-youtube-video
1 Install youtube-transcript-api (https://github.com/jdepoix/youtube-transcript-api), e.g.:
pip3 install youtube_transcript_api
2 Create youtube_transcript_api-wrapper.py with the following code (based partially on https://stackoverflow.com/a/65325576/2585501):
from youtube_transcript_api import YouTubeTranscriptApi
#srt = YouTubeTranscriptApi.get_transcript(video_id)
videoListName = "youtubeVideoIDlist.txt"
with open(videoListName) as f:
video_ids = f.read().splitlines()
transcript_list, unretrievable_videos = YouTubeTranscriptApi.get_transcripts(video_ids, continue_after_error=True)
for video_id in video_ids:
if video_id in transcript_list.keys():
print("\nvideo_id = ", video_id)
#print(transcript)
srt = transcript_list.get(video_id)
text_list = []
for i in srt:
text_list.append(i['text'])
text = ' '.join(text_list)
print(text)
3 Create youtubeVideoIDlist.txt containing a list of video_ids
4 python3 youtube_transcript_api-wrapper.py

Adobe DTM - Analytics/Omniture query string missing parameters

I've searched for days looking into this issue but have yet to come up with something. We are migrating our analytics code over to DTM. We are using our own Library hosted at DTM. Everything works great except for some missing data collection parameters in the query string only when using the Adobe Analytics tool to assign variables.
Let me explain. When I use custom code in DTM in a rule to call analytics I get exactly the same query string parameters in the request that we were getting before.
var str = 'string';
s.linkTrackVars = 'prop61,eVar61';
s.linkTrackEvents = 'none';
s.prop61 = str;
s.eVar61 = str;
s.tl(this, 'o', str);
This works fine.
If I try to set eVar61 and prop61 with the Adobe Analytics tool inside a rule, five parameters are no longer in the query string. Specifically 'pev1', 'pid', 'pidt', 'oid' and 'ot'. Is there a way to get DTM to set those parameters or am I just to use custom code for all our rules?
Thanks
Those are clickmap query string parameters. Click on the gear icon to edit the global Analytics tool, and under Link Tracking, make sure 'Enable Clickmap' is checked. Alternatively, you can set s.trackInlineStats=true in your code, which effectively achieves the same effect.
If you ever see missing query string parameters in the future, you can determine what variables to define using the Data Collection Query Parameters in the Marketing Cloud documentation.

How to create QBO BillPayment

I am converting some V2 Desktop code to V3 online. I am having trouble with what was a ReceivePaymentAdd in V2. I looked at the conversion guide and it says to make the ReceivePaymentAdd a BillPayment. I tried but do not see how to add the AR reference and the customer reference. Do I create a Payment object then link the BillPayment somehow?
Here is the C++ V2 code I need to convert to C# V3. Thanks for any help!
CQBXface::ReceivePaymentAdd* pTrx = &QB.m_RecvPmtAdd;
pTrx->CustomerRef.sFullName = customerName;
pTrx->ARAccountRef.sFullName = acctName;
pTrx->DepositToAccountRef.sFullName = depositName;
pTrx->PaymentMethodRef.sFullName = payMethodName;
pTrx->sMemo = memo;
pTrx->sRefNumber = documentNum;
pTrx->sTotalAmount = amount;
pTrx->sTxnDate = transDate;
If the conversion guide really says that a v2 ReceivePayment is equivalent to a v3 BillPayment, then it is incorrect.
But, looking at the migration guide that's not what it says...
A Payment in v2 is equivalent to a Payment in v3. BillPayment is a completely separate and unrelated type of transaction.

Resources