Getting the index of a specif element in a complex list in flutter - flutter

I have a list of this structure List messages = [ [{body: QGB59WIO57 Confirmed. Your account balance was: M-PESA Account : Ksh0.00 on 11/7/22 at 12:42 PM. Transaction cost, Ksh0.00. Dial *334# now to get your stamped M-Pesa Statement., address: MPESA, timestamp: 1657532523000, status: failed}],
I/flutter ( 4659): [{body: QGB7A3UGAX Confirmed. Your account balance was: M-PESA Account : Ksh0.00 on 11/7/22 at 2:18 PM. Transaction cost, Ksh0.00. Dial *334# now to get your stamped M-Pesa Statement., address: MPESA, timestamp: 1657538312000, status: failed}] ]
I want to get the index of where timestamp is equal to 1657538312000 in this case the ondex of the second element of the list

I didn't fully get the structure but you should be able to do seomthing like
var index = messages.indexOf(messages.firstWhere((element) => /*your check here*/ ));

Related

Soundcloud trackID by track URL address

I would like to add soundcloud widget to my app.
for that, I need to send parameters on the iframe src.
The problem is that soundcloud demands for TrackID rather than the URL address of the track, and my users won't be able to find this trackID on Soundcloud's UI.
How can I resolve TrackID by track URL address?
If it's possible only by using the API - then how can I register as a new app? It seems impossible now. Also what API call would I need to make to resolve this info?
Thank you.
Unfortunately, the SoundCloud API is indefinitely not accepting new registrations. Like the comment above, an easy alternative solution is if you use this URL, it will provide you with a wide/short player:
https://w.soundcloud.com/player/?url= + URL of track
Example: https://w.soundcloud.com/player/?url=https://soundcloud.com/chrisbjerken/you-still-have-my-heart
This works for both a single track or a playlist.
Like you I needed to fetch some track informations from a soundcloud url, however the use of the API can't be an option from my side (API closed since 2017). This is what I came up with to get the track ID.
<?php
// url test example
$url = "https://soundcloud.com/the-bugle/bugle-179-playas-gon-play";
// this link give some infos of the track
$infos_music_soundcloud = 'https://soundcloud.com/oembed?url='.urlencode($url).'&format=json';
$page_content = file_get_contents($infos_music_soundcloud);
if(!empty($page_content)){
$content = json_decode($page_content);
// now, the track ID is in the html iframe code. Lets get it.
$matches = array();
preg_match('/tracks%2F(.*?)&/s', $content->{'html'}, $matches);
echo "the track id is ".$matches[1];
}else{
echo "the track don't seems to exists. Please verify the link";
}
?>
You can get also track title, description, thumbnail, author name/url...
Hope it helps ;)
edit -
if the track is private, just make sure you give the private link (ie. with something like "/s-clUrZ" at the end)
Soundcloud has an API that can be invoked in order to resolve an URL.
If you have a valid client_id you can perform a GET request setting the url and your client_id as parameters.
https://api.soundcloud.com/resolve.json?url=https://soundcloud.com/tomer-maizner/forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner&client_id=CLIENT_ID
This will give you this response:
{
kind: "track",
id: 460976748,
created_at: "2018/06/20 16:25:14 +0000",
user_id: 8504856,
duration: 3570385,
commentable: true,
state: "finished",
original_content_size: 142800123,
last_modified: "2018/06/23 15:26:59 +0000",
sharing: "public",
tag_list: ""forever tel aviv" circuit "we party" mix pride "tel aviv"",
permalink: "forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner",
streamable: true,
embeddable_by: "all",
purchase_url: null,
purchase_title: null,
label_id: null,
genre: "Electronic",
title: "Forever Tel-Aviv - Pride 2018 Anthems (Mixed By Tomer Maizner)",
description: "The best of the best from the pride weekend in Tel-Aviv including tracks from all Forever Tel-Aviv superstars . Sagi Kariv / Tomer Maizner / Yinon Yahel / Tommer Mizrahi / Mor Avrahami / Elad Navon / Micky Friedman Enjoy!!! Tracklist : 1. Tomer Maizner Feat. Madame Meyhem - Unbreak My Heart 2018 2. N-Trance - Set You Free (Sagi Kariv remix) 3. Maître Gims – Mi Gna (Tommer Mizrahi Remix) 4. Micky Friedman - Eshebo feat Hila Ben Saadon (Original Mix) 5. Edson Pride - Freedom (Tomer Maizner Stanga Mash) 6. Netta - Toy (Sagi Kariv extended remix) 7. Arian Grande - No Tears Left To Cry Remix (DJ Aron Remix) 8. Steven Redant - Sunshine On My Shoulders (Tommer Mizrahi Remix) 9. Mor Avrahami - Kumei (Original Mix) 10 . Sissy That B.Y.O.B (Tomer Maizner Mashup) 11. Louie Vega - Diamond Life (Elad Navon & Niv Aroya Remix) 12. Hanna Hais - Je Ne Veux Plus Etre Ta Reine (Ranz Remix) 13. I Am Free (Yinon Yahel Remix)",
label_name: null,
release: null,
track_type: null,
key_signature: null,
isrc: null,
video_url: null,
bpm: null,
release_year: null,
release_month: null,
release_day: null,
original_format: "mp3",
license: "all-rights-reserved",
uri: "https://api.soundcloud.com/tracks/460976748",
user: {
id: 8504856,
kind: "user",
permalink: "tomer-maizner",
username: "TOMER MAIZNER",
last_modified: "2018/06/20 17:34:39 +0000",
uri: "https://api.soundcloud.com/users/8504856",
permalink_url: "http://soundcloud.com/tomer-maizner",
avatar_url: "https://i1.sndcdn.com/avatars-000234677748-voqr8o-large.jpg"
},
permalink_url: "https://soundcloud.com/tomer-maizner/forever-tel-aviv-pride-2018-anthems-mixed-by-tomer-maizner",
artwork_url: "https://i1.sndcdn.com/artworks-000363076815-gwll9g-large.jpg",
stream_url: "https://api.soundcloud.com/tracks/460976748/stream",
download_url: "https://api.soundcloud.com/tracks/460976748/download",
playback_count: 8696,
download_count: 0,
favoritings_count: 792,
reposts_count: 62,
comment_count: 5,
downloadable: false,
waveform_url: "https://w1.sndcdn.com/WoEUY48eF4tR_m.png",
attachments_uri: "https://api.soundcloud.com/tracks/460976748/attachments"
}

Ruby date format for PayPal Button Manager API

I can't get a date format that PayPal will accept via its PayPal Button manager API. "The start date specified is invalid." is the error.
Attempt 1: copy the string directly from the documentation:
"start_date": "2017-12-22T09:13:49Z"
I saw this https://github.com/paypal/PayPal-Ruby-SDK/issues/107 so tried
strftime('%Y-%m-%dT%H:%M:%SZ') and utc.iso8601
start_date = "1980-02-19T00:37:04Z"
start_date = (DateTime.now - 10.years).utc.iso8601
start_date = (DateTime.now - 10.years).utc
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
# Make API call & get response
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
#Errors=[#<PayPal::SDK::ButtonManager::DataTypes::ErrorType:0x007fa58b12e110 #ShortMessage="Invalid Argument", #LongMessage="The start date specified is invalid.", #ErrorCode="11998
(byebug) #bm_build_button_search.start_date.class
PayPal::SDK::Core::API::DataTypes::SimpleTypes::DateTime
So it looks like PayPal is fine with this DateTime format but when I call
#api.BMButtonSearch(#bm_build_button_search)
I get the error #LongMessage="The start date specified is invalid."
I just verified following script using Ruby version 2.3.3 and its working fine. Following is the script i used in ruby console.
Step1: install Paypal SDK
$ gem install paypal-sdk-buttonmanager
Step2:
require 'paypal-sdk-buttonmanager'
#api = PayPal::SDK::ButtonManager::API.new(
:mode => "sandbox", # Set "live" for production
:app_id => "APP-80W284485P519543T",
:username => "jb-us-seller_api1.paypal.com",
:password => "WX4WTU3S8MY44S7F",
:signature => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-
RWy" )
Step3:
start_date = "1980-02-19T00:37:04Z"
#bm_build_button_search = #api.build_bm_button_search({ "start_date" => start_date })
#bm_button_search_response = #api.BMButtonSearch(#bm_build_button_search)
Response: I, [2017-05-06T05:43:14.803444 #6541] INFO -- : Action: BMButtonSearch
I, [2017-05-06T05:43:14.803551 #6541] INFO -- : Request[post]: https://api-3t.sandbox.paypal.com/2.0/
I, [2017-05-06T05:43:27.057413 #6541] INFO -- : Response[200]: OK, Duration: 12.254s
**Please verify using Ruby 2.3.3. Screenshot has been attached. thanks!**
reference: https://github.com/paypal/buttonmanager-sdk-ruby

Slack API: Retrieve all member emails from a slack channel

Given the name of a slack channel, is there a way to retrieve a list of emails of all the members in that channel? I tried looking in the slack api docs but couldn't find the method I need to make this happen (https://api.slack.com/methods).
Provided you have the necessary scopes you can retrieved the emails of all members of a channel starting with the channel name as follows:
Call channels.list to get the list of all channels and to convert the channel name to its ID
Call channels.info of the desired channel with channel ID to get the list of its members.
Call users.list to retrieve the list of all Slack users including their profile information and email
Match the channel member list with the user list by user ID to get the correct users and emails
Note that this also works for private channels using groups.list and groups.info, but only if the user or bot related to the access token is a member of that private channel.
Update 2019
Would strongly recommend to rather use the newer conversations.* methods, instead of channels.* and groups.*, because they are more flexible and they are some cases where the older methods will not work (e.g. converted channels).
Here's a version that works with Python 2 or 3 using up-to-date APIs.
import os
import requests
SLACK_API_TOKEN='xoxb-TOKENID' # Your token here
CHANNEL_NAME='general' # Your channel here
channel_list = requests.get('https://slack.com/api/conversations.list?token=%s&types=%s' % (SLACK_API_TOKEN, 'public_channel,private_channel,im,mpim')).json()['channels']
for c in channel_list:
if 'name' in c and c['name'] == CHANNEL_NAME:
channel = c
members = requests.get('https://slack.com/api/conversations.members?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['members']
users_list = requests.get('https://slack.com/api/users.list?token=%s' % SLACK_API_TOKEN).json()['members']
for user in users_list:
if "email" in user['profile'] and user['id'] in members:
print(user['profile']['email'])
Note that you'll need to create a Slack App with an OAuth API token and the following scopes authorized for this to work for all of the various types of conversations:
channels:read
groups:read
im:read
mpim:read
users:read
users:read.email
Also, to read from private channels or chats, you'll need to add your app to the Workspace and "/invite appname" for each channel you're interested in.
Note: channels.list, channels.info, users.list are deprecated (retire and cease functioning on November 25, 2020).
Replace to conversations.list, conversations.members, users.info
You can get the email like this way:
conversations.list - Get the list of Channel Id (public or private)
conversations.members - Get the list of Member Id by Channel Id
users.info - Get the Email by Member Id
Here's the python code:
import requests
SLACK_API_TOKEN = "" # get one from https://api.slack.com/docs/oauth-test-tokens
CHANNEL_NAME = ""
# channel_list = requests.get('https://slack.com/api/channels.list?token=%s' % SLACK_API_TOKEN).json()['channels']
# channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]
# channel_info = requests.get('https://slack.com/api/channels.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['channel']
# members = channel_info['members']
channel_list = requests.get('https://slack.com/api/groups.list?token=%s' % SLACK_API_TOKEN).json()['groups']
channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]
channel_info = requests.get('https://slack.com/api/groups.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['group']
print channel_info
members = channel_info['members']
users_list = requests.get('https://slack.com/api/users.list?token=%s' % SLACK_API_TOKEN).json()['members']
users = filter(lambda u: u['id'] in members, users_list)
for user in users:
first_name, last_name = '', ''
if user['real_name']:
first_name = user['real_name']
if ' ' in user['real_name']:
first_name, last_name = user['real_name'].split()
# print "%s,%s,%s" % (first_name, last_name, user['profile']['email'])
print "%s" % (user['profile']['email'])
I just made a small Ruby script, what retrieves all members from a slack channel and returns it in CSV format.
Script: https://github.com/olivernadj/toolbox/tree/master/slack-members
Example:
$ ./membersof.rb -t xoxp-123456789A-BCDEF01234-56789ABCDE-F012345678 -g QWERTYUIO
first_name,last_name,email
John,Doe,john.doe#example.com
Jane,Doe,jane.doe#example.com
Based on the answer by #Lam, I modified it to work with python3.
import requests
SLACK_API_TOKEN = "" # get one from https://api.slack.com/docs/oauth-test-tokens
CHANNEL_NAME = ""
# channel_list = requests.get('https://slack.com/api/channels.list?token=%s' % SLACK_API_TOKEN).json()['channels']
# channel = filter(lambda c: c['name'] == CHANNEL_NAME, channel_list)[0]
# channel_info = requests.get('https://slack.com/api/channels.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['channel']
# members = channel_info['members']
channel_list = requests.get('https://slack.com/api/groups.list?token=%s' % SLACK_API_TOKEN).json()['groups']
for c in channel_list:
if c['name'] == CHANNEL_NAME:
channel = c
channel_info = requests.get('https://slack.com/api/groups.info?token=%s&channel=%s' % (SLACK_API_TOKEN, channel['id'])).json()['group']
print(channel_info)
members = channel_info['members']
users_list = requests.get('https://slack.com/api/users.list?token=%s' % SLACK_API_TOKEN).json()['members']
for user in users_list:
if "email" in user['profile']:
print(user['profile']['email'])
Ruby solution using slack-ruby-client:
Scopes:
channels:read
users.profile:read
users:read.email
users:read
require 'slack-ruby-client'
Slack.configure do |config|
config.token = ENV['SLACK_TOKEN_IN_BASH_PROFILE']
end
client = Slack::Web::Client.new
CH = '#channel-name'
client.conversations_members(channel: CH).members.each do |user|
puts client.users_profile_get(user: user).profile.email
end
I'm not sure if these are all outdated but I couldn't get any of them to work. The best way I found to do it was to use the client.conversations_members method to find all user IDs and then get emails for those users.
import slack
def get_channel_emails(channel_id:str)-> list:
client = slack.WebClient(token=os.getenv("SLACK_TOKEN"))
result = client.conversations_members(channel= channel_id)
emails = []
for user in result['members']:
info = client.users_info(user = user).data
if 'email' in info['user']['profile'].keys():
emails.append(info['user']['profile']['email'])
return emails
Some notable roadblocks are:
The slack package is actually slackclient so use pip install slackclient instead
The channel_id is not the channel name but the code slack gives to the channel. It can be found in the web browser version path and is formatted CXXXXXXXXXX.
If without coding you require to get emails of all users from Slack channel:
Go to Channel settings, there is a option for "Copy member email address".
With Slack API:
conversations.list - Get the list of Channel Id (public or private)
conversations.members - Get the list of Member Id by Channel Id
users.info - Get the Email by Member Id
with python3 and package 'slackclient'
HERE
pip3 install slackclient
def get_channel_emails(channel_id: str):
slack_api_bot_token = 'YOUR_BOT_TOKEN'
## Require BOT permission ##
# channels:read
# groups:read
# im:read
# mpim:read
# users:read
client = slack.WebClient(token=slack_api_bot_token)
result = client.conversations_members(channel=channel_id)
i = 0
for user in result['members']:
#print(user)
info = client.users_info(user=user).data
i = i + 1
#print(info)
member_id = info['user']['id']
team_id = info['user']['team_id']
display_name = info['user']['name']
real_name = info['user']['real_name']
phone = info['user']['profile']['phone']
email = info['user']['profile']['email']
if not member_id:
member_id = 'null'
elif not team_id:
team_id = 'null'
elif not display_name:
display_name = 'null'
elif not real_name:
real_name = 'null'
elif not phone:
phone = 'null'
elif not email:
email = 'null'
print(f'{i},{real_name},{display_name},{team_id},{member_id},{email},{phone}')
def main():
#channel id: https://app.slack.com/huddle/TB37ZG064/CB3CF4A7B
#if end of URL string starts with "C", it means CHANNEL
get_channel_emails('CB3CF4A7B')

AD FS email claim not found

I have a web app. I'm trying to get it to authenticate against a Win2012 R2 ADFS server.
I have the relying party set up, get redirected, sign in, then redirected back to the app as a failed request.
In the event log I have this:
MSIS7070: The SAML request contained a NameIDPolicy that was not satisfied by the issued token. Requested NameIDPolicy: AllowCreate: True Format: urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress SPNameQualifier: . Actual NameID properties: null.
If I read this right, the webapp is asking for urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress but that policy isn't found for the relying party.
Under the relying party, I have two rules:
# get email address from active directory
c:[Type == "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname", Issuer == "AD AUTHORITY"]
=> issue(store = "Active Directory",
types = ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"), query = ";mail;{0}", param = c.Value);
rule 2
transform email address to nameid/email
c:[Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"]
=> issue(Type = "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
Issuer = c.Issuer,
OriginalIssuer = c.OriginalIssuer,
Value = c.Value,
ValueType = c.ValueType,
Properties["http://schemas.xmlsoap.org/ws/2005/05/identity/claimproperties/format"]
= "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress");
I've double checked and made sure that the formats match, but I'm stuck on the error messages.

geocode don't show subpremise address Brazil

how to collect room number information on a building in the google geocode?
in my search don't show. SUBPREMISE
example address: rua joao samaha 1385, sala 403 bl 02 sao joao batista, belo horizonte, MG, Brazil.
https://maps.googleapis.com/maps/api/geocode/json?address=
I'm a developer at SmartyStreets, an international address verification API provider. Here's the component information that we have on that address:
[
{
// preceding data omitted
"components":{
"administrative_area":"MG",
"building":"Bloco 02",
"dependent_locality":"São João Batista (Venda Nova)",
"country_iso_3":"BRA",
"locality":"Belo Horizonte",
"postal_code":"31520-100",
"postal_code_short":"31520-100",
"premise":"1385",
"premise_number":"1385",
"thoroughfare":"Rua João Samaha",
"thoroughfare_name":"Joao Samaha",
"thoroughfare_type":"Rua",
"building_leading_type":"Bloco",
"sub_building_type":"Sala",
"sub_building_number":"403"
},
// remaining data omitted
}
]
Does that information help?
https://smartystreets.com/docs/international#components