How to include # (hash) DTMF in tel URI format as part of extension? - uri

Based on https://www.ietf.org/rfc/rfc3966.txt
If I have a number +12366778899 and an extension 123, then the tel URI is tel:+12366778899;ext=123
However, if I have an extension 123# what would be the correct tel URI?
https://www.ietf.org/rfc/rfc3966.txt specifies that:
extension = ";ext=" 1*phonedigit
...
phonedigit = DIGIT / [ visual-separator ]
...
which does not include # as I understand.

Related

django rest framework post method not allowed

I am creating an api and no idea why post method not allowed on any url.
views
class MessagesView(APIView):
permission_classes = (IsAuthenticated,)
def post(self, request):
serializer = MessageSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
chat.urls
urlpatterns = [
path("<str:pk>/", ChatDetail.as_view()),
path("messages/", MessagesView.as_view()),
]
response
{
"detail": "Method \"POST\" not allowed."
}
I am providing the token for the request, so isAuthenticated does not do anything wrong here.
Your first pattern will fire if you visit messages/. Indeed, its <str:pk> parameter matches any string (with at least one character and without slashes). But messages is thus also matched with this view.
What you can do is swap the places of the two urls, then calling messages/ will fire the correct view:
urlpatterns = [
# &downarrow; messages first
path('messages/', MessagesView.as_view()),
path('<str:pk>/', ChatDetail.as_view()),
]
If pk is an integer, you can further restrict the pk with the <int:…> path converter:
urlpatterns = [
path('messages/', MessagesView.as_view()),
path('<int:pk>/', ChatDetail.as_view()),
]

How to filter non-resolvable URIs on a SPARQL query?

Is it possibe to filter out results that contains a non-resolvable URI within the SPARQL query?
An example: I'm making the following query (endpoint: http://linkeddata.systems:8890/sparql):
PREFIX RO: <http://www.obofoundry.org/ro/ro.owl#>
PREFIX SIO: <http://semanticscience.org/resource/>
PREFIX EDAM: <http://edamontology.org/>
PREFIX PHIO: <http://linkeddata.systems/ontologies/SemanticPHIBase#>
PREFIX PUBMED: <http://linkedlifedata.com/resource/pubmed/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX up: <http://purl.uniprot.org/core/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?disn_1 ?label ?rel ?valor
WHERE { ?disn_1 ?rel ?valor . ?disn_1 rdfs:label ?label FILTER(( ?disn_1 = <http://linkeddata.systems/SemanticPHIBase/Resource/host/HOST_00561>))}
In the results, as you can see there is in ?valor variable a triple that contains a non-resolvable URI (text: /hostncbitaxid/). I would like to know if there is some specific FILTER that can be added in the SPARQL query to remove those results with non-resolvable URIs.
I'm having problems with the API that I'm using to process these results in C# because it is returning an exception due to non-resolvable URIs so I would like to filter them out in the SPARQL query (if possible).
How do you know that it's not resolvable? RDF doesn't have a concept of a "relative URI", all the URIs are resolved relative to something (and perhaps to what is an implementation detail in some cases), so you end up with absolute URIs. In the HTML results from that endpoint, I get http://linkeddata.systems:8890/hostncbitaxid/, and that could easily be resolvable.
That said, if you are ending up with results that include non-absolute URIs, and you want to filter those out, you could use some heuristics to do that. For instance, if you only want URIs beginning with http, you can do that. E.g., here's a query that returns two values for ?uri:
prefix : <urn:ex:>
select * where {
values ?uri { <http://www.example.org/> </foobar> }
}
-----------------------------
| uri |
=============================
| <http://www.example.org/> |
| <file:///foobar> |
-----------------------------
(Notice that the relative URI /foobar got resolved as a file:// URI.) You can keep only http URIs with a filter:
prefix : <urn:ex:>
select * where {
values ?uri { <http://www.example.org/> </foobar> }
filter strstarts(str(?uri), "http")
}
-----------------------------
| uri |
=============================
| <http://www.example.org/> |
-----------------------------
The query returns (SPARQL results in JSON format):
"valor": { "type": "uri", "value": "/hostncbitaxid/" }}
This is bad data - it must be an absolute URI in RDF. Presumably the data is bad. You can remove it in the query as #joshua-taylor shows.

How to use anchors in Symfony routing?

I have defined a route as followed in my routing.yml file :
route_name:
path: "/dashboard#messages/{id}"
However when I ask Symfony to generate that route, I get :
/dashboard%23messages/12345
How can I skip the encoding part of the route generation? Or how can I escape the # char in the path definition?
PS : Working with a (big) legacy system, I cannot change the urls.
Available from Symfony 3.2.
Support for anchors has been announced for the routing component using the fragment variable :
$this->get('router')->generate('user_settings', ['_fragment' => 'password']);
Will generate an url : /user/settings#password
For more information view the announcement.
You cannot easily - route parts are encoded unconditionally:
$url = strtr(rawurlencode($url), $this->decodedChars);
see at https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php#L192
Technically you might have extended the class UrlGenerator class and swap them using router.options.generator_class parameter. Then you could override the doGenerate method and replace %23 -> #.
In twig
<a href="{{ path('user_settings', { '_fragment': 'password' }) }}">

Swagger:Issue with Path parameter

I am try to create a swagger file with the following path:
paths:
/v1/customers/{id}/summary :
However I get the following error right off bat:
API requires path parameter but it is not defined: id
at paths ▹ /v1/customers/{id}/summary
It does not seem to like the 'id' parameter. Could anybody tell me how I could rectify this?
If I drill down on this I see the following:
Details
Object
swaggerError: Object
errors: Array [1]
0: Object
code: "MISSING_API_PATH_PARAMETER"
message: "API requires path parameter but it is not defined: id"
data: "/v1/customers/{id}/summary"
path: Array [2]
warnings: Array [0]
Basically, you're declaring a path that has a path parameter in it, by using path templates. In this case {id} declares a path parameter called id.
When you declare such a path, it means that you have to declare that path parameter as part of the operation.
Take a look at this YAML example:
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: findPetById
produces:
- application/json
- application/xml
- text/xml
- text/html
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
'200':
description: pet response
schema:
$ref: '#/definitions/pet'
default:
description: unexpected error
schema:
$ref: '#/definitions/errorModel'
You can see there's an {id} in the path, and a corresponding id parameter definition. Without it, the spec won't be valid.

Convert Bundle:Controller:Filename to actual file path

Is there a way to convert Symfony filename notation Bundle:Controller:Filename to a real file path /var/www/whatever/src/Bundle/Resources/views/Controller/Filename?
Tak a look at this question: Resolve local file path from Twig template name . Accepted answer says:
"If you want to retrieve path from a controller you can use this code:
$parser = $this->container->get('templating.name_parser');
$locator = $this->container->get('templating.locator');
$path = $locator->locate($parser->parse('AcmeProjectBundle::home.html.twig'));
For more info take a look at code of:
Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser::parse
Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::locate
"

Resources