Upload Captions YouTube Data API ruby - youtube-data-api

I am trying to upload captions to YouTube using the Data API. However I can't find in the reference or in the forum any example in Ruby. In specific how to send the actual caption file (xml).
body = {
:snippet => {
:videoId => videoId,
:language => "English",
:name => "English"
}
}
captions_insert_response = client.execute(
:api_method => youtube.captions.insert,
:parameters => {
:part => body.keys.join(',')
},
:body_object => body
)
where and how do I add the caption file? I tried doing it like uploading a video, but it didn't seem to work. This line was added after ":body_object"
:media => Google::APIClient::UploadIO.new(captions_file, 'text/xml')
Thanks

I solved the issue changing the language in the snippet to "en".
This is the complete request if someone needs it.
body = {
:snippet => {
:videoId => videoId,
:language => "en",
:name => "English"
}
}
captions_insert_response = client.execute(
:api_method => youtube.captions.insert,
:body_object => body,
:media => Google::APIClient::UploadIO.new(captions_file, 'text/xml'),
:parameters => {
'uploadType' => 'multipart',
:part => body.keys.join(',')
}
)

Related

jira-ruby: issue.save returning false

I am trying to create an issue with jira-ruby in the terminal. So far I have done the following (where username, password, site and project have been replaced with the proper values). I have been able to fetch issues, but not to create them. Jira-ruby return false when i try and save an issue
options = {
:username => "username",
:password => "password",
:site => 'site',
:context_path => '',
:auth_type => :basic
}
client = JIRA::Client.new(options)
issue = client.Issue.build
issue.save({
"fields" => {
"summary" => "blarg from in example.rb",
"project" => {"key" => "mykey"},
"issuetype" => {"id" => "1"}
}
})
=> false
issue.attrs
=> {"errorMessages"=>[], "errors"=>{"issuetype"=>"issue type is required"}, "summary"=>"blarg from in example.rb", "key"=>"somekey", "id"=>"someid", "self"=>"site", "exception"=>{"class"=>"Net::HTTPBadRequest", "code"=>"400", "message"=>"Bad Request"}}
What is the problem?

Savon: Wrong Element Name Prefix. How can I change it?

So here is the code that I have:
resp = client.call(
:producer_query,
message: {
'cmn:Carrier' => '',
'cmn:ProducerCriteria' => { 'cmn:EntityType' => 'Individual',
'cmn:CustomerId' => 5555,
:attributes! => {'CustomerId' => {'type' => 'AGENTCD'}}},
'cmn:SectionConfiguration' => { 'cmn:SectionType' => 'Associations', :attributes! => {'cmn:SectionType' => {'activeOnly' => 'false'}}},
:attributes! => { 'cmn:Carrier' => { "id" => 55555 }}
}
) do
wsse_auth ENV['ID'], ENV['PASSWORD'], :digest
end
And it produces something that looks like:
<soapenv:Body>
<cmn:ProducerQuery>
<cmn:Carrier id="5555"/>
<cmn:ProducerCriteria>
<cmn:EntityType>Individual</cmn:EntityType>
<cmn:CustomerId>55555</cmn:CustomerId>
</cmn:ProducerCriteria>
<cmn:SectionConfiguration>
<cmn:SectionType activeOnly="false">Associations</cmn:SectionType>
</cmn:SectionConfiguration>
</cmn:ProducerQuery>
</soapenv:Body>
I've added in the 'cmn' to everything, but the ProducerQuery to make it match what I think it should be. However, I think it really should read 'tran' instead. I can control the 'cmn' for everything but the part that reads <cmn:ProducerQuery>. How can I make it read <cmn:ProducerQuery>?

Why am I getting this 'no implicit conversion of Hash into String' when mocking Stripe with WebMock

I'm trying to mock Stripe like this:
stub_request(:post, "https://api.stripe.com/v1/tokens").with(
:body => {"card" => {"number" => "4242424242424242", "exp_month"=> "12", "exp_year" => "2018", "cvc" => "123"}}
).
to_return(:status => 200, :headers => {}, :body => {
"id" => "tok_14CgP22eZvKYlo2CkgJ6ymLE",
"livemode" => false,
"created" => 1404517660,
"used" => false,
"object" => "token",
"type" => "card",
"card" => {
"id" => "card_14CgP22eZvKYlo2CcdUNvicW",
"object" => "card",
"last4" => "4242",
"brand" => "Visa",
"funding" => "credit",
"exp_month" => 12,
"exp_year" => 2018,
"fingerprint" => "Xt5EWLLDS7FJjR1c",
"country" => "US"
}
})
I am getting a no implicit conversion of Hash into String error when I call:
token = Stripe::Token.create(:card => {
:number => params["number"],
:exp_month => params["expiry_month"],
:exp_year => params["expiry_year"],
:cvc => params["cvc"]})
It's because of the hash in body in to_return, but I don't know how to avoid the error.
If I add .to_s to the hash, I get:
Invalid response object from API: "{\"id\"=>\"tok_14CgP22eZvKYlo2CkgJ6ymLE\", \"livemode\"=>false, \"created\"=>1404517660, \"used\"=>false, \"object\"=>\"token\", \"type\"=>\"card\", \"card\"=>{\"id\"=>\"card_14CgP22eZvKYlo2CcdUNvicW\", \"object\"=>\"card\", \"last4\"=>\"4242\", \"brand\"=>\"Visa\", \"funding\"=>\"credit\", \"exp_month\"=>12, \"exp_year\"=>2018, \"fingerprint\"=>\"Xt5EWLLDS7FJjR1c\", \"country\"=>\"US\"}}" (HTTP response code was 200)
If I add a .to_json to the end, Stripe::Token passes but I get a stack error too deep error when I try to use the resulting token in any way.
What do you recommend?
It could be that your stubbing is not returning correctly. It may help to make your stubbing a little less specific. For example:
body = {
"id" => "tok_14CgP22eZvKYlo2CkgJ6ymLE",
"livemode" => false
# snip...
}
stub_request(:post, "https://api.stripe.com/v1/tokens")
.to_return(:status => 200, :body => body.to_json)
However, it's difficult to know exactly what errors are being thrown, so I can only give vague ideas which may help. What error does calling token give you?

Why am I getting =0A inside emails being sent, where there should be a line break?

I'm getting =0A inside my emails where there should be a line break.
#article = DB[:posts][:nodeview_id => view, :nodeview => 'article']
Pony.mail(:html_body => #article[:content], :reply_to => #email, :subject => "New article #{#article[:title]}", :headers => { "X-MC-Tags" => "feedback" } )
And ##article[:content]} in this context, is
apples
bananas
inside the database, no \n or <br> tags.
Here's how Pony is configured.
Pony.options = { :from => 'Compesh <donotreply#compesh.com>', :to => 'blahblahblah#emails.com',
:via => :smtp, :via_options => {
:address => 'smtp.mandrillapp.com', :port => '587',
:user_name => 'XXX', :password => 'XXXXXX'
},
:headers => { "X-MC-AutoText" => "yes" }, :charset => 'utf-8'
}
But in my emails I get
apples=0Abananas
Pony doesn't let me choose the content type, I don't think.
I managed to fix this by converting newlines to a <br> tag. It turns out it had nothing to do with the content type or encoding of the email at a..
mystring.gsub(/(?:\n\r?|\r\n?)/, '<br>')
This specially general regex function, has a way of covering DOS, *NIX, Mac and accidental invalid line endings.

Google Calendar Ruby API

I'm working on an app that needs to update a google calendar.
By following the Google Calendar Developer Guide at:
http://code.google.com/apis/calendar/v3/using.html#creating_events
event = {
'summary' => 'Appointment',
'location' => 'Somewhere',
'start' => {
'dateTime' => '2011-06-03T10:00:00.000-07:00'
},
'end' => {
'dateTime' => '2011-06-03T10:25:00.000-07:00'
}
}
result = client.execute(:api_method => service.events.insert,
:parameters => {'calendarId' => 'primary'},
:body => JSON.dump(event),
:headers => {'Content-Type' => 'application/json'})
I get the following error:
TypeError (Expected body to respond to :each.):
I have tried to do event.to_json as well.
Just a couple of suggestions from the top of my head which may help. Please try them and inform us if these help.
Wrap :body into array:
result = client.execute(:api_method => service.events.insert,
:parameters => {'calendarId' => 'primary'},
:body => [JSON.dump(event)],
:headers => {'Content-Type' => 'application/json'})
Or use:body_object instead of body, and don't jsonify the event hash:
result = client.execute(:api_method => service.events.insert,
:parameters => {'calendarId' => 'primary'},
:body_object => event,
:headers => {'Content-Type' => 'application/json'})
Take a look at http://code.google.com/p/google-api-ruby-client/source/browse/lib/google/api_client/reference.rb, and you'll understand how I came up with these suggestions.

Resources