Grape API is removing '+' from string (replacing with blank space) - grape-api

I have a grape API and as part of a POST request I am passing a string that has a '+' as part of it (it's a phone number). Grape seems to be removing the + and replacing it with a blank space.
module V1
class CustomerDetails < Grape::API
before do
error!("Unauthorized", 401) unless authenticated?
end
resource :customer_details do
desc 'Update customer number'
post anchor: false do
params do
requires :customer_id, type: String
requires :customer_number, type: String
end
# Current behaviour:
# params[:customer_number] here will be ' 441920765847'
# Expected behaviour:
# params[:customer_number] here will be '+441920765847'
end
end
end
end
I expect to use postman to make the http POST request, with the parameter customer_number with value +441920765847and it does not lose the + (i.e. does not show as 441920765847.

solved! It was postman removing it because i was sending it in the params (url string) and not in the body

Related

karate : handling soap response from a called feature file

first.feature
Given ur ''
def payload = read('')
request payload
soap action ''
value = /Envelope/Body/Response/Result/Num
print value # prints value correctly as expected
second.feature
Background:
*def fetch = read('first.feature')
*def data = call fetch
Scenario:
print data.response # prints the soap response in json format.
def res = data.response
print res["s:Envelope"][""]["s:Body"]["Response"][""]["Result"]["_"]["a:num']
first.feature works as expected ( response is in soap )
When I try to call this feature in another feature then the response is in json format.
I want to use a value from this response to pass it on to another request.
I had to use res["s:Envelope"]["_"]["s:Body"][][].. to get to that.
Is there a way to easily fetch a value from this response as we do in first.feature?
Please could anyone let me know how to achieve this.
Make this change:
* xml res = data.response
We will be improving this in the next version, it would be good if you can test the develop branch and confirm: https://github.com/intuit/karate/wiki/Developer-Guide

Maximo REST API : MXAPIMeter Create Meter Failed

I tried to create Meter using HTTP POST olscmeter and mxapimeter.
My python code is
postReq = mxURL + "/maximo/oslc/os/oslcmeter"
headers = {'Content-type': 'application/json', 'maxauth' : maxAuth}
body = {'METERNAME' : meterName, 'METERTYPE' : meterType, 'DESCRIPTION' : description, 'READINGTYPE' : 'ACTUAL', 'MEASUREUNITID' : ''}
print(postReq, headers, body)
r = requests.post(url = postReq, headers = headers, json = body)
print(r.status_code, r.text)
And I kept encountering the under-mentioned error.
400
{"oslc:Error":
{"oslc:statusCode":"400",
"errorattrname":"metername",
"spi:reasonCode":"BMXAA4195E",
"errorobjpath":"meter",
"correlationid":null,
"oslc:message":"BMXAA4195E - A value is required for the Meter field on the METER object.",
"oslc:extendedError":{"oslc:moreInfo":{"rdf:resource":"http:\/\/mx7vm\/maximo\/oslc\/error\/messages\/BMXAA4195E"}
}
}
}
Any advice on what I have missed?
Thank you.
BMXAA4195E is just a generic error that means a required field is missing.
I have never generated MBOs this way, but I think the issue is that JSON keys are case sensitive. In all the examples I've seen online, the attributes in the body are always lowercase. This also makes sense with the error message.
Try using all lowercase keys in your body.

Karate framework variable usage

I have this steps:
...
Then status 200
And match response.requests[0].request.url == "/endpoint"
And json body = response.requests[0].request.body
And match body == { "something": "something"}
To simplify, I tried to put response.requests[0].request in a variable called request:
...
Then status 200
And def request = response.requests[0].request
And match request.url == "/endpoint"
And json body = request.body
And match body == { "something": "something"}
I'm having the following error:
'request' is not a variable, use the form '* request <expression>' instead
I read the documentation and the use of request seems to be fine:
Given def color = 'red '
And def num = 5
Then assert color + num == 'red 5'
What am I doing wrong?
Thanks in advance.
Just make this change:
* def req = response.requests[0].request
# other steps
* request req
We simply disallow def request (using request as a variable name) because a lot of newbie users get confused. The error message has worked 99.9% of the time for users to understand what the problem is, but I guess you fall in the 0.1% :)

Rails / Sitemap_Generator: Subdomain sitemaps

I'm trying to create a sitemap for my app which features subdomains using the sitemap_generator gem. However, I'm getting an error with my code:
the scheme http does not accept registry part: .foo.com (or bad hostname?)
My sitemap.rb:
SitemapGenerator::Sitemap.default_host = "http://www.foo.com"
SitemapGenerator::Sitemap.sitemaps_host = "http://s3.amazonaws.com/foo/"
SitemapGenerator::Sitemap.public_path = 'tmp/'
SitemapGenerator::Sitemap.sitemaps_path = 'sitemaps/'
SitemapGenerator::Sitemap.adapter = SitemapGenerator::WaveAdapter.new
SitemapGenerator::Sitemap.create do
add '/home'
end
Customer.find_each do |customer|
SitemapGenerator::Sitemap.default_host = "http://#{customer.user_name}.foo.com"
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/#{customer.user_name}"
SitemapGenerator::Sitemap.create do
add '/home'
end
end
What am I doing wrong?
I'm the author of this gem.
I am fairly certain that the problem is with one of the customer user name's containing a character which is not allowed in a URL. A simple test with simple names works e.g.:
%w(bill mary bob).each do |customer|
SitemapGenerator::Sitemap.default_host = "http://#{customer}.foo.com"
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/#{customer}"
SitemapGenerator::Sitemap.create do
add '/home'
end
end

Ruby on Rails - string to array weird formatting in email parsing

I can get the body of an email in String format like so
body = params[:plain]
And when I output it, it looks like:
Hi there.
--
John B.
Sent from my iPhone.
Now, when I try and split by newline body.split("\n") I get:
---
- ! 'Hi there.'
- ''
- ! '-- '
- John B.
- ''
- Sent from my iPhone.
I don't really understand the extra hyphens and bangs. Any thoughts?
Also if I do body[2] I get --, but body.index("--") returns me nothing.
UPDATE
In my ReceivingMails controller:
...
def create
body = params[:plain]
parsed_body = parse_body(body)
Comment.new(:content => parsed_body)
end
private
def parse_body(body)
split = body.split("\n")
sig_index = split.index("-- ")
return split[0, sig_index].join("\n")
end
In my view, comments are shown as: <%= simple_format(comment.content)%>
UPDATE 2
When I do something like, body.split("\n").to_s I get what the expected array should look like (as String): ["Hi there. ", "", "-- ", "John B.", "", "Sent from my iPhone."]
I don't think params[:plain] is actually a string - I think you should test it to find out what it actually is. For example try:
puts params[:plain].class