Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "code"), level = DeprecationLevel.ERROR) - okhttp

why okhttp4.x use the replaceWith to forbid developer to get response's code like response.code(). Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "code"), level = DeprecationLevel.ERROR)
why okhttp4.x use the replaceWith to forbid developer to get response's code like response.code(). Deprecated( message = "moved to val", replaceWith = ReplaceWith(expression = "code"), level = DeprecationLevel.ERROR)

In OkHttp 4.x, the Response.code() method has been deprecated in favor of using the code property. This change improves the readability and consistency of the code. To get the response code, use response.code instead of response.code().

Related

Update contact in Google People API

I'm having trouble updating the notes of contacts through Googles People API. I used some code from a previous stackoverflow answer, but it doesn't seem to work anymore. Below is the function I'm using. I'm attempting to change the notes of a particular contact to "changed bio xyz".
What am I doing wrong? The api does read a listing of the contacts, but I haven't been able to successfully write yet.
Thanks and please let me know if I can make this question more clear
results = service.people().connections().list(
resourceName='people/me',
pageSize=1500,
personFields='names,emailAddresses,phoneNumbers,biographies').execute()
connections = results.get('connections', [])
aContact = service.people().get(
resourceName = 'people/c1589313158061148817',
personFields = 'biographies' ).execute()
notesNames = aContact['biographies'][0]
notesNames['value'] = 'changed bio xyz'
result = service.people().updateContact(
resourceName = 'people/c1589313158061148817',
body = aContact,
updatePersonFields = 'biographies'
).execute()
I figured it out. The update goes in the body section, and it needs to follow a dictionary format
aContact = service.people().get(
resourceName = 'people/c36943406266964946',
personFields = 'names,nicknames'
).execute()
print ('this is acontact', aContact)
NickNames = aContact['nicknames'][0]
NickNames['value'] = 'newNickName'
aContact['nicknames'] = NickNames
result = service.people().updateContact(
resourceName = 'people/c36943406266964946',
body = aContact,
updatePersonFields = 'nicknames'
).execute()

reply to thread google-api-ruby-client

So here's what my code (pretty much) looks like to create a message using the google-api-ruby-client:
service ||= Google::Apis::GmailV1::GmailService.new
message = RMail::Message.new
message.header['To'] = params[:gmail][:to]
message.header['From'] = current_user_google_user_id
message.header['Subject'] = params[:gmail][:subject]
message.header['Subject'] = params[:gmail][:subject]
message.body = params[:gmail][:body]
service.send_user_message(
current_user_google_user_id,
upload_source: StringIO.new(message.to_s),
content_type: 'message/rfc822',
thread_id: params[:gmail][:thread_id]
)
It obviously fails because of where I have thread_id. If I remove that line, things work fine, but I'm not able to keep things scoped to a thread. How should I be passing the thread ID to the GmailService?
Looking at the source on GitHub for send_user_message shows that it doesn't take a thread_id as a parameter. However the Message class does have it as an attribute.
So perhaps trying this should work:
service ||= Google::Apis::GmailV1::GmailService.new
message = RMail::Message.new
message.header['To'] = params[:gmail][:to]
message.header['From'] = current_user_google_user_id
message.header['Subject'] = params[:gmail][:subject]
message.header['Subject'] = params[:gmail][:subject]
message.body = params[:gmail][:body]
message.thread_id = params[:gmail][:thread_id]
service.send_user_message(
current_user_google_user_id,
upload_source: StringIO.new(message.to_s),
content_type: 'message/rfc822'
)

Pushing Offline Leads using Adwords API

I am using the below function to push my offline leads to api, everything looks good and returns success but when I check adwords, it doesnt show any data saying it received. I have tried many leads and also waited for around 3-4 days now.
What am I doing wrong?
function UploadOfflineConversionsExample(AdWordsUser $user, $conversionName,$gClId, $conversionTime, $conversionValue)
{
// Get the services, which loads the required classes.
// $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION);
$offlineConversionService = $user->GetService('OfflineConversionFeedService', ADWORDS_VERSION);
// Associate offline conversions with the upload conversion we created.
$feed = new OfflineConversionFeed();
$feed->conversionName = $conversionName;
$feed->conversionTime = $conversionTime;
$feed->conversionValue = $conversionValue;
$feed->googleClickId = $gClId;
$offlineConversionOperation = new OfflineConversionFeedOperation();
$offlineConversionOperation->operator = 'ADD';
$offlineConversionOperation->operand = $feed;
$offlineConversionOperations = array($offlineConversionOperation);
$result = $offlineConversionService->mutate($offlineConversionOperations);
$feed = $result->value[0];
return ("Uploaded offline conversion value of ". $feed->conversionValue.
" for Google Click ID = ". $feed->googleClickId." and Conversion Name " . $feed->conversionName);
}
In adwords reports this conversion will be shown in Conversions Column. and change the daterange to the date what you pushed as $conversionTime

Retrieve bibtex data from crossref by sending DOI from matlab: translation from ruby

I want to retrieve bibtex data (for building a bibliography) by sending a DOI (Digital Object Identifier) to http://www.crossref.org from within matlab.
The crossref API suggests something like this:
curl -LH "Accept: text/bibliography; style=bibtex" http://dx.doi.org/10.1038/nrd842
based on this source.
Another example from here suggests the following in ruby:
open("http://dx.doi.org/10.1038/nrd842","Accept" => "text/bibliography; style=bibtex"){|f| f.each {|line| print line}}
Although I've heard ruby rocks I want to do this in matlab and have no clue how to translate the ruby message or interpret the crossref command.
The following is what I have so far to send a doi to crossref and retrieve data in xml (in variable retdat), but not bibtex, format:
clear
clc
doi = '10.1038/nrd842';
URL_PATTERN = 'http://dx.doi.org/%s';
fetchurl = sprintf(URL_PATTERN,doi);
numinputs = 1;
www = java.net.URL(fetchurl);
is = www.openStream;
%Read stream of data
isr = java.io.InputStreamReader(is);
br = java.io.BufferedReader(isr);
%Parse return data
retdat = [];
next_line = toCharArray(br.readLine)'; %First line contains headings, determine length
%Loop through data
while ischar(next_line)
retdat = [retdat, 13, next_line];
tmp = br.readLine;
try
next_line = toCharArray(tmp)';
if strcmp(next_line,'M END')
next_line = [];
break
end
catch
break;
end
end
%Cleanup java objects
br.close;
isr.close;
is.close;
Help translating the ruby statement to something matlab can send using a script such as that posted to establish the communication with crossref would be greatly appreciated.
Edit:
Additional constraints include backward compatibility of the code (back at least to R14) :>(. Also, no use of ruby, since that solves the problem but is not a "matlab" solution, see here for how to invoke ruby from matlab via system('ruby script.rb').
You can easily edit urlread for what you need. I won't post my modified urlread function code due to copyright.
In urlread, (mine is at C:\Program Files\MATLAB\R2012a\toolbox\matlab\iofun\urlread.m), as the least elegant solution:
Right before "% Read the data from the connection." I added:
urlConnection.setRequestProperty('Accept','text/bibliography; style=bibtex');
The answer from user2034006 lays the path to a solution.
The following script works when urlread is modified:
URL_PATTERN = 'http://dx.doi.org/%s';
doi = '10.1038/nrd842';
fetchurl = sprintf(URL_PATTERN,doi);
method = 'post';
params= {};
[string,status] = urlread(fetchurl,method,params);
The modification in urlread is not identical to the suggestion of user2034006. Things worked when the line
urlConnection.setRequestProperty('Content-Type','application/x-www-form-urlencoded');
in urlread was replaced with
urlConnection.setRequestProperty('Accept','text/bibliography; style=bibtex');

Django Form Preview - Adding the User to the Form before save

class RegistrationFormPreview(FormPreview):
preview_template = 'workshops/workshop_register_preview.html'
form_template = 'workshops/workshop_register_form.html'
def done(self, request, cleaned_data):
# Do something with the cleaned_data, then redirect
# to a "success" page.
# data = request.POST.copy()
# data['user_id'] = u'%s' % (request.user.id)
# cleaned_data['user'] = u'%s' % (request.user.id)
#f = self.form(cleaned_data)
#f = self.form(data)
#f.user = request.user
f = self.form(request.POST)
f.save()
pdb.set_trace()
return HttpResponseRedirect('/register/success')
As you can see, I've tried a few ways, and that have been commented out. The task is apparently simple: Add the user from request to the form before save, and then save.
What is the accepted, working method here?
If the user can't be modified, I would say it shouldn't even be included in the form in the first place.
Either way, using the commit argument to prevent the resulting object being saved immediately should work (assuming FormPreview uses ModelForm):
obj = form.save(commit=False)
obj.user = request.user
obj.save()

Resources