rest-client

Rails - How to add contacts to SendGrid marketing campaigns via API

回眸只為那壹抹淺笑 提交于 2019-12-02 06:29:23
I need to make HTTP get and post requests with SendGrid to add contacts to our account, however there doesn't seem to be a gem for their email marketing functionality. It boils down to making a few requests however I can't get past their authentication step. They say to do this curl -X "GET" "https://api.sendgrid.com/v3/templates" -H "Authorization: Bearer Your.API.Key-HERE" -H "Content-Type: application/json" And using the Rest-Client gem I'm trying to make the authentication request like so... username = 'username' api_key = 'SG.MY_API_KEY' key = Base64.encode64(username + ":" + api_key)

error in parsing json inside an AsynTask in Android

不羁的心 提交于 2019-12-02 06:27:42
问题 I have an AsynTask and trying to retrieve a json and parse it, but I get this error: 03-21 11:38:07.033: E/AndroidRuntime(8439): FATAL EXCEPTION: main 03-21 11:38:07.033: E/AndroidRuntime(8439): java.lang.NullPointerException 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextValue(JSONTokener.java:94) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json

error in parsing json inside an AsynTask in Android

人走茶凉 提交于 2019-12-01 23:49:51
I have an AsynTask and trying to retrieve a json and parse it, but I get this error: 03-21 11:38:07.033: E/AndroidRuntime(8439): FATAL EXCEPTION: main 03-21 11:38:07.033: E/AndroidRuntime(8439): java.lang.NullPointerException 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextValue(JSONTokener.java:94) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.<init>(JSONObject.java:154) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.<init

Logging RestClient in a Rails app

泪湿孤枕 提交于 2019-12-01 17:32:02
I'd like to debug the request my Rails app makes with RestClient . The RestClient docs say: To enable logging you can set RestClient.log with a ruby Logger or set an environment variable to avoid modifying the code (in this case you can use a file name, “stdout” or “stderr”): $ RESTCLIENT_LOG=stdout path/to/my/program Either produces logs like this: RestClient.get " http://some/resource " => 200 OK | text/html 250 bytes RestClient.put " http://some/resource ", "payload" => 401 Unauthorized | application/xml 340 bytes Note that these logs are valid Ruby, so you can paste them into the

Uploading a file to a S3 Presigned URL

不羁岁月 提交于 2019-12-01 14:16:51
I'm trying to upload a local file to a S3 presigned URL. It should be really straight forward, but looks like I'm missing something. http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html Example: ENV['RESTCLIENT_LOG'] = "stdout" require 'aws-sdk' require 'rest_client' s3_object_key = "folder-name/file.zip" AWS.config(access_key_id: 'xxx', secret_access_key: 'xx') s3 = AWS::S3.new bucket = s3.buckets['my-bucket-name'] s3_object = bucket.objects[s3_object_key] upload_url = s3_object.url_for(:put, expires: 100000).to_s RestClient.put(upload_url, file: File.new("local-file

Uploading a file to a S3 Presigned URL

醉酒当歌 提交于 2019-12-01 13:15:07
问题 I'm trying to upload a local file to a S3 presigned URL. It should be really straight forward, but looks like I'm missing something. http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html Example: ENV['RESTCLIENT_LOG'] = "stdout" require 'aws-sdk' require 'rest_client' s3_object_key = "folder-name/file.zip" AWS.config(access_key_id: 'xxx', secret_access_key: 'xx') s3 = AWS::S3.new bucket = s3.buckets['my-bucket-name'] s3_object = bucket.objects[s3_object_key] upload_url

The request sent by the client was syntactically incorrect ().+Spring , RESTClient

心已入冬 提交于 2019-12-01 03:53:58
I am working with Spring MVC using JSON objects. while I am tring to send JSON Object from RESTClient, I am getting HTTP Status 400 - The request sent by the client was syntactically incorrect (). This is my controller ObjectMapper mapper=new ObjectMapper(); @RequestMapping(value = "/addTask", method = RequestMethod.GET) public ModelAndView addTask(@RequestParam("json") String json) throws JsonParseException, JsonMappingException, IOException { System.out.println("Json object from REST : "+json); Task task=(Task) mapper.readValue(json, Task); service.addService(task); return new ModelAndView(

How do I make Ruby's RestClient gem respect content_type on post?

Deadly 提交于 2019-11-30 17:45:41
For instance, in the RestClient console: RestClient.post 'http://localhost:5001', {:a => 'b'}, :content_type => 'application/json' This does not send application/json as the content type. Instead I see: Content-Type: application/x-www-form-urlencoded I was able to trace the change to restclient/payload.rb: class UrlEncoded < Base ... def headers super.merge({'Content-Type' => 'application/x-www-form-urlencoded'}) end end Replacing super.merge with super causes the content type to be respected, but obviously that's not a real solution. Does anyone know the proper way to fix this? Thanks. You

How do I make Ruby's RestClient gem respect content_type on post?

允我心安 提交于 2019-11-30 01:27:19
问题 For instance, in the RestClient console: RestClient.post 'http://localhost:5001', {:a => 'b'}, :content_type => 'application/json' This does not send application/json as the content type. Instead I see: Content-Type: application/x-www-form-urlencoded I was able to trace the change to restclient/payload.rb: class UrlEncoded < Base ... def headers super.merge({'Content-Type' => 'application/x-www-form-urlencoded'}) end end Replacing super.merge with super causes the content type to be respected

HttpStatus become deprecated in API level 22

≡放荡痞女 提交于 2019-11-30 01:16:40
Usually I used to check for the server different code responses in my RestClient class using the org.apache.http.HttpStatus class as the following example: if (HttpStatus.SC_OK == restClient.getResponseCode()) { //200 OK (HTTP/1.0 - RFC 1945) return true; } else if (HttpStatus.SC_BAD_GATEWAY == restClient.getResponseCode()){ //502 Bad Gateway (HTTP/1.0 - RFC 1945) return false; } But recently the class became deprecated since API level 22 according to the official documentation This interface was deprecated in API level 22. Please use openConnection() instead. Please visit this webpage for