Alamofire problems Xcode 8 GM Ambiguous reference to member request - alamofire

I updated to xcode 8 GM and this lead me to update my Alamofire package and I have not been able to fix what used to work before, where now I get this error
"Ambiguous reference to member request"
public func executeWebRequest(url: String) -> Request
{
let defaultHeaders: [String : String] = ["Content-Type":"application/json;charset=utf-8", "Accept": "application/json"]
let parameters = [
"foo": "bar",
"baz": ["a", 1],
"qux": [
"x": 1,
"y": 2,
"z": 3
]
] as [String : Any]
let restRequest = Alamofire.request(url,
withMethod: .post,
parameters: parameters,
encoding: JSONEncoding.default,
headers:defaultHeaders)
return restRequest
}
This was working with beta6 and now is not. I am not able to find to problem. I tired this in the test case of the Alamofire project its self and I am not getting the error, only in my project which is a framework.
My take is that some how some thing change in the way to set the framework and its causing this. wondering if any one did get the same and with luck did find a fix.

You can blame the Swift interpreter for being so uninformative. Change withMethod: to method:. It changed in a recent commit to Alamofire and I had the same issue!

Related

Using JIRA REST-API to update a custom field

I've been trying to set up a new custom webhook in Zapier, that automatically updates a custom field in JIRA, whenever a specific action occurs. I've followed some tutorials on how to do it, but when I sent the PUT request, it didn't work. I also tested a bunch in postman, but with similar results.
I used this URL:
https://bitsandbirds.atlassian.net/rest/api/3/issue/CYBIRD-1252
Here is my input:
{
"update" : {
"customfield_10051" : "test"
}
}
This is what I got back:
{
"errorMessages": [
"Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token\n at [Source: org.apache.catalina.connector.CoyoteInputStream#498ac517; line: 3, column: 8] (through reference chain: com.atlassian.jira.rest.v2.issue.IssueUpdateBean[\"update\"])"
]
}
Anyone know where I messed up & how to do it right?
fyi here is the view in Zapier
There should be
{
"fields": {
"customfield_10051" : "test"
}
}

How to submit new github issue through access token using rust

I'm trying to write a rust script that submits an issue with given name, label and body to a specific repository using github access token. I've found github-rs and octocrab, but can't figure out how this exact function works.
UPDATE
Here's the code using rust-curl:
use std::io::Read;
use curl::easy::{Easy, List};
fn main() {
let mut data = r#"{
"title": "Found a bug",
"body": "I'm having a problem with this.",
"labels": [
"bug"
]
}"#.as_bytes();
let mut easy = Easy::new();
easy.url("https://api.github.com").unwrap();
let mut list = List::new();
list.append("Authorization: token TOKEN_HERE").unwrap();
easy.http_headers(list).unwrap();
easy.perform().unwrap();
easy.post(true).unwrap();
easy.post_field_size(data.len() as u64).unwrap();
let mut transfer = easy.transfer();
transfer.read_function(|buf| {
Ok(data.read(buf).unwrap_or(0))
}).unwrap();
transfer.perform().unwrap();
}
If those librairies don't include an easy way, you could fall back to alexcrichton/curl-rust
It does let you add custom headers, including the "Authorization: token MY_TOKEN_NUMBERS" you can see used here, which will authenticate you.
From there, your curl call (in rust) can use the GitHub API "create issue" endpoint:
POST /repos/:owner/:repo/issues
with the data:
{
"title": "Found a bug",
"body": "I'm having a problem with this.",
"assignees": [
"octocat"
],
"milestone": 1,
"labels": [
"bug"
]
}

Get Method is not working inside App if URL contains .info?

I am making a simple GET Method inside the APP , But its Not Working on some URL..
For Eg :
https://lievensberg.webcamconsult.com/wachtkamer/ZwXIk9KcYvMBFeJWiSeUQQ.json . - this is working (contains .com)
https://soa-webcamconsult.sense.info/wachtkamer/pk3rs51FpFUQkrHOJ0uBHg.json - this is not working (contains .info)
Both URL is Working Perfect in Browser...!
I am using AFNetworking, Any one can Help Me Please ?
This is the Call Method , Url given below
//https://soa-webcamconsult.sense.info/wachtkamer/pk3rs51FpFUQkrHOJ0uBHg.json
NSDictionary *header = [NSDictionary dictionaryWithObjectsAndKeys:#"application/json",#"Content-Type", #"application/json", #"Accept", #"iPhone",#"User-Agent",nil];
NSLog(#"url---%#",url);
NSLog(#"header---%#",[Utilities printJson:header]);
[SSNetworkClient initServerCallWithURL:url requestMethod:SSRequestMethodGET requestSerialize:YES headers:header imageData:nil imageDataName:nil parameters:nil success:^(id object) {
completionBlock(YES,object);
} failure:^(id object) {
failureCompletion(NO,object);
}];
In you response of second url you are getting invalid json and which should be like this,
{
"status": {
"code": "on_time",
"message": "U bent op tijd",
"content": "Uw afspraak begint om *|afspraak_tijd|* ."
},
"slave": {
"name1": "Dhr. sunny",
"name2": "Meneer sunny"
},
"master": {
"name1": "Mr beheerder"
},
"push": {
"origin": "pubsub.pubnub.com",
"pub_key": "pub-c-a6ca4c51-0a6f-475d-8f93-f53f48ba117b",
"sub_key": "sub-c-97578f62-3587-11e3-be49-02ee2ddab7fe",
"uuid": "sunny-5a323ac22cacff0004c2a717",
"channels": ["5a29524f2b4faa000470384a", "5a323ac22cacff0004c2a717"]
},
"lobby_message": "",
"contact_info": "/dyncontent/pk3rs51FpFUQkrHOJ0uBHg"
}
Above is the correct json which you will need to improve in your api response
And if you wont verify just create the json file with above json it will work perfectly with browser and with your .info api response json it won't work so you need to improvise your .info json file response
My Mozilla browser Quantum version response,

CakePHP3.4: How to send a json object response?

I try to migrate to 3.4 and I have a problem to send a json object.
Up to 3.3, I used the following code:
$jsonSites = json_encode([
'reqLocation' => [
'latitude' => $latitude,
'longitude' => $longitude
],
'sites' => $sitesList,
'discoveryBooks' => $discoveryBooksList,
'deleteSites' => !empty($inDeviceSites) ? [$inDeviceSites] : [],
'deleteBooks' => !empty($inDeviceBooks) ? [$inDeviceBooks] : []
]);
$this->response->type('application/json');
$this->response->body($jsonSites);
And my client received such kind of object:
{
"reqLocation": {
"latitude": 48.080563,
"longitude": 4.4649
},
"sites": [
{
"id": 5076,
"name": "...",
"modified": "2017-01-28T03:03:23+00:00",
"directory_name": "fr/26/26120_56cc30ea4d907",
"type": "portail",
"longitude": 7.031953,
"latitude": 47.939468,
"image_0": "jpg",
"picto_color": "#FFDDDDDD",
"agthemes": [],
"distance": 131.29188575851,
"category": 1281,
"category_name": "Jardin",
"sitecategories": [
{
"id": 10,
"code": 1281,
"name_fr": "Jardin",
"_joinData": {
"id": 1876,
"site_id": 5076,
"site_category_id": 10,
"authorized": true
}
},
{
"id": 33,
"code": 1283,
"name_fr": "Jardin botanique",
"_joinData": {
"id": 5693,
"site_id": 5076,
"site_category_id": 33,
"authorized": true
}
}
]
},
],
"discoveryBooks": [],
"deleteSites": [],
"deleteBooks": []
}
So now I just replaced the deprecated Response methods like that:
EDIT: Of course I return the response object but that cannot work like done here!
$this->response->withType('application/json');
$this->response->withStringBody($jsonSites);
return $this->response;
But now my client doesn't receive anything. I also tried with postman, nothing!
What's wrong?
Check the migration guide, the new reponse methods follow the PSR-7 immutability pattern.
Request & Response Deprecations
The bulk of deprecations for 3.4 are in the Request and Response
objects. The existing methods that modify objects in-place are now
deprecated, and superseded by methods that follow the immutable object
patterns described in the PSR-7 standard.
Cookbook > 3.x Migration Guide > 3.4 Migration Guide > Request & Response Deprecations
Adopting Immutable Responses
Before you migrate your code to use the new response methods you
should be aware of the conceptual differences the new methods have.
The immutable methods are generally indicated using a with prefix. For
example, withLocation(). Because these methods operate in an immutable
context, they return new instances which you need to assign to
variables or properties. If you had controller code that looked like:
$response = $this->response;
$response->location('/login')
$response->header('X-something', 'a value');
If you were to simply find & replace method names your code would break.
Instead you must now use code that looks like:
$this->response = $this->response
->withLocation('/login')
->withHeader('X-something', 'a value');
There are a few key differences:
The result of your changes is re-assigned to $this->response. This is
critical to preserving the intent of the above code. The setter
methods can all be chained together. This allows you to skip storing
all the intermediate objects.
Cookbook > 3.x Migration Guide > 3.4 Migration Guide > Adopting Immutable Responses
Long story short, in your case you must return the new request object created by the immutable methods:
return $this->response
->withType('application/json');
->withStringBody($jsonSites);
If you wouldn't return a response object, then you'd need to reassign the new reponse to $this->response as mentioned in the above quote.

HTTP Adapter Error "Runtime: Failed to parse JSON string"

I am using IBM Worklight Studio, and trying to create HTTP Adapter which retrieve JSON object from external http server.
When I just access target http server with HTTP Get access(with browser, for example), I know their response is like following array style JSON format:
[
{ "xxx":"aaa", "yyy":"bbb", ... },
{ "xxx":"ccc", "yyy":"ddd", ... },
:
{ "xxx":"eee", "yyy":"fff", ... }
]
And I had created HTTP Adapter which would retrieve above information
var input = {
method : 'get',
returnedContentType : 'json',
path : path
};
return WL.Server.invokeHttp(input);
Now I tried to invoke this adapter with "Run As -> Invoke Worklight Procedure", then I got this error message:
{
"errors": [
"Runtime: Failed to parse JSON string\n\n[\n {\n
(raw JSON data) } ],
"info": [],
"isSuccessful": false,
"warnings": []
}
And in my log console, worklight says following error messages:
FWLSE0101E: Caused by: java.io.IOException: Expecting '{' on line 2, column 2 instead, obtained token: 'Token: ['
From above information, it seems that worklight would expect that returned JSON object need to start with "{", not "[".
Is this my guess right? Are there any workaround for this?
Thanks for advance.
Worklight knows how to handle JSON objects that start with [ (JSON arrays). In such case Worklight will return the response as:
{ "array" : [*the json array*]}
Looking at the code of the HTTP Adapter, I see that there is a bug with parsing JSON arrays that do not start with [.
I do not see a workaround for this problem, except changing the response returned from the http server.
I opened an internal bug about this, thank you for helping us find this bug.
You can change returnedContentType to "plain", this will make WL server return content as a big string and not attempt to parse it.
Then in your adapter you can use var obj = JSON.parse(response.text)